Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: BjRo/apex
base: 4226b3397b
...
head fork: BjRo/apex
compare: b26da2afa3
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 36 additions and 10 deletions.
  1. +15 −7 lib/apex/format.ex
  2. +10 −3 lib/apex/format/tuple.ex
  3. +11 −0 test/format_test.exs
View
22 lib/apex/format.ex
@@ -3,11 +3,15 @@ defprotocol Apex.Format do
end
defimpl Apex.Format, for: BitString do
- def format(data, _ // []), do: "\"#{data}\"" <> Apex.Format.Utils.new_line
+ def format(data, _ // []) do
+ "\"#{data}\"" <> Apex.Format.Utils.new_line
+ end
end
defimpl Apex.Format, for: Integer do
- def format(data, _ // []), do: "#{data}" <> Apex.Format.Utils.new_line
+ def format(data, _ // []) do
+ "#{data}" <> Apex.Format.Utils.new_line
+ end
end
defimpl Apex.Format, for: Float do
@@ -17,27 +21,31 @@ defimpl Apex.Format, for: Float do
end
defimpl Apex.Format, for: Atom do
- def format(data, _ // []), do: "#{data}" <> Apex.Format.Utils.new_line
+ def format(data, _ // []) do
+ "#{data}" <> Apex.Format.Utils.new_line
+ end
end
defimpl Apex.Format, for: List do
- def format(data, options // []), do: Apex.Format.Seq.format(data, options)
+ def format(data, options // []) do
+ Apex.Format.Seq.format(data, options)
+ end
end
defimpl Apex.Format, for: Range do
- def format({name, lower_bound, upper_bound}, options // []) do
+ def format({name, lower_bound, upper_bound}, _ // []) do
"##{name} #{lower_bound}..#{upper_bound}" <> Apex.Format.Utils.new_line
end
end
defimpl Apex.Format, for: PID do
- def format(data, options // []) do
+ def format(data, _ // []) do
inspect(data) <> Apex.Format.Utils.new_line
end
end
defimpl Apex.Format, for: Function do
- def format(data, options // []) do
+ def format(data, _ // []) do
inspect(data) <> Apex.Format.Utils.new_line
end
end
View
13 lib/apex/format/tuple.ex
@@ -1,19 +1,26 @@
defimpl Apex.Format, for: Tuple do
import Apex.Format.Utils
+ alias Apex.Format.Seq
- def format(data, options // []), do: do_format(data, options)
+ def format(data, options // []) do
+ do_format(data, options)
+ end
defp do_format({key, value}, options) when is_atom(key) do
"#{key}: " <> Apex.Format.format(value, options)
end
- defp do_format(data, options) do
+ defp do_format(data, options) when is_record(data) do
{pre, entries} = if function_exported?(data, :__record__, 1) do
{ "##{data.__record__(:name)} {", data.to_keywords }
else
{ "{", tuple_to_list(data) }
end
- Apex.Format.Seq.format(entries, options, start_token: pre, end_token: "}")
+ Seq.format(entries, options, start_token: pre, end_token: "}")
+ end
+
+ defp do_format(data, options) do
+ Seq.format(tuple_to_list(data), options, start_token: "{", end_token: "}")
end
end
View
11 test/format_test.exs
@@ -59,6 +59,17 @@ defmodule Apex.Format.Test do
"""
end
+ test "Can format that don't start with an atom" do
+ assert format({1, "John", 1, true}, color: false) == """
+ {
+ [0] 1
+ [1] "John"
+ [2] 1
+ [3] true
+ }
+ """
+ end
+
defrecord User, first_name: nil, last_name: nil
test "Can format records" do
assert format(User.new(first_name: "John", last_name: "Doe"), color: false) == """

No commit comments for this range

Something went wrong with that request. Please try again.