@@ -624,57 +624,37 @@ defmodule ExUnit.DocTest do
624
624
end
625
625
end
626
626
627
- defp adjust_indent ( kind , [ line | rest ] , line_no , adjusted_lines , indent , module )
628
- when kind in [ :prompt , :after_prompt ] do
627
+ defp adjust_indent ( kind , [ line | rest ] , line_no , adjusted_lines , indent , module ) do
629
628
stripped_line = strip_indent ( line , indent )
629
+ trimmed_line = String . trim_leading ( line )
630
630
631
- case String . trim_leading ( line ) do
632
- "" ->
633
- :ok
634
-
635
- ^ stripped_line ->
636
- :ok
637
-
638
- _ ->
639
- n_spaces = if indent == 1 , do: "#{ indent } space" , else: "#{ indent } spaces"
631
+ if kind != :code and trimmed_line != stripped_line do
632
+ n_spaces = if indent == 1 , do: "#{ indent } space" , else: "#{ indent } spaces"
640
633
641
- raise Error ,
642
- line: line_no ,
643
- module: module ,
644
- message: """
645
- indentation level mismatch on doctest line: #{ inspect ( line ) }
634
+ raise Error ,
635
+ line: line_no ,
636
+ module: module ,
637
+ message: """
638
+ indentation level mismatch on doctest line: #{ inspect ( line ) }
646
639
647
- If you are planning to assert on the result of an `iex>` expression, \
648
- make sure the result is indented at the beginning of `iex>`, which \
649
- in this case is exactly #{ n_spaces } .
640
+ If you are planning to assert on the result of an `iex>` expression, \
641
+ make sure the result is indented at the beginning of `iex>`, which \
642
+ in this case is exactly #{ n_spaces } .
650
643
651
- If instead you have an `iex>` expression that spans over multiple lines, \
652
- please make sure that each line after the first one begins with `...>`.
653
- """
644
+ If instead you have an `iex>` expression that spans over multiple lines, \
645
+ please make sure that each line after the first one begins with `...>`.
646
+ """
654
647
end
655
648
656
- adjusted_lines = [ { adjust_prompt ( stripped_line , line_no , module ) , line_no } | adjusted_lines ]
657
-
658
- next =
659
- cond do
660
- kind == :prompt -> :after_prompt
661
- String . starts_with? ( stripped_line , @ iex_prompt ++ @ dot_prompt ) -> :after_prompt
662
- true -> :code
663
- end
664
-
665
- adjust_indent ( next , rest , line_no + 1 , adjusted_lines , indent , module )
666
- end
667
-
668
- defp adjust_indent ( :code , [ line | rest ] , line_no , adjusted_lines , indent , module ) do
669
- stripped_line = strip_indent ( line , indent )
670
-
671
649
cond do
672
650
stripped_line == "" or String . starts_with? ( stripped_line , @ fences ) ->
673
651
adjusted_lines = [ { "" , line_no } | adjusted_lines ]
674
652
adjust_indent ( :text , rest , line_no + 1 , adjusted_lines , 0 , module )
675
653
676
- String . starts_with? ( String . trim_leading ( stripped_line ) , @ iex_prompt ) ->
677
- adjust_indent ( :prompt , [ line | rest ] , line_no , adjusted_lines , indent , module )
654
+ kind == :prompt or String . starts_with? ( trimmed_line , @ iex_prompt ) or
655
+ ( kind == :maybe_prompt and String . starts_with? ( trimmed_line , @ dot_prompt ) ) ->
656
+ line = { adjust_prompt ( stripped_line , line_no , module ) , line_no }
657
+ adjust_indent ( :maybe_prompt , rest , line_no + 1 , [ line | adjusted_lines ] , indent , module )
678
658
679
659
true ->
680
660
adjusted_lines = [ { stripped_line , line_no } | adjusted_lines ]
0 commit comments