1
1
defmodule 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
+
2
12
require Gradient.Debug
3
13
import Gradient.Debug , only: [ elixir_to_ast: 1 ]
4
14
import Gradient.TestHelpers
@@ -59,14 +69,6 @@ defmodule Gradient.AstData do
59
69
[ { :integer , 56 , 1 } , { :atom , 55 , :ok } ] } }
60
70
end
61
71
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
-
70
72
@ spec ast_data ( ) :: [
71
73
{ atom ( ) , { Types . abstract_expr ( ) , Types . tokens ( ) , Types . options ( ) } , tuple ( ) }
72
74
]
@@ -77,4 +79,17 @@ defmodule Gradient.AstData do
77
79
{ name , { ast , tokens , [ line: start_line , end_line: end_line ] } , expected }
78
80
end )
79
81
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
80
95
end
0 commit comments