Add more examples for Integer.parse
- show behavior of parsing with unparsable suffix bits - show behavior of parsing float as integer
This commit is contained in:
@@ -39,6 +39,14 @@ defmodule Numbers do
|
|||||||
assert Integer.parse("2A", 16) == {___, ""}
|
assert Integer.parse("2A", 16) == {___, ""}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "The remaining unparsable part is also returned" do
|
||||||
|
assert Integer.parse("5 years") == {5, ___}
|
||||||
|
end
|
||||||
|
|
||||||
|
koan "What if you parse a floating point value as an integer?" do
|
||||||
|
assert Integer.parse("1.2") == {___, ___}
|
||||||
|
end
|
||||||
|
|
||||||
koan "Just want to parse to a float" do
|
koan "Just want to parse to a float" do
|
||||||
assert Float.parse("34.5") == {___, ""}
|
assert Float.parse("34.5") == {___, ""}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ defmodule NumbersTests do
|
|||||||
'7',
|
'7',
|
||||||
"1234",
|
"1234",
|
||||||
42,
|
42,
|
||||||
|
" years",
|
||||||
|
{:multiple, [1, ".2"]},
|
||||||
34.5,
|
34.5,
|
||||||
1.5,
|
1.5,
|
||||||
35.0,
|
35.0,
|
||||||
|
|||||||
Reference in New Issue
Block a user