Skip to content

Commit 61ae563

Browse files
gmilejosevalim
authored andcommitted
Run the code formatter on KeywordTest (#6690)
1 parent 1b49dce commit 61ae563

File tree

1 file changed

+79
-33
lines changed

1 file changed

+79
-33
lines changed

lib/elixir/test/elixir/keyword_test.exs

+79-33
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
Code.require_file "test_helper.exs", __DIR__
1+
Code.require_file("test_helper.exs", __DIR__)
22

33
defmodule KeywordTest do
44
use ExUnit.Case, async: true
55

6-
doctest Keyword
6+
doctest(Keyword)
77

88
test "has a literal syntax" do
99
assert [B: 1] == [{:B, 1}]
@@ -13,66 +13,83 @@ defmodule KeywordTest do
1313
end
1414

1515
test "is a :: operator on ambiguity" do
16-
assert [{:::, _, [{:a, _, _}, {:b, _, _}]}] = quote(do: [a::b])
16+
assert [{:::, _, [{:a, _, _}, {:b, _, _}]}] = quote(do: [a :: b])
1717
end
1818

1919
test "supports optional comma" do
20-
[a: 1,
21-
b: 2,
22-
c: 3,]
20+
[a: 1, b: 2, c: 3]
2321
end
2422

2523
test "implements (almost) all functions in Map" do
26-
assert Map.__info__(:functions) -- Keyword.__info__(:functions) ==
27-
[from_struct: 1]
24+
assert Map.__info__(:functions) -- Keyword.__info__(:functions) == [from_struct: 1]
2825
end
2926

3027
test "get_and_update/3 raises on bad return value from the argument function" do
31-
assert_raise RuntimeError, "the given function must return a two-element tuple or :pop, got: 1", fn ->
28+
message = "the given function must return a two-element tuple or :pop, got: 1"
29+
30+
assert_raise RuntimeError, message, fn ->
3231
Keyword.get_and_update([a: 1], :a, fn value -> value end)
3332
end
3433

35-
assert_raise RuntimeError, "the given function must return a two-element tuple or :pop, got: nil", fn ->
34+
message = "the given function must return a two-element tuple or :pop, got: nil"
35+
36+
assert_raise RuntimeError, message, fn ->
3637
Keyword.get_and_update([], :a, fn value -> value end)
3738
end
3839
end
3940

4041
test "get_and_update!/3 raises on bad return value from the argument function" do
41-
assert_raise RuntimeError, "the given function must return a two-element tuple or :pop, got: 1", fn ->
42+
message = "the given function must return a two-element tuple or :pop, got: 1"
43+
44+
assert_raise RuntimeError, message, fn ->
4245
Keyword.get_and_update!([a: 1], :a, fn value -> value end)
4346
end
4447
end
4548

4649
test "merge/2" do
47-
assert Keyword.merge([a: 1, b: 2], [c: 11, d: 12]) == [a: 1, b: 2, c: 11, d: 12]
48-
assert Keyword.merge([], [c: 11, d: 12]) == [c: 11, d: 12]
50+
assert Keyword.merge([a: 1, b: 2], c: 11, d: 12) == [a: 1, b: 2, c: 11, d: 12]
51+
assert Keyword.merge([], c: 11, d: 12) == [c: 11, d: 12]
4952
assert Keyword.merge([a: 1, b: 2], []) == [a: 1, b: 2]
5053

51-
assert_raise ArgumentError, "expected a keyword list as the first argument, got: [1, 2]", fn ->
52-
Keyword.merge([1, 2], [c: 11, d: 12])
54+
message = "expected a keyword list as the first argument, got: [1, 2]"
55+
56+
assert_raise ArgumentError, message, fn ->
57+
Keyword.merge([1, 2], c: 11, d: 12)
5358
end
5459

55-
assert_raise ArgumentError, "expected a keyword list as the first argument, got: [1 | 2]", fn ->
56-
Keyword.merge([1 | 2], [c: 11, d: 12])
60+
message = "expected a keyword list as the first argument, got: [1 | 2]"
61+
62+
assert_raise ArgumentError, message, fn ->
63+
Keyword.merge([1 | 2], c: 11, d: 12)
5764
end
5865

59-
assert_raise ArgumentError, "expected a keyword list as the second argument, got: [11, 12, 0]", fn ->
66+
message = "expected a keyword list as the second argument, got: [11, 12, 0]"
67+
68+
assert_raise ArgumentError, message, fn ->
6069
Keyword.merge([a: 1, b: 2], [11, 12, 0])
6170
end
6271

63-
assert_raise ArgumentError, "expected a keyword list as the second argument, got: [11 | 12]", fn ->
72+
message = "expected a keyword list as the second argument, got: [11 | 12]"
73+
74+
assert_raise ArgumentError, message, fn ->
6475
Keyword.merge([a: 1, b: 2], [11 | 12])
6576
end
6677

6778
# duplicate keys in keywords1 are kept if key is not present in keywords2
68-
assert Keyword.merge([a: 1, b: 2, a: 3], [c: 11, d: 12]) == [a: 1, b: 2, a: 3, c: 11, d: 12]
69-
assert Keyword.merge([a: 1, b: 2, a: 3], [a: 11]) == [b: 2, a: 11]
79+
assert Keyword.merge([a: 1, b: 2, a: 3], c: 11, d: 12) == [a: 1, b: 2, a: 3, c: 11, d: 12]
80+
assert Keyword.merge([a: 1, b: 2, a: 3], a: 11) == [b: 2, a: 11]
7081

7182
# duplicate keys in keywords2 are always kept
72-
assert Keyword.merge([a: 1, b: 2], [c: 11, c: 12, d: 13]) == [a: 1, b: 2, c: 11, c: 12, d: 13]
83+
assert Keyword.merge([a: 1, b: 2], c: 11, c: 12, d: 13) == [a: 1, b: 2, c: 11, c: 12, d: 13]
7384

7485
# any key in keywords1 is removed if key is present in keyword2
75-
assert Keyword.merge([a: 1, b: 2, c: 3, c: 4], [c: 11, c: 12, d: 13]) == [a: 1, b: 2, c: 11, c: 12, d: 13]
86+
assert Keyword.merge([a: 1, b: 2, c: 3, c: 4], c: 11, c: 12, d: 13) == [
87+
a: 1,
88+
b: 2,
89+
c: 11,
90+
c: 12,
91+
d: 13
92+
]
7693
end
7794

7895
test "merge/3" do
@@ -82,35 +99,64 @@ defmodule KeywordTest do
8299
assert Keyword.merge([], [c: 11, d: 12], fun) == [c: 11, d: 12]
83100
assert Keyword.merge([a: 1, b: 2], [], fun) == [a: 1, b: 2]
84101

85-
assert_raise ArgumentError, "expected a keyword list as the first argument, got: [1, 2]", fn ->
102+
message = "expected a keyword list as the first argument, got: [1, 2]"
103+
104+
assert_raise ArgumentError, message, fn ->
86105
Keyword.merge([1, 2], [c: 11, d: 12], fun)
87106
end
88107

89-
assert_raise ArgumentError, "expected a keyword list as the first argument, got: [1 | 2]", fn ->
108+
message = "expected a keyword list as the first argument, got: [1 | 2]"
109+
110+
assert_raise ArgumentError, message, fn ->
90111
Keyword.merge([1 | 2], [c: 11, d: 12], fun)
91112
end
92113

93-
assert_raise ArgumentError, "expected a keyword list as the second argument, got: [{:x, 1}, :y, :z]", fn ->
114+
message = "expected a keyword list as the second argument, got: [{:x, 1}, :y, :z]"
115+
116+
assert_raise ArgumentError, message, fn ->
94117
Keyword.merge([a: 1, b: 2], [{:x, 1}, :y, :z], fun)
95118
end
96119

97-
assert_raise ArgumentError, "expected a keyword list as the second argument, got: [:x | :y]", fn ->
120+
message = "expected a keyword list as the second argument, got: [:x | :y]"
121+
122+
assert_raise ArgumentError, message, fn ->
98123
Keyword.merge([a: 1, b: 2], [:x | :y], fun)
99124
end
100125

101-
assert_raise ArgumentError, "expected a keyword list as the second argument, got: [{:x, 1} | :y]", fn ->
126+
message = "expected a keyword list as the second argument, got: [{:x, 1} | :y]"
127+
128+
assert_raise ArgumentError, message, fn ->
102129
Keyword.merge([a: 1, b: 2], [{:x, 1} | :y], fun)
103130
end
104131

105132
# duplicate keys in keywords1 are left untouched if key is not present in keywords2
106-
assert Keyword.merge([a: 1, b: 2, a: 3], [c: 11, d: 12], fun) == [a: 1, b: 2, a: 3, c: 11, d: 12]
133+
assert Keyword.merge([a: 1, b: 2, a: 3], [c: 11, d: 12], fun) == [
134+
a: 1,
135+
b: 2,
136+
a: 3,
137+
c: 11,
138+
d: 12
139+
]
140+
107141
assert Keyword.merge([a: 1, b: 2, a: 3], [a: 11], fun) == [b: 2, a: 12]
108142

109143
# duplicate keys in keywords2 are always kept
110-
assert Keyword.merge([a: 1, b: 2], [c: 11, c: 12, d: 13], fun) == [a: 1, b: 2, c: 11, c: 12, d: 13]
144+
assert Keyword.merge([a: 1, b: 2], [c: 11, c: 12, d: 13], fun) == [
145+
a: 1,
146+
b: 2,
147+
c: 11,
148+
c: 12,
149+
d: 13
150+
]
111151

112152
# every key in keywords1 is replaced with fun result if key is present in keyword2
113-
assert Keyword.merge([a: 1, b: 2, c: 3, c: 4], [c: 11, c: 50, d: 13], fun) == [a: 1, b: 2, c: 14, c: 54, d: 13]
153+
assert Keyword.merge([a: 1, b: 2, c: 3, c: 4], [c: 11, c: 50, d: 13], fun) == [
154+
a: 1,
155+
b: 2,
156+
c: 14,
157+
c: 54,
158+
d: 13
159+
]
114160
end
115161

116162
test "merge/2 and merge/3 behave exactly the same way" do
@@ -123,7 +169,7 @@ defmodule KeywordTest do
123169
{[a: 1, b: 2, a: 3], [c: 11, d: 12]},
124170
{[a: 1, b: 2, a: 3], [a: 11]},
125171
{[a: 1, b: 2], [c: 11, c: 12, d: 13]},
126-
{[a: 1, b: 2, c: 3, c: 4], [c: 11, c: 12, d: 13]},
172+
{[a: 1, b: 2, c: 3, c: 4], [c: 11, c: 12, d: 13]}
127173
]
128174

129175
args_error = [
@@ -133,7 +179,7 @@ defmodule KeywordTest do
133179
{[a: 1, b: 2], [11 | 12]},
134180
{[a: 1, b: 2], [{:x, 1}, :y, :z]},
135181
{[a: 1, b: 2], [:x | :y]},
136-
{[a: 1, b: 2], [{:x, 1} | :y]},
182+
{[a: 1, b: 2], [{:x, 1} | :y]}
137183
]
138184

139185
for {arg1, arg2} <- args do

0 commit comments

Comments
 (0)