add .formatter.exs + format

This commit is contained in:
Martino Visintin
2018-05-22 21:46:54 +01:00
parent 08c90ce0d8
commit b07df7c780
52 changed files with 332 additions and 264 deletions

View File

@@ -8,30 +8,32 @@ defmodule BlanksTest do
end
test "Work with multiple different replacements" do
[koan | _] = SampleKoan.all_koans
assert :ok == apply(SampleKoan, koan, [{:multiple, [3,4]}])
[koan | _] = SampleKoan.all_koans()
assert :ok == apply(SampleKoan, koan, [{:multiple, [3, 4]}])
end
test "complex example" do
ast = quote do: assert true == ___
ast = quote do: assert(true == ___)
assert Blanks.replace(ast, true) == quote(do: assert true == true)
assert Blanks.replace(ast, true) == quote(do: assert(true == true))
end
test "multiple arguments" do
ast = quote do: assert ___ == ___
ast = quote do: assert(___ == ___)
assert Blanks.replace(ast, [true, false]) == quote(do: assert true == false)
assert Blanks.replace(ast, [true, false]) == quote(do: assert(true == false))
end
test "pins variables in assert_receive replacement" do
ast = quote do: assert_receive ___
assert Blanks.replace(ast, Macro.var(:answer, __MODULE__)) == quote(do: assert_receive ^answer)
ast = quote do: assert_receive(___)
assert Blanks.replace(ast, Macro.var(:answer, __MODULE__)) ==
quote(do: assert_receive(^answer))
end
test "does not pin values in assert_receive replacement" do
ast = quote do: assert_receive ___
assert Blanks.replace(ast, :lolwat) == quote(do: assert_receive :lolwat)
ast = quote do: assert_receive(___)
assert Blanks.replace(ast, :lolwat) == quote(do: assert_receive(:lolwat))
end
test "counts simple blanks" do
@@ -41,41 +43,46 @@ defmodule BlanksTest do
end
test "counts multiple blanks" do
ast = quote do: assert ___ == ___
ast = quote do: assert(___ == ___)
assert Blanks.count(ast) == 2
end
test "replaces whole line containing blank" do
ast = quote do
1 + 2
2 + ___
end
ast =
quote do
1 + 2
2 + ___
end
expected_result = quote do
1 + 2
true
end
expected_result =
quote do
1 + 2
true
end
actual_result = Blanks.replace_line(ast, fn(_) -> true end)
actual_result = Blanks.replace_line(ast, fn _ -> true end)
assert actual_result == expected_result
end
test "replacement fn can access line" do
ast = quote do
1 + 2
2 + ___
end
ast =
quote do
1 + 2
2 + ___
end
expected_result = quote do
1 + 2
some_fun(2 + ___)
end
expected_result =
quote do
1 + 2
some_fun(2 + ___)
end
actual_result = Blanks.replace_line(ast, fn(line) ->
quote do: some_fun(unquote(line))
end)
actual_result =
Blanks.replace_line(ast, fn line ->
quote do: some_fun(unquote(line))
end)
assert actual_result == expected_result
end

View File

@@ -18,39 +18,39 @@ defmodule FailureTests do
error = error(%ExUnit.AssertionError{expr: quote(do: :lol == :wat), left: :lol, right: :wat})
assert Failure.format_failure(error) == """
Assertion failed in some_file.ex:42
:lol == :wat
Assertion failed in some_file.ex:42
:lol == :wat
left: :lol
right: :wat
"""
left: :lol
right: :wat
"""
end
test "match failure" do
error = error(%ExUnit.AssertionError{expr: quote(do: match?(:lol,:wat)), right: :wat})
error = error(%ExUnit.AssertionError{expr: quote(do: match?(:lol, :wat)), right: :wat})
assert Failure.format_failure(error) == """
Assertion failed in some_file.ex:42
match?(:lol, :wat)
Assertion failed in some_file.ex:42
match?(:lol, :wat)
value does not match: :wat
"""
value does not match: :wat
"""
end
test "only offending lines are displayed for errors" do
[koan] = SingleArity.all_koans
error = apply(SingleArity, koan, []) |> error()
[koan] = SingleArity.all_koans()
error = apply(SingleArity, koan, []) |> error()
assert Failure.format_failure(error) == """
Assertion failed in some_file.ex:42\nmatch?(:foo, ___)
"""
Assertion failed in some_file.ex:42\nmatch?(:foo, ___)
"""
end
defp error(error) do
%{
error: error,
file: "some_file.ex",
line: 42
line: 42
}
end
end

View File

@@ -3,7 +3,7 @@ defmodule NotificationTest do
alias Display.Notifications
test "shows possible koans when a koan can not be found" do
message = Notifications.invalid_koan(SampleKoan, [PassingKoan])
message = Notifications.invalid_koan(SampleKoan, [PassingKoan])
assert message == "Did not find koan SampleKoan in PassingKoan"
end
end

View File

@@ -13,7 +13,6 @@ defmodule ProgressBarTest do
assert bar == "|=======> | 3 of 12"
end
test "full bar" do
bar = ProgressBar.progress_bar(%{total: 12, current: 12})
assert bar == "|=============================>| 12 of 12"

View File

@@ -12,6 +12,6 @@ defmodule ExecuteTest do
end
test "can access intro" do
assert SampleKoan.intro == "There is something\n"
assert SampleKoan.intro() == "There is something\n"
end
end

View File

@@ -8,7 +8,7 @@ defmodule AgentTests do
"Why hello",
"HI THERE",
{:multiple, [["Milk"], ["Bread", "Milk"]]},
false,
false
]
test_all(Agents, answers)

View File

@@ -9,17 +9,17 @@ defmodule EnumTests do
{:multiple, [true, false]},
{:multiple, [true, false]},
{:multiple, [true, false]},
[10,20,30],
[1,3],
[10, 20, 30],
[1, 3],
[2],
[1,2,3],
[1,2,3,4,5],
[1,2,3],
[1, 2, 3],
[1, 2, 3, 4, 5],
[1, 2, 3],
[a: 1, b: 2, c: 3],
2,
nil,
:no_such_element,
6,
6
]
test_all(Enums, answers)

View File

@@ -10,7 +10,7 @@ defmodule EqualitiesTests do
2,
1,
4,
2,
2
]
test_all(Equalities, answers)

View File

@@ -7,7 +7,7 @@ defmodule FunctionsTests do
"Hello, World!",
3,
{:multiple, ["One and Two", "Only One"]},
{:multiple, ["Hello Hello Hello Hello Hello ","Hello Hello "]},
{:multiple, ["Hello Hello Hello Hello Hello ", "Hello Hello "]},
{:multiple, [:entire_list, :single_thing]},
{:multiple, ["10 is bigger than 5", "4 is not bigger than 27"]},
{:multiple, ["The number was zero", "The number was 5"]},
@@ -18,7 +18,7 @@ defmodule FunctionsTests do
100,
1000,
"Full Name",
{:multiple, ["GOOD", "good"]},
{:multiple, ["GOOD", "good"]}
]
test_all(Functions, answers)

View File

@@ -13,7 +13,7 @@ defmodule GenServersTests do
{:error, "Incorrect password!"},
"Congrats! Your process was successfully named.",
{:ok, "Laptop unlocked!"},
{:multiple, ["Laptop unlocked!", "Incorrect password!", "Jack Sparrow"]},
{:multiple, ["Laptop unlocked!", "Incorrect password!", "Jack Sparrow"]}
]
test_all(GenServers, answers)

View File

@@ -8,7 +8,7 @@ defmodule KeywordListsTests do
"bar",
"baz",
{:multiple, [:foo, "bar"]},
"foo",
"foo"
]
test_all(KeywordLists, answers)

View File

@@ -3,24 +3,25 @@ defmodule ListsTests do
import TestHarness
test "Lists" do
answers = [1,
3,
[1, 2, :a, "b"],
[1,2],
[:a, :c],
[:a, :b],
["life", "life", "life"],
[1, 2, 3, 4, 5],
[1, 4, 2, 3],
[10, 2, 3],
[1, 2, 3],
[1, 2, 3, 4],
[1, 2, 3, 4],
{1, 2, 3},
["value"],
[],
["value"],
]
answers = [
1,
3,
[1, 2, :a, "b"],
[1, 2],
[:a, :c],
[:a, :b],
["life", "life", "life"],
[1, 2, 3, 4, 5],
[1, 4, 2, 3],
[10, 2, 3],
[1, 2, 3],
[1, 2, 3, 4],
[1, 2, 3, 4],
{1, 2, 3},
["value"],
[],
["value"]
]
test_all(Lists, answers)
end

View File

@@ -14,7 +14,7 @@ defmodule MapSetsTest do
false,
true,
7,
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5]
]
test_all(MapSets, answers)

View File

@@ -13,7 +13,7 @@ defmodule MapsTests do
false,
%{:first_name => "Jon", :last_name => "Snow"},
{:ok, "Baratheon"},
%{:first_name => "Jon", :last_name => "Snow"},
%{:first_name => "Jon", :last_name => "Snow"}
]
test_all(Maps, answers)

View File

@@ -30,7 +30,7 @@ defmodule NumbersTests do
{:multiple, [6.0, 5.0, 8.9, -5.567]},
{:multiple, [1, 10]},
{:multiple, [true, true, false]},
{:multiple, [true, false]},
{:multiple, [true, false]}
]
test_all(Numbers, answers)

View File

@@ -5,14 +5,14 @@ defmodule PatternsTests do
test "Pattern Matching" do
answers = [
1,
{:multiple, [1, [2,3,4]]},
[1,2,3,4],
{:multiple, [1, [2, 3, 4]]},
[1, 2, 3, 4],
3,
"eggs, milk",
"Honda",
MatchError,
{:multiple, [:make, "Honda"]},
[1,2,3],
[1, 2, 3],
{:multiple, ["Meow", "Woof", "Eh?"]},
{:multiple, ["Mickey", "Donald", "I need a name!"]},
"dog",

View File

@@ -18,7 +18,7 @@ defmodule ProcessesTests do
{:waited_too_long, "I am impatient"},
{:exited, :random_reason},
:normal,
:normal,
:normal
]
test_all(Processes, answers)

View File

@@ -11,7 +11,7 @@ defmodule SigilsTests do
~S(1 + 1 = #{1+1}),
["Hello", "world"],
["Hello", "123"],
["Hello", ~S(#{1+1})],
["Hello", ~S(#{1+1})]
]
test_all(Sigils, answers)

View File

@@ -13,7 +13,7 @@ defmodule StringTests do
"banana",
"banana",
"StringStringString",
"LISTEN",
"LISTEN"
]
test_all(Strings, answers)

View File

@@ -11,7 +11,7 @@ defmodule StructsTests do
{:ok, 22},
%Structs.Airline{plane: %Structs.Plane{maker: :airbus}, name: "Southwest"},
%Structs.Airline{plane: %Structs.Plane{maker: :boeing, passengers: 202}, name: "Southwest"},
%{plane: %{maker: :cessna}, name: "Southwest"},
%{plane: %{maker: :cessna}, name: "Southwest"}
]
test_all(Structs, answers)

View File

@@ -9,8 +9,8 @@ defmodule TasksTests do
nil,
false,
9,
[1,4,9,16],
]
[1, 4, 9, 16]
]
test_all(Tasks, answers)
end

View File

@@ -11,7 +11,7 @@ defmodule TupleTests do
{:a, :new_thing, "hi"},
{"Huey", "Dewey", "Louie"},
{:this, :is, :awesome},
[:this, :can, :be, :a, :list],
[:this, :can, :be, :a, :list]
]
test_all(Tuples, answers)

View File

@@ -5,5 +5,4 @@ defmodule RunnerTest do
path = "lib/koans/01_just_an_example.ex"
assert Runner.path_to_number(path) == 1
end
end

View File

@@ -23,10 +23,10 @@ defmodule TestHarness do
end
defp check_results(results) do
Enum.each(results, &(assert &1 == :passed))
Enum.each(results, &assert(&1 == :passed))
end
def run_all(pairs, module) do
Enum.map(pairs, fn ({koan, answer}) -> Execute.run_koan(module, koan, [answer]) end)
Enum.map(pairs, fn {koan, answer} -> Execute.run_koan(module, koan, [answer]) end)
end
end

View File

@@ -5,24 +5,24 @@ defmodule TrackerTest do
test "can start" do
Tracker.set_total(@sample_modules)
assert Tracker.summarize == %{total: 2, current: 0, visited_modules: []}
assert Tracker.summarize() == %{total: 2, current: 0, visited_modules: []}
end
test "can be notified of completed koans" do
Tracker.set_total(@sample_modules)
Tracker.completed(SampleKoan, :"Hi there")
assert Tracker.summarize == %{total: 2, current: 1, visited_modules: [SampleKoan]}
assert Tracker.summarize() == %{total: 2, current: 1, visited_modules: [SampleKoan]}
end
test "multiple comletions of the same koan count only once" do
Tracker.set_total(@sample_modules)
Tracker.completed(SampleKoan, :"Hi there")
Tracker.completed(SampleKoan, :"Hi there")
assert Tracker.summarize == %{total: 2, current: 1, visited_modules: [SampleKoan]}
assert Tracker.summarize() == %{total: 2, current: 1, visited_modules: [SampleKoan]}
end
test "knows when koans are not complete" do
Tracker.set_total(@sample_modules)
refute Tracker.complete?
refute Tracker.complete?()
end
end