Skip to content

Commit c0bb6d7

Browse files
author
Gustavo Brunoro
committed
kwlist are inspected as a list of tuples with raw: true
1 parent d195429 commit c0bb6d7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/elixir/lib/inspect.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ defimpl Inspect, for: List do
215215
cond do
216216
:io_lib.printable_list(thing) ->
217217
<< ?', String.escape(:unicode.characters_to_binary(thing), ?') :: binary, ?' >>
218-
keyword?(thing) ->
218+
keyword?(thing) && !opts.raw ->
219219
surround_many("[", thing, "]", opts.limit, keyword(&1, opts))
220220
true ->
221221
surround_many("[", thing, "]", opts.limit, Kernel.inspect(&1, opts))

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ defmodule Inspect.ListTest do
180180
"[foo: [1, 2, 3, :bar],\n bazzz: :bat]"
181181
end
182182

183+
test :keyword_with_raw do
184+
assert inspect([a: 1], raw: true) == "[{:a, 1}]"
185+
assert inspect([a: 1, b: 2], raw: true) == "[{:a, 1}, {:b, 2}]"
186+
assert inspect([a: 1, a: 2, b: 2], raw: true) == "[{:a, 1}, {:a, 2}, {:b, 2}]"
187+
end
188+
183189
test :non_keyword do
184190
assert inspect([{ Regex, 1 }]) == "[{Regex, 1}]"
185191
end

0 commit comments

Comments
 (0)