Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/nimble_options/validation_error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ defmodule NimbleOptions.ValidationError do
|> Map.drop([:__struct__, :__exception__])
|> Map.update!(:value, &if(redacted?, do: "**redacted**", else: &1))
|> Enum.sort_by(fn {key, _val} -> key end)
|> Enum.map(fn {key, val} -> [string("#{key}:"), break(), to_doc(val, opts)] end)
|> Enum.intersperse([string(","), break()])
|> List.flatten()
|> Enum.map(fn {key, val} -> concat([string("#{key}: "), to_doc(val, opts)]) end)
|> Enum.intersperse(string(", "))

concat(["##{inspect(@for)}<"] ++ fields ++ [">"])
concat(["##{inspect(@for)}<", concat(fields), ">"])
end
end
end
10 changes: 10 additions & 0 deletions test/nimble_options/validation_error_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ defmodule NimbleOptions.ValidationErrorTest do
~s(#NimbleOptions.ValidationError<key: :foo, keys_path: [], message: "invalid value for :foo option: expected integer, got: true", redact: false, value: true>)
end

test "with syntax colors" do
schema = [foo: [type: :integer]]
opts = [foo: true]

{:error, error} = NimbleOptions.validate(opts, schema)

assert inspect(error, syntax_colors: [atom: :red]) ==
~s(#NimbleOptions.ValidationError<key: \e[31m:foo\e[0m, keys_path: [], message: "invalid value for :foo option: expected integer, got: true", redact: false, value: true>)
end

test "with a redacted option" do
schema = [foo: [type: :integer, redact: true]]

Expand Down
Loading