Skip to content

Commit 46c43cb

Browse files
committed
Merge pull request elixir-editors#28 from iurifq/add-vimrunner
Add Vimrunner integration tests
2 parents 15182f2 + 2d7ec3f commit 46c43cb

File tree

9 files changed

+213
-0
lines changed

9 files changed

+213
-0
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: ruby
2+
rvm:
3+
- 1.9.3
4+
before_install: sudo apt-get install vim-gtk
5+
before_script:
6+
- "export DISPLAY=:99.0"
7+
- "sh -e /etc/init.d/xvfb start"
8+
script: "bundle exec rspec --color -f d"

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'http://rubygems.org'
2+
3+
gem 'rspec'
4+
gem 'vimrunner'

Gemfile.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
diff-lcs (1.2.4)
5+
rspec (2.13.0)
6+
rspec-core (~> 2.13.0)
7+
rspec-expectations (~> 2.13.0)
8+
rspec-mocks (~> 2.13.0)
9+
rspec-core (2.13.1)
10+
rspec-expectations (2.13.0)
11+
diff-lcs (>= 1.1.3, < 2.0)
12+
rspec-mocks (2.13.1)
13+
vimrunner (0.3.0)
14+
15+
PLATFORMS
16+
ruby
17+
18+
DEPENDENCIES
19+
rspec
20+
vimrunner
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require 'spec_helper'
2+
3+
describe "Indenting" do
4+
context "single body functions inside do block" do
5+
it "is declared with fn syntax" do
6+
assert_correct_indenting <<-EOF
7+
def do
8+
some_func = fn x -> x end
9+
end
10+
EOF
11+
end
12+
13+
it "is declared with function syntax" do
14+
assert_correct_indenting <<-EOF
15+
def do
16+
some_func = function do x -> x end
17+
end
18+
EOF
19+
end
20+
21+
it "spans in multiple lines" do
22+
assert_correct_indenting <<-EOF
23+
def test do
24+
assert_raise Queue.Empty, fn ->
25+
Q.new |> Q.deq!
26+
end
27+
end
28+
EOF
29+
end
30+
31+
it "spans in multiple lines inside parentheses" do
32+
assert_correct_indenting <<-EOF
33+
defmodule Test do
34+
def lol do
35+
Enum.map([1,2,3], fn x ->
36+
x * 3
37+
end)
38+
end
39+
end
40+
EOF
41+
end
42+
end
43+
44+
context "multiple body functions declaring" do
45+
it "it with fn syntax" do
46+
assert_correct_indenting <<-EOF
47+
fizzbuzz = fn
48+
0, 0, _ -> "FizzBuzz"
49+
0, _, _ -> "Fizz"
50+
_, 0, _ -> "Buzz"
51+
_, _, x -> x
52+
end
53+
EOF
54+
end
55+
56+
it "it with function syntax" do
57+
assert_correct_indenting <<-EOF
58+
fizzbuzz = function do
59+
0, 0, _ -> "FizzBuzz"
60+
0, _, _ -> "Fizz"
61+
_, 0, _ -> "Buzz"
62+
_, _, x -> x
63+
end
64+
EOF
65+
end
66+
end
67+
end

spec/indent/blocks_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'spec_helper'
2+
3+
describe "Indenting" do
4+
specify "'do' indenting" do
5+
assert_correct_indenting <<-EOF
6+
do
7+
something
8+
end
9+
EOF
10+
end
11+
12+
it "does not consider :end as end" do
13+
assert_correct_indenting <<-EOF
14+
defmodule Test do
15+
def lol do
16+
IO.inspect :end
17+
end
18+
end
19+
EOF
20+
end
21+
end

spec/indent/documentation_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'spec_helper'
2+
3+
describe "Indenting" do
4+
context "documentation" do
5+
it "with end keyword" do
6+
assert_correct_indenting <<-EOF
7+
defmodule Test do
8+
@doc ""
9+
end
10+
""
11+
end
12+
EOF
13+
end
14+
end
15+
end

spec/indent/if_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'spec_helper'
2+
3+
describe "Indenting" do
4+
it "if-clauses" do
5+
assert_correct_indenting <<-EOF
6+
if foo do
7+
bar
8+
end
9+
EOF
10+
end
11+
12+
it "if-else-clauses" do
13+
assert_correct_indenting <<-EOF
14+
if foo do
15+
bar
16+
else
17+
baz
18+
end
19+
EOF
20+
end
21+
end

spec/indent/lists_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'spec_helper'
2+
3+
describe "Indenting" do
4+
specify "lists" do
5+
assert_correct_indenting <<-EOF
6+
def project do
7+
[name: "mix",
8+
version: "0.1.0"]
9+
end
10+
EOF
11+
end
12+
end

spec/spec_helper.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'tmpdir'
2+
require 'vimrunner'
3+
4+
module Support
5+
def assert_correct_indenting(string)
6+
whitespace = string.scan(/^\s*/).first
7+
string = string.split("\n").map { |line| line.gsub /^#{whitespace}/, '' }.join("\n").strip
8+
9+
File.open 'test.exs', 'w' do |f|
10+
f.write string
11+
end
12+
13+
@vim.edit 'test.exs'
14+
@vim.normal 'gg=G'
15+
@vim.write
16+
17+
IO.read('test.exs').strip.should eq string
18+
end
19+
end
20+
21+
RSpec.configure do |config|
22+
include Support
23+
24+
config.before(:suite) do
25+
VIM = Vimrunner.start_gvim
26+
VIM.prepend_runtimepath(File.expand_path('../..', __FILE__))
27+
VIM.command('runtime ftdetect/elixir.vim')
28+
end
29+
30+
config.after(:suite) do
31+
VIM.kill
32+
end
33+
34+
config.around(:each) do |example|
35+
@vim = VIM
36+
37+
# cd into a temporary directory for every example.
38+
Dir.mktmpdir do |dir|
39+
Dir.chdir(dir) do
40+
@vim.command("cd #{dir}")
41+
example.call
42+
end
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)