/
lists_spec.rb
180 lines (162 loc) · 3.53 KB
/
lists_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# frozen_string_literal: true
require 'spec_helper'
describe 'Indenting' do
specify 'lists' do
expect(<<~EOF).to be_elixir_indentation
def example do
[ :foo,
:bar,
:baz ]
end
EOF
end
specify 'nested list' do
expect(<<~EOF).to be_elixir_indentation
[
[
:foo
]
]
EOF
end
specify 'keyword list' do
expect(<<~EOF).to be_elixir_indentation
def project do
[ name: "mix",
version: "0.1.0",
deps: deps ]
end
EOF
end
specify 'keyword' do
expect(<<~EOF).to be_elixir_indentation
def config do
[ name:
"John" ]
end
EOF
end
specify 'list of tuples' do
expect(<<~EOF).to be_elixir_indentation
def test do
[ { :cowboy, github: "extend/cowboy" },
{ :dynamo, "0.1.0-dev", github: "elixir-lang/dynamo" },
{ :ecto, github: "elixir-lang/ecto" },
{ :pgsql, github: "semiocast/pgsql" } ]
end
EOF
end
specify 'list of lists' do
expect(<<~EOF).to be_elixir_indentation
def test do
[ [:a, :b, :c],
[:d, :e, :f] ]
end
EOF
end
specify 'complex list' do
expect(<<~EOF).to be_elixir_indentation
def test do
[ app: :first,
version: "0.0.1",
dynamos: [First.Dynamo],
compilers: [:elixir, :dynamo, :ecto, :app],
env: [prod: [compile_path: "ebin"]],
compile_path: "tmp/first/ebin",
deps: deps ]
end
EOF
end
specify 'lists without whitespace' do
expect(<<~EOF).to be_elixir_indentation
def project do
[{:bar, path: "deps/umbrella/apps/bar"},
{:umbrella, path: "deps/umbrella"}]
end
EOF
end
specify 'lists with line break after square brackets' do
expect(<<~EOF).to be_elixir_indentation
def project do
[
{ :bar, path: "deps/umbrella/apps/bar" },
{ :umbrella, path: "deps/umbrella" }
]
end
EOF
end
specify 'multiple lists with multiline elements' do
expect(<<~EOF).to be_elixir_indentation
def test do
a = [
%{
foo: 1,
bar: 2
}
]
b = %{
[
:foo,
:bar
]
}
[
a,
b
]
end
EOF
end
it 'indent function body even when breaking the parameter list in many lines' do
expect(<<~EOF).to be_elixir_indentation
def create(conn, %{
"grant_type" => "password",
"username" => username,
"password" => password
}) do
1
end
EOF
end
it 'parameters list in many lines' do
expect(<<~EOF).to be_elixir_indentation
def double(x) do
add(x,
y)
end
EOF
end
it 'long parameters list in many lines' do
expect(<<~EOF).to be_elixir_indentation
def double(x) do
add(x,
y,
w,
z)
end
EOF
end
describe 'restore last indentation after multiline lists' do
it 'correct indentation after long parameter list' do
expect(<<~EOF).to be_elixir_indentation
def double(x) do
resutl = add(x,
z)
div(result, 2)
end
EOF
end
it 'correct indentation after long map list' do
expect(<<~EOF).to be_elixir_indentation
defmodule Module do
@person1 { name: "name",
age: 18,
enabled?: true }
@person2 { name: "other name",
age: 21,
enabled?: false }
end
EOF
end
end
end