Skip to content

Commit f90eeaa

Browse files
author
José Valim
committed
Fix map printing to indent 2 levels, closes #2165
1 parent 9451e69 commit f90eeaa

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

lib/elixir/lib/inspect.ex

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,8 @@ defimpl Inspect, for: BitString do
210210
end
211211
defp escape(<<>>, _char, binary), do: binary
212212

213-
214213
@doc false
215-
# also used by Regex
214+
# Also used by Regex
216215
def escape_char(char) when char in ?\000..?\377,
217216
do: octify(char)
218217

@@ -237,7 +236,6 @@ defimpl Inspect, for: BitString do
237236
defp to_hex(c) when c in 0..9, do: ?0+c
238237
defp to_hex(c) when c in 10..15, do: ?a+c-10
239238

240-
241239
defp append(<<h, t :: binary>>, binary), do: append(t, << binary :: binary, h >>)
242240
defp append(<<>>, binary), do: binary
243241

@@ -355,7 +353,7 @@ end
355353

356354
defimpl Inspect, for: Map do
357355
def inspect(map, opts) do
358-
inspect(map, "", opts)
356+
nest inspect(map, "", opts), 1
359357
end
360358

361359
def inspect(map, name, opts) do

lib/elixir/lib/inspect/algebra.ex

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ defmodule Inspect.Algebra do
180180
end
181181

182182
@doc """
183-
Returns `:doc_nil` which is a document entity used to represent
184-
nothingness. Takes no arguments.
183+
Returns a document entity used to represent nothingness.
185184
186185
## Examples
187186
@@ -193,8 +192,7 @@ defmodule Inspect.Algebra do
193192
def empty, do: :doc_nil
194193

195194
@doc """
196-
Concatenates two document entities. Takes two arguments:
197-
left doc and right doc. Returns a DocCons doc
195+
Concatenates two document entities.
198196
199197
## Examples
200198
@@ -216,15 +214,16 @@ defmodule Inspect.Algebra do
216214
folddoc(docs, &concat(&1, &2))
217215
end
218216

219-
@doc """
220-
Nests document entity `x` positions deep. Nesting will be
221-
appended to the line breaks.
217+
@doc ~S"""
218+
Nests document entity `x` positions deep.
219+
220+
Nesting will be appended to the line breaks.
222221
223222
## Examples
224223
225-
iex> doc = Inspect.Algebra.nest(Inspect.Algebra.concat(Inspect.Algebra.break, "6"), 5)
226-
iex> Inspect.Algebra.pretty(doc, 80)
227-
" 6"
224+
iex> doc = Inspect.Algebra.nest(Inspect.Algebra.glue("hello", "world"), 5)
225+
iex> Inspect.Algebra.pretty(doc, 5)
226+
"hello\n world"
228227
229228
"""
230229
@spec nest(t, non_neg_integer) :: doc_nest
@@ -237,9 +236,11 @@ defmodule Inspect.Algebra do
237236
end
238237

239238
@doc ~S"""
240-
Document entity representing a break. This break can
241-
be rendered as a linebreak or as spaces, depending on the
242-
`mode` of the chosen layout or the provided separator.
239+
Document entity representing a break.
240+
241+
This break can be rendered as a linebreak or as spaces,
242+
depending on the `mode` of the chosen layout or the provided
243+
separator.
243244
244245
## Examples
245246

lib/elixir/test/elixir/inspect_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ defmodule Inspect.MapTest do
214214

215215
test :basic do
216216
assert inspect(%{1 => "b"}) == "%{1 => \"b\"}"
217-
assert inspect(%{1 => "b", 2 => "c"}, [pretty: true, width: 1]) == "%{1 => \"b\",\n 2 => \"c\"}"
217+
assert inspect(%{1 => "b", 2 => "c"}, [pretty: true, width: 1]) == "%{1 => \"b\",\n 2 => \"c\"}"
218218
end
219219

220220
test :keyword do

0 commit comments

Comments
 (0)