Skip to content

Commit

Permalink
Fix indentation in multiline result
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Feb 25, 2024
1 parent 79e1a86 commit 3cd7dd9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/doctest_formatter/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ defmodule DoctestFormatter.Formatter do
|> Enum.join("\n")
|> Code.format_string!(opts)
|> IO.iodata_to_binary()
|> Indentation.indent(chunk.indentation)
|> String.split("\n")
|> Enum.map(fn line ->
Indentation.indent(line, chunk.indentation)
end)

formatted_lines ++ [formatted_result]
formatted_lines ++ formatted_result
end
end
35 changes: 35 additions & 0 deletions test/doctest_formatter/formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,41 @@ defmodule DoctestFormatter.FormatterTest do
assert output == desired_output
end

test "multiline expected result indentation" do
input =
"""
defmodule Foo do
@doc \"""
It concatenates two strings together
iex> ~T[01:02:03]
%Time{
hour: 1,
minute: 2,
second: 3
}
\"""
end
"""

desired_output =
"""
defmodule Foo do
@doc \"""
It concatenates two strings together
iex> ~T[01:02:03]
%Time{
hour: 1,
minute: 2,
second: 3
}
\"""
end
"""

output = format(input, [])
assert output == desired_output
end

test "multiple tests in single doc" do
input =
"""
Expand Down

0 comments on commit 3cd7dd9

Please sign in to comment.