diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8b87cba --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.diff] +trim_trailing_whitespace=false diff --git a/bin/smoke_test.exs b/bin/smoke_test.exs index db37b0c..2a6f655 100755 --- a/bin/smoke_test.exs +++ b/bin/smoke_test.exs @@ -42,12 +42,11 @@ Enum.each(projects, fn project -> {_, 0} = System.cmd("mix", ["compile"], cd: project_path) end + {_, 0} = System.cmd("mix", ["test"], cd: project_path) {_, 0} = System.cmd("mix", ["format"], cd: project_path) {diff, 0} = System.cmd("git", ["diff"], cd: project_path) - Code.eval_file("#{project_path}/expected_diff.ex") - - expected_diff = ExpectedDiff.diff() + expected_diff = File.read!("#{project_path}/expected_diff.diff") :code.delete(ExpectedDiff) :code.purge(ExpectedDiff) diff --git a/smoke_test_data/elixir-1-13/project_with_formatted_code/expected_diff.diff b/smoke_test_data/elixir-1-13/project_with_formatted_code/expected_diff.diff new file mode 100644 index 0000000..e69de29 diff --git a/smoke_test_data/elixir-1-13/project_with_formatted_code/expected_diff.ex b/smoke_test_data/elixir-1-13/project_with_formatted_code/expected_diff.ex deleted file mode 100644 index d4a2089..0000000 --- a/smoke_test_data/elixir-1-13/project_with_formatted_code/expected_diff.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule ExpectedDiff do - def diff do - "" - end -end diff --git a/smoke_test_data/elixir-1-13/project_with_formatted_code/lib/project_with_formatted_code.ex b/smoke_test_data/elixir-1-13/project_with_formatted_code/lib/project_with_formatted_code.ex index 3ca5dab..b223feb 100644 --- a/smoke_test_data/elixir-1-13/project_with_formatted_code/lib/project_with_formatted_code.ex +++ b/smoke_test_data/elixir-1-13/project_with_formatted_code/lib/project_with_formatted_code.ex @@ -18,7 +18,7 @@ defmodule ProjectWithFormattedCode do ...> |> ProjectWithFormattedCode.add(2) 3 - iex> 3 + "3" + iex> ProjectWithFormattedCode.add(3, "3") ** (ArithmeticError) bad argument in arithmetic expression """ diff --git a/smoke_test_data/elixir-1-13/project_with_unformatted_code/expected_diff.diff b/smoke_test_data/elixir-1-13/project_with_unformatted_code/expected_diff.diff new file mode 100644 index 0000000..19b52ce --- /dev/null +++ b/smoke_test_data/elixir-1-13/project_with_unformatted_code/expected_diff.diff @@ -0,0 +1,54 @@ +diff --git a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex +index 5b65e4d..98f817c 100644 +--- a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex ++++ b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex +@@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do + @moduledoc """ + Documentation for `ProjectWithUnformattedCode`. + +- iex> ProjectWithUnformattedCode.add(5,5) ++ iex> ProjectWithUnformattedCode.add(5, 5) + 10 + """ + +@@ -15,7 +15,7 @@ defmodule ProjectWithUnformattedCode do + 3 + + iex> 1 +- ...> |> ProjectWithUnformattedCode.add(2) ++ ...> |> ProjectWithUnformattedCode.add(2) + 3 + + """ +@@ -24,12 +24,28 @@ defmodule ProjectWithUnformattedCode do + end + + @doc """ +- iex> ProjectWithUnformattedCode.subtract( 5, 4 ) ++ iex> ProjectWithUnformattedCode.subtract(5, 4) + 1 + +- iex> [100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000, 700_000_000_000] ++ iex> [ ++ ...> 100_000_000_000, ++ ...> 200_000_000_000, ++ ...> 300_000_000_000, ++ ...> 400_000_000_000, ++ ...> 500_000_000_000, ++ ...> 600_000_000_000, ++ ...> 700_000_000_000 ++ ...> ] + ...> |> Enum.map(&ProjectWithUnformattedCode.subtract(&1, 100_000_000_000)) +- [0, 100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000] ++ [ ++ 0, ++ 100_000_000_000, ++ 200_000_000_000, ++ 300_000_000_000, ++ 400_000_000_000, ++ 500_000_000_000, ++ 600_000_000_000 ++ ] + """ + def subtract(a, b) do + a - b diff --git a/smoke_test_data/elixir-1-13/project_with_unformatted_code/expected_diff.ex b/smoke_test_data/elixir-1-13/project_with_unformatted_code/expected_diff.ex deleted file mode 100644 index 0c83d36..0000000 --- a/smoke_test_data/elixir-1-13/project_with_unformatted_code/expected_diff.ex +++ /dev/null @@ -1,62 +0,0 @@ -defmodule ExpectedDiff do - def diff do - """ - diff --git a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex - index 730bd33..50b6379 100644 - --- a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex - +++ b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex - @@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do - @moduledoc """ - Documentation for `ProjectWithUnformattedCode`. - #{" "} - - iex> ProjectWithFormattedCode.add(5,5) - + iex> ProjectWithFormattedCode.add(5, 5) - 10 - \""" - #{" "} - @@ -15,8 +15,8 @@ defmodule ProjectWithUnformattedCode do - 3 - #{" "} - iex> 1 - - ...> |> ProjectWithUnformattedCode.add(2) - - 3 - + ...> |> ProjectWithUnformattedCode.add(2) - + 3 - #{" "} - \""" - def add(a, b) do - @@ -24,12 +24,28 @@ defmodule ProjectWithUnformattedCode do - end - #{" "} - @doc \""" - - iex> ProjectWithUnformattedCode.subtract( 5, 4 ) - + iex> ProjectWithUnformattedCode.subtract(5, 4) - 1 - #{" "} - - iex> [100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000, 700_000_000_000] - + iex> [ - + ...> 100_000_000_000, - + ...> 200_000_000_000, - + ...> 300_000_000_000, - + ...> 400_000_000_000, - + ...> 500_000_000_000, - + ...> 600_000_000_000, - + ...> 700_000_000_000 - + ...> ] - ...> |> Enum.map(&ProjectWithUnformattedCode.subtract(&1, 100_000_000_000)) - - [0, 100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000] - + [ - + 0, - + 100_000_000_000, - + 200_000_000_000, - + 300_000_000_000, - + 400_000_000_000, - + 500_000_000_000, - + 600_000_000_000 - + ] - \""" - def subtract(a, b) do - a - b - """ - end -end diff --git a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex index 730bd33..5b65e4d 100644 --- a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex +++ b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex @@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do @moduledoc """ Documentation for `ProjectWithUnformattedCode`. - iex> ProjectWithFormattedCode.add(5,5) + iex> ProjectWithUnformattedCode.add(5,5) 10 """ @@ -16,7 +16,7 @@ defmodule ProjectWithUnformattedCode do iex> 1 ...> |> ProjectWithUnformattedCode.add(2) - 3 + 3 """ def add(a, b) do diff --git a/smoke_test_data/elixir-1-13/project_with_unformatted_code/test/project_with_unformatted_code_test.exs b/smoke_test_data/elixir-1-13/project_with_unformatted_code/test/project_with_unformatted_code_test.exs index e7d30a9..f0066dd 100644 --- a/smoke_test_data/elixir-1-13/project_with_unformatted_code/test/project_with_unformatted_code_test.exs +++ b/smoke_test_data/elixir-1-13/project_with_unformatted_code/test/project_with_unformatted_code_test.exs @@ -1,8 +1,4 @@ defmodule ProjectWithUnformattedCodeTest do use ExUnit.Case doctest ProjectWithUnformattedCode - - test "greets the world" do - assert ProjectWithUnformattedCode.hello() == :world - end end diff --git a/smoke_test_data/project_with_formatted_code/expected_diff.diff b/smoke_test_data/project_with_formatted_code/expected_diff.diff new file mode 100644 index 0000000..e69de29 diff --git a/smoke_test_data/project_with_formatted_code/expected_diff.ex b/smoke_test_data/project_with_formatted_code/expected_diff.ex deleted file mode 100644 index d4a2089..0000000 --- a/smoke_test_data/project_with_formatted_code/expected_diff.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule ExpectedDiff do - def diff do - "" - end -end diff --git a/smoke_test_data/project_with_formatted_code/lib/project_with_formatted_code.ex b/smoke_test_data/project_with_formatted_code/lib/project_with_formatted_code.ex index 3ca5dab..b223feb 100644 --- a/smoke_test_data/project_with_formatted_code/lib/project_with_formatted_code.ex +++ b/smoke_test_data/project_with_formatted_code/lib/project_with_formatted_code.ex @@ -18,7 +18,7 @@ defmodule ProjectWithFormattedCode do ...> |> ProjectWithFormattedCode.add(2) 3 - iex> 3 + "3" + iex> ProjectWithFormattedCode.add(3, "3") ** (ArithmeticError) bad argument in arithmetic expression """ diff --git a/smoke_test_data/project_with_unformatted_code/expected_diff.diff b/smoke_test_data/project_with_unformatted_code/expected_diff.diff new file mode 100644 index 0000000..03bbee0 --- /dev/null +++ b/smoke_test_data/project_with_unformatted_code/expected_diff.diff @@ -0,0 +1,54 @@ +diff --git a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex +index 5b65e4d..98f817c 100644 +--- a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex ++++ b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex +@@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do + @moduledoc """ + Documentation for `ProjectWithUnformattedCode`. + +- iex> ProjectWithUnformattedCode.add(5,5) ++ iex> ProjectWithUnformattedCode.add(5, 5) + 10 + """ + +@@ -15,7 +15,7 @@ defmodule ProjectWithUnformattedCode do + 3 + + iex> 1 +- ...> |> ProjectWithUnformattedCode.add(2) ++ ...> |> ProjectWithUnformattedCode.add(2) + 3 + + """ +@@ -24,12 +24,28 @@ defmodule ProjectWithUnformattedCode do + end + + @doc """ +- iex> ProjectWithUnformattedCode.subtract( 5, 4 ) ++ iex> ProjectWithUnformattedCode.subtract(5, 4) + 1 + +- iex> [100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000, 700_000_000_000] ++ iex> [ ++ ...> 100_000_000_000, ++ ...> 200_000_000_000, ++ ...> 300_000_000_000, ++ ...> 400_000_000_000, ++ ...> 500_000_000_000, ++ ...> 600_000_000_000, ++ ...> 700_000_000_000 ++ ...> ] + ...> |> Enum.map(&ProjectWithUnformattedCode.subtract(&1, 100_000_000_000)) +- [0, 100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000] ++ [ ++ 0, ++ 100_000_000_000, ++ 200_000_000_000, ++ 300_000_000_000, ++ 400_000_000_000, ++ 500_000_000_000, ++ 600_000_000_000 ++ ] + """ + def subtract(a, b) do + a - b diff --git a/smoke_test_data/project_with_unformatted_code/expected_diff.ex b/smoke_test_data/project_with_unformatted_code/expected_diff.ex deleted file mode 100644 index e2406bc..0000000 --- a/smoke_test_data/project_with_unformatted_code/expected_diff.ex +++ /dev/null @@ -1,62 +0,0 @@ -defmodule ExpectedDiff do - def diff do - """ - diff --git a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex - index 730bd33..50b6379 100644 - --- a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex - +++ b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex - @@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do - @moduledoc """ - Documentation for `ProjectWithUnformattedCode`. - #{" "} - - iex> ProjectWithFormattedCode.add(5,5) - + iex> ProjectWithFormattedCode.add(5, 5) - 10 - \""" - #{" "} - @@ -15,8 +15,8 @@ defmodule ProjectWithUnformattedCode do - 3 - #{" "} - iex> 1 - - ...> |> ProjectWithUnformattedCode.add(2) - - 3 - + ...> |> ProjectWithUnformattedCode.add(2) - + 3 - #{" "} - \""" - def add(a, b) do - @@ -24,12 +24,28 @@ defmodule ProjectWithUnformattedCode do - end - #{" "} - @doc \""" - - iex> ProjectWithUnformattedCode.subtract( 5, 4 ) - + iex> ProjectWithUnformattedCode.subtract(5, 4) - 1 - #{" "} - - iex> [100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000, 700_000_000_000] - + iex> [ - + ...> 100_000_000_000, - + ...> 200_000_000_000, - + ...> 300_000_000_000, - + ...> 400_000_000_000, - + ...> 500_000_000_000, - + ...> 600_000_000_000, - + ...> 700_000_000_000 - + ...> ] - ...> |> Enum.map(&ProjectWithUnformattedCode.subtract(&1, 100_000_000_000)) - - [0, 100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000] - + [ - + 0, - + 100_000_000_000, - + 200_000_000_000, - + 300_000_000_000, - + 400_000_000_000, - + 500_000_000_000, - + 600_000_000_000 - + ] - \""" - def subtract(a, b) do - a - b - """ - end -end diff --git a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex index 730bd33..5b65e4d 100644 --- a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex +++ b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex @@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do @moduledoc """ Documentation for `ProjectWithUnformattedCode`. - iex> ProjectWithFormattedCode.add(5,5) + iex> ProjectWithUnformattedCode.add(5,5) 10 """ @@ -16,7 +16,7 @@ defmodule ProjectWithUnformattedCode do iex> 1 ...> |> ProjectWithUnformattedCode.add(2) - 3 + 3 """ def add(a, b) do diff --git a/smoke_test_data/project_with_unformatted_code/test/project_with_unformatted_code_test.exs b/smoke_test_data/project_with_unformatted_code/test/project_with_unformatted_code_test.exs index e7d30a9..f0066dd 100644 --- a/smoke_test_data/project_with_unformatted_code/test/project_with_unformatted_code_test.exs +++ b/smoke_test_data/project_with_unformatted_code/test/project_with_unformatted_code_test.exs @@ -1,8 +1,4 @@ defmodule ProjectWithUnformattedCodeTest do use ExUnit.Case doctest ProjectWithUnformattedCode - - test "greets the world" do - assert ProjectWithUnformattedCode.hello() == :world - end end diff --git a/test/doctest_formatter/formatter_test.exs b/test/doctest_formatter/formatter_test.exs index 365ff96..309230c 100644 --- a/test/doctest_formatter/formatter_test.exs +++ b/test/doctest_formatter/formatter_test.exs @@ -181,15 +181,17 @@ defmodule DoctestFormatter.FormatterTest do output = format(input, []) assert output == desired_output end + end - test "keeps the indent level of the start of the code block" do + describe "format/2 on @moduledocs" do + test "formats doctests in moduledocs, multiline string" do input = """ defmodule Foo do - @doc \""" + @moduledoc \""" It adds two numbers together - iex> Foo.add 4,2 - 6 + iex> Foo.add(4,2) + 6 \""" @spec add(a :: integer, b :: integer) :: integer def add(a, b) do @@ -201,10 +203,10 @@ defmodule DoctestFormatter.FormatterTest do desired_output = """ defmodule Foo do - @doc \""" + @moduledoc \""" It adds two numbers together - iex> Foo.add(4, 2) - 6 + iex> Foo.add(4, 2) + 6 \""" @spec add(a :: integer, b :: integer) :: integer def add(a, b) do @@ -217,6 +219,95 @@ defmodule DoctestFormatter.FormatterTest do assert output == desired_output end + test "formats doctests in moduledocs, single line string" do + input = + """ + defmodule Foo do + @moduledoc \"It adds two numbers together\niex> Foo.add(4,2)\n6\" + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + desired_output = + """ + defmodule Foo do + @moduledoc \"It adds two numbers together\niex> Foo.add(4, 2)\n6\" + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + output = format(input, []) + assert output == desired_output + end + + test "formats doctests in moduledocs, lowercase s sigil string" do + input = + """ + defmodule Foo do + @moduledoc ~s/It adds two numbers together\niex> Foo.add(4,2)\n6/ + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + desired_output = + """ + defmodule Foo do + @moduledoc ~s/It adds two numbers together\niex> Foo.add(4, 2)\n6/ + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + output = format(input, []) + assert output == desired_output + end + + test "formats doctests in moduledocs, uppercase s sigil string" do + input = + """ + defmodule Foo do + @moduledoc ~S/It adds two numbers together + iex> Foo.add(4,2) + 6 + / + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + desired_output = + """ + defmodule Foo do + @moduledoc ~S/It adds two numbers together + iex> Foo.add(4, 2) + 6 + / + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + output = format(input, []) + assert output == desired_output + end + end + + describe "format/2 on single line doctests" do test "respects formatter options" do opts = [locals_without_parens: [add: 2], force_do_end_blocks: true] @@ -254,6 +345,61 @@ defmodule DoctestFormatter.FormatterTest do assert output == desired_output end + test "different integer formats" do + input = + """ + defmodule IntegerFormats do + @doc \""" + iex> ?A + 0x41 + + iex> 0b1000001 + 65 + + iex> 0x00 + 0b00 + + iex> 0b1000001 + 65 + \""" + + def func do + [?A, ?B, ?C] + [0x41, 0x42, 0x43] + [0b1000001, 0b1000010, 0b1000011] + end + end + """ + + desired_output = + """ + defmodule IntegerFormats do + @doc \""" + iex> ?A + 0x41 + + iex> 0b1000001 + 65 + + iex> 0x00 + 0b00 + + iex> 0b1000001 + 65 + \""" + + def func do + [?A, ?B, ?C] + [0x41, 0x42, 0x43] + [0b1000001, 0b1000010, 0b1000011] + end + end + """ + + output = format(input, []) + assert output == desired_output + end + test "keeps line number in iex>() prompt" do input = """ @@ -311,7 +457,9 @@ defmodule DoctestFormatter.FormatterTest do output = format(input, []) assert output == desired_output end + end + describe "format/2 on multiline doctests" do test "multiline doctest" do input = """ @@ -542,6 +690,43 @@ defmodule DoctestFormatter.FormatterTest do output = format(input, []) assert output == desired_output end + end + + describe "format/2 indentation" do + test "keeps the indent level of the start of the code block" do + input = + """ + defmodule Foo do + @doc \""" + It adds two numbers together + iex> Foo.add 4,2 + 6 + \""" + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + desired_output = + """ + defmodule Foo do + @doc \""" + It adds two numbers together + iex> Foo.add(4, 2) + 6 + \""" + @spec add(a :: integer, b :: integer) :: integer + def add(a, b) do + a + b + end + end + """ + + output = format(input, []) + assert output == desired_output + end test "multiline expected result indentation" do input = @@ -832,7 +1017,9 @@ defmodule DoctestFormatter.FormatterTest do output = format(input, opts) assert output == desired_output end + end + describe "format/2 on exceptions" do test "can handle exceptions in results" do input = """ @@ -862,130 +1049,4 @@ defmodule DoctestFormatter.FormatterTest do assert output == desired_output end end - - describe "format/2 on @moduledocs" do - test "formats doctests in moduledocs, multiline string" do - input = - """ - defmodule Foo do - @moduledoc \""" - It adds two numbers together - iex> Foo.add(4,2) - 6 - \""" - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - desired_output = - """ - defmodule Foo do - @moduledoc \""" - It adds two numbers together - iex> Foo.add(4, 2) - 6 - \""" - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - output = format(input, []) - assert output == desired_output - end - - test "formats doctests in moduledocs, single line string" do - input = - """ - defmodule Foo do - @moduledoc \"It adds two numbers together\niex> Foo.add(4,2)\n6\" - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - desired_output = - """ - defmodule Foo do - @moduledoc \"It adds two numbers together\niex> Foo.add(4, 2)\n6\" - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - output = format(input, []) - assert output == desired_output - end - - test "formats doctests in moduledocs, lowercase s sigil string" do - input = - """ - defmodule Foo do - @moduledoc ~s/It adds two numbers together\niex> Foo.add(4,2)\n6/ - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - desired_output = - """ - defmodule Foo do - @moduledoc ~s/It adds two numbers together\niex> Foo.add(4, 2)\n6/ - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - output = format(input, []) - assert output == desired_output - end - - test "formats doctests in moduledocs, uppercase s sigil string" do - input = - """ - defmodule Foo do - @moduledoc ~S/It adds two numbers together - iex> Foo.add(4,2) - 6 - / - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - desired_output = - """ - defmodule Foo do - @moduledoc ~S/It adds two numbers together - iex> Foo.add(4, 2) - 6 - / - @spec add(a :: integer, b :: integer) :: integer - def add(a, b) do - a + b - end - end - """ - - output = format(input, []) - assert output == desired_output - end - end - - # TODO: test string interpolation? end