11defmodule Gradient.AstData do
2+ @ moduledoc """
3+ Stores the test cases data for expressions line specifying. To increase the flexibility
4+ the data need normalization before equality assertion. Thus we check only the line change,
5+ not the exact value and there is no need to update expected values when the file content
6+ changes.
7+
8+ This way of testing is useful only for more complex expressions in which we can observe
9+ some line change. For example, look at the pipe operator cases.
10+ """
11+
212 require Gradient.Debug
313 import Gradient.Debug , only: [ elixir_to_ast: 1 ]
414 import Gradient.TestHelpers
@@ -59,14 +69,6 @@ defmodule Gradient.AstData do
5969 [ { :integer , 56 , 1 } , { :atom , 55 , :ok } ] } }
6070 end
6171
62- defp example do
63- { __ENV__ . function ,
64- { __ENV__ . line ,
65- elixir_to_ast do
66- :ok
67- end , __ENV__ . line } , _expected = { } }
68- end
69-
7072 @ spec ast_data ( ) :: [
7173 { atom ( ) , { Types . abstract_expr ( ) , Types . tokens ( ) , Types . options ( ) } , tuple ( ) }
7274 ]
@@ -77,4 +79,17 @@ defmodule Gradient.AstData do
7779 { name , { ast , tokens , [ line: start_line , end_line: end_line ] } , expected }
7880 end )
7981 end
82+
83+ def normalize_expression ( expression ) do
84+ { expression , _ } =
85+ :erl_parse . mapfold_anno (
86+ fn anno , acc ->
87+ { { :erl_anno . line ( anno ) - acc , :erl_anno . column ( anno ) } , acc }
88+ end ,
89+ :erl_anno . line ( elem ( expression , 1 ) ) ,
90+ expression
91+ )
92+
93+ expression
94+ end
8095end
0 commit comments