Fix typos and bring back the failing pattern match.
This commit is contained in:
@@ -111,7 +111,7 @@ defmodule PatternMatching do
|
|||||||
assert a == ___
|
assert a == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "A variable can be pinned to prevent it from being rebound" do
|
koan "A variable can be pinned to use its value when matching instead of binding to a new value" do
|
||||||
pinned_variable = 1
|
pinned_variable = 1
|
||||||
|
|
||||||
example = fn
|
example = fn
|
||||||
@@ -124,14 +124,20 @@ defmodule PatternMatching do
|
|||||||
assert example.(3) == ___
|
assert example.(3) == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
koan "Pinning works on anywhere one would match, including 'case'" do
|
koan "Pinning works anywhere one would match, including 'case'" do
|
||||||
pinned_variable = 1
|
pinned_variable = 1
|
||||||
other_variable = 1
|
result = case 1 do
|
||||||
result = case other_variable do
|
|
||||||
^pinned_variable -> "same"
|
^pinned_variable -> "same"
|
||||||
other -> "different #{other}"
|
other -> "different #{other}"
|
||||||
end
|
end
|
||||||
|
|
||||||
assert result == ___
|
assert result == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "Trying to rebind a pinned variable will result in an error" do
|
||||||
|
a = 1
|
||||||
|
assert_raise MatchError, fn() ->
|
||||||
|
^a = ___
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ defmodule PatternsTests do
|
|||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
{:multiple, ["The number One", "The number Two", "The number 3"]},
|
{:multiple, ["The number One", "The number Two", "The number 3"]},
|
||||||
"same"
|
"same",
|
||||||
|
2
|
||||||
]
|
]
|
||||||
|
|
||||||
test_all(PatternMatching, answers)
|
test_all(PatternMatching, answers)
|
||||||
|
|||||||
Reference in New Issue
Block a user