Skip to content

Commit

Permalink
Better inspect for floats
Browse files Browse the repository at this point in the history
  • Loading branch information
Devin Torres committed Oct 15, 2012
1 parent c5e19a3 commit ab4c932
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/elixir/lib/binary/inspect.ex
Expand Up @@ -272,7 +272,7 @@ defimpl Binary.Inspect, for: List do
keywords?(thing) ->
"[" <> join_keywords(thing, opts) <> "]"
true ->
container_join(thing, "[", "]", opts)
container_join(thing, "[", "]", opts)
end
end

Expand All @@ -285,7 +285,7 @@ defimpl Binary.Inspect, for: List do
keywords?(rest, key)
end
defp keywords?([], _prev), do: true
defp keywords?(_other, _prev), do: false
defp keywords?(_other, _prev), do: false

defp join_keywords(thing, opts) do
Enum.join(lc {key, value} inlist thing do
Expand Down Expand Up @@ -416,7 +416,7 @@ defimpl Binary.Inspect, for: Number do
end

def inspect(thing, _) do
list_to_binary float_to_list(thing)
list_to_binary :io_lib.format("~p", [thing])
end
end

Expand Down
9 changes: 5 additions & 4 deletions lib/elixir/test/elixir/binary/inspect_test.exs
Expand Up @@ -84,9 +84,10 @@ defmodule Binary.Inspect.NumberTest do
end

test :float do
assert inspect(1.0) == "1.00000000000000000000e+00"
assert inspect(1.0e10) == "1.00000000000000000000e+10"
assert inspect(1.0e+10) == "1.00000000000000000000e+10"
assert inspect(1.0) == "1.0"
assert inspect(1.0e10) == "1.0e10"
assert inspect(1.0e+10) == "1.0e10"
assert inspect(1.0e-10) == "1.0e-10"
end
end

Expand Down Expand Up @@ -155,7 +156,7 @@ defmodule Binary.Inspect.ListTest do
end

test :non_printable do
assert inspect([{:b, 1},{:a,1}]) == "[{:b,1},{:a,1}]"
assert inspect([{:b, 1},{:a,1}]) == "[{:b,1},{:a,1}]"
end

test :unproper do
Expand Down

0 comments on commit ab4c932

Please sign in to comment.