Skip to content

Commit 34873ee

Browse files
authored
replace all indent tests with i helper (#455)
1 parent b9cfc31 commit 34873ee

14 files changed

+523
-682
lines changed

spec/indent/anonymous_functions_spec.rb

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,69 +3,53 @@
33
require 'spec_helper'
44

55
describe 'Indenting anonymous functions' do
6-
context 'single body functions inside do block' do
7-
it 'is declared with fn syntax' do
8-
expect(<<~EOF).to be_elixir_indentation
9-
def do
10-
some_func = fn x -> x end
11-
end
12-
EOF
13-
end
6+
i <<~EOF
7+
def do
8+
some_func = fn x -> x end
9+
end
10+
EOF
1411

15-
it 'is declared with function syntax' do
16-
expect(<<~EOF).to be_elixir_indentation
17-
def do
18-
some_func = function do x -> x end
19-
end
20-
EOF
21-
end
12+
i <<~EOF
13+
def do
14+
some_func = function do x -> x end
15+
end
16+
EOF
2217

23-
it 'spans in multiple lines' do
24-
expect(<<~EOF).to be_elixir_indentation
25-
def test do
26-
assert_raise Queue.Empty, fn ->
27-
Q.new |> Q.deq!
28-
end
29-
end
30-
EOF
18+
i <<~EOF
19+
def test do
20+
assert_raise Queue.Empty, fn ->
21+
Q.new |> Q.deq!
3122
end
23+
end
24+
EOF
3225

33-
it 'spans in multiple lines inside parentheses' do
34-
expect(<<~EOF).to be_elixir_indentation
35-
defmodule Test do
36-
def lol do
37-
Enum.map([1,2,3], fn x ->
38-
x * 3
39-
end)
40-
end
41-
end
42-
EOF
26+
i <<~EOF
27+
defmodule Test do
28+
def lol do
29+
Enum.map([1,2,3], fn x ->
30+
x * 3
31+
end)
4332
end
4433
end
34+
EOF
4535

46-
context 'multiple body functions declaring' do
47-
it 'it with fn syntax' do
48-
expect(<<~EOF).to be_elixir_indentation
49-
fizzbuzz = fn
50-
0, 0, _ -> "FizzBuzz"
51-
0, _, _ -> "Fizz"
52-
_, 0, _ -> "Buzz"
53-
_, _, x -> x
54-
end
55-
EOF
56-
end
36+
i <<~EOF
37+
fizzbuzz = fn
38+
0, 0, _ -> "FizzBuzz"
39+
0, _, _ -> "Fizz"
40+
_, 0, _ -> "Buzz"
41+
_, _, x -> x
42+
end
43+
EOF
5744

58-
it 'it with function syntax' do
59-
expect(<<~EOF).to be_elixir_indentation
60-
fizzbuzz = function do
61-
0, 0, _ -> "FizzBuzz"
62-
0, _, _ -> "Fizz"
63-
_, 0, _ -> "Buzz"
64-
_, _, x -> x
65-
end
66-
EOF
67-
end
45+
i <<~EOF
46+
fizzbuzz = function do
47+
0, 0, _ -> "FizzBuzz"
48+
0, _, _ -> "Fizz"
49+
_, 0, _ -> "Buzz"
50+
_, _, x -> x
6851
end
52+
EOF
6953

7054
i <<~EOF
7155
{:ok, 0} = Mod.exec!(cmd, fn progress ->

spec/indent/blocks_spec.rb

Lines changed: 60 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,116 +3,94 @@
33
require 'spec_helper'
44

55
describe 'Indenting blocks' do
6-
it "'do' indenting" do
7-
expect(<<~EOF).to be_elixir_indentation
8-
do
9-
something
10-
end
11-
EOF
6+
i <<~EOF
7+
do
8+
something
129
end
10+
EOF
1311

14-
it 'does not consider :end as end' do
15-
expect(<<~EOF).to be_elixir_indentation
16-
defmodule Test do
17-
def lol do
18-
IO.inspect :end
19-
end
12+
i <<~EOF
13+
defmodule Test do
14+
def lol do
15+
IO.inspect :end
2016
end
21-
EOF
2217
end
18+
EOF
2319

24-
it 'indent inline functions' do
25-
expect(<<~EOF).to be_elixir_indentation
26-
defmodule Hello do
27-
def name, do: IO.puts "bobmarley"
28-
# expect next line starting here
20+
i <<~EOF
21+
defmodule Hello do
22+
def name, do: IO.puts "bobmarley"
23+
# expect next line starting here
2924
30-
def name(param) do
31-
param
32-
end
25+
def name(param) do
26+
param
3327
end
34-
EOF
3528
end
29+
EOF
3630

37-
it 'type inline functions' do
38-
expect(<<~EOF).to be_typed_with_right_indent
39-
defmodule Hello do
40-
def name, do: IO.puts "bobmarley"
31+
i <<~EOF
32+
defmodule Hello do
33+
def name, do: IO.puts "bobmarley"
4134
42-
def name(param) do
43-
param
44-
end
35+
def name(param) do
36+
param
4537
end
46-
EOF
4738
end
39+
EOF
4840

49-
it 'does not consider do: as the start of a block' do
50-
expect(<<~EOF).to be_elixir_indentation
51-
def f do
52-
if true, do: 42
53-
end
54-
EOF
41+
i <<~EOF
42+
def f do
43+
if true, do: 42
5544
end
45+
EOF
5646

57-
it "do not mislead atom ':do'" do
58-
expect(<<~EOF).to be_elixir_indentation
59-
def f do
60-
x = :do
61-
end
62-
EOF
47+
i <<~EOF
48+
def f do
49+
x = :do
6350
end
51+
EOF
6452

65-
it 'multiline assignment' do
66-
expect(<<~EOF).to be_elixir_indentation
67-
defmodule Test do
68-
def test do
69-
one =
70-
user
71-
|> build_assoc(:videos)
72-
|> Video.changeset()
73-
74-
other =
75-
user2
76-
|> build_assoc(:videos)
77-
|> Video.changeset()
78-
end
53+
i <<~EOF
54+
defmodule Test do
55+
def test do
56+
one =
57+
user
58+
|> build_assoc(:videos)
59+
|> Video.changeset()
60+
61+
other =
62+
user2
63+
|> build_assoc(:videos)
64+
|> Video.changeset()
7965
end
80-
EOF
8166
end
67+
EOF
8268

83-
it 'does not indent based on opening symbols inside strings' do
84-
expect(<<~EOF).to be_elixir_indentation
85-
defmodule MyMod do
86-
def how_are_you do
87-
IO.puts "I'm filling bad :("
88-
IO.puts "really bad"
89-
end
69+
i <<~EOF
70+
defmodule MyMod do
71+
def how_are_you do
72+
IO.puts "I'm filling bad :("
73+
IO.puts "really bad"
9074
end
91-
EOF
9275
end
76+
EOF
9377

94-
describe 'indenting while typing' do
95-
it 'close block' do
96-
expect(<<~EOF).to be_typed_with_right_indent
97-
defmodule MyMod do
98-
def how_are_you do
99-
"function return"
100-
end
101-
end
102-
EOF
78+
i <<~EOF
79+
defmodule MyMod do
80+
def how_are_you do
81+
"function return"
10382
end
10483
end
84+
EOF
10585

106-
it 'indenting with a blank line in it' do
107-
expect(<<~EOF).to be_elixir_indentation
108-
scope "/", API do
109-
pipe_through :api # Use the default browser stack
86+
i <<~EOF
87+
scope "/", API do
88+
pipe_through :api # Use the default browser stack
11089
111-
get "/url", Controller, :index
112-
post "/url", Controller, :create
113-
end
114-
EOF
90+
get "/url", Controller, :index
91+
post "/url", Controller, :create
11592
end
93+
EOF
11694

11795
i <<~EOF
11896
def hello do

0 commit comments

Comments
 (0)