@@ -57,7 +57,7 @@ defmodule Kernel.ParserTest do
57
57
58
58
describe "strings/sigils" do
59
59
test "delimiter information for sigils is included" do
60
- string_to_quoted = & Code . string_to_quoted! ( & 1 , token_metadata: false )
60
+ string_to_quoted = & Code . string_to_quoted! ( & 1 , token_metadata: false , columns: false )
61
61
62
62
assert parse! ( "~r/foo/" ) ==
63
63
{ :sigil_r , [ delimiter: "/" , line: 1 ] , [ { :<<>> , [ line: 1 ] , [ "foo" ] } , [ ] ] }
@@ -78,39 +78,37 @@ defmodule Kernel.ParserTest do
78
78
end
79
79
80
80
test "sigil newlines" do
81
- assert { :sigil_s , _ , [ { :<<>> , _ , [ "here\n doc" ] } , [ ] ] } =
82
- Code . string_to_quoted! ( ~s| ~s"here\n doc"| )
81
+ assert { :sigil_s , _ , [ { :<<>> , _ , [ "here\n doc" ] } , [ ] ] } = parse! ( ~s| ~s"here\n doc"| )
83
82
84
- assert { :sigil_s , _ , [ { :<<>> , _ , [ "here\r \n doc" ] } , [ ] ] } =
85
- Code . string_to_quoted! ( ~s| ~s"here\r \n doc"| )
83
+ assert { :sigil_s , _ , [ { :<<>> , _ , [ "here\r \n doc" ] } , [ ] ] } = parse! ( ~s| ~s"here\r \n doc"| )
86
84
end
87
85
88
86
test "string newlines" do
89
- assert Code . string_to_quoted !( ~s| "here\n doc"| ) == "here\n doc"
90
- assert Code . string_to_quoted !( ~s| "here\r \n doc"| ) == "here\r \n doc"
91
- assert Code . string_to_quoted !( ~s| "here\\ \n doc"| ) == "heredoc"
92
- assert Code . string_to_quoted !( ~s| "here\\ \r \n doc"| ) == "heredoc"
87
+ assert parse !( ~s| "here\n doc"| ) == "here\n doc"
88
+ assert parse !( ~s| "here\r \n doc"| ) == "here\r \n doc"
89
+ assert parse !( ~s| "here\\ \n doc"| ) == "heredoc"
90
+ assert parse !( ~s| "here\\ \r \n doc"| ) == "heredoc"
93
91
end
94
92
95
93
test "heredoc newlines" do
96
- assert Code . string_to_quoted !( ~s| """\n here\n doc\n """| ) == "here\n doc\n "
97
- assert Code . string_to_quoted !( ~s| """\r \n here\r \n doc\r \n """| ) == "here\r \n doc\r \n "
98
- assert Code . string_to_quoted !( ~s| """\n here\n doc\n """| ) == "here\n doc\n "
99
- assert Code . string_to_quoted !( ~s| """\r \n here\r \n doc\r \n """| ) == "here\r \n doc\r \n "
100
- assert Code . string_to_quoted !( ~s| """\n here\\ \n doc\\ \n """| ) == "heredoc"
101
- assert Code . string_to_quoted !( ~s| """\r \n here\\ \r \n doc\\ \r \n """| ) == "heredoc"
94
+ assert parse !( ~s| """\n here\n doc\n """| ) == "here\n doc\n "
95
+ assert parse !( ~s| """\r \n here\r \n doc\r \n """| ) == "here\r \n doc\r \n "
96
+ assert parse !( ~s| """\n here\n doc\n """| ) == "here\n doc\n "
97
+ assert parse !( ~s| """\r \n here\r \n doc\r \n """| ) == "here\r \n doc\r \n "
98
+ assert parse !( ~s| """\n here\\ \n doc\\ \n """| ) == "heredoc"
99
+ assert parse !( ~s| """\r \n here\\ \r \n doc\\ \r \n """| ) == "heredoc"
102
100
end
103
101
104
102
test "heredoc indentation" do
105
103
meta = [ delimiter: "'''" , line: 1 ]
106
104
args = { :sigil_S , meta , [ { :<<>> , [ indentation: 2 , line: 1 ] , [ " sigil heredoc\n " ] } , [ ] ] }
107
- assert Code . string_to_quoted !( "~S'''\n sigil heredoc\n '''" ) == args
105
+ assert parse !( "~S'''\n sigil heredoc\n '''" ) == args
108
106
end
109
107
end
110
108
111
109
describe "string_to_quoted/2" do
112
110
test "converts strings to quoted expressions" do
113
- assert Code . string_to_quoted ( "1 + 2" ) == { :ok , { :+ , [ line: 1 ] , [ 1 , 2 ] } }
111
+ assert Code . string_to_quoted ( "1 + 2" ) == { :ok , { :+ , [ line: 1 , column: 3 ] , [ 1 , 2 ] } }
114
112
115
113
assert Code . string_to_quoted ( "a.1" ) ==
116
114
{ :error , { [ line: 1 , column: 3 ] , "syntax error before: " , "\" 1\" " } }
@@ -150,7 +148,7 @@ defmodule Kernel.ParserTest do
150
148
{ :ok , { :my , "atom" , ref } }
151
149
end
152
150
153
- assert { :ok , { { :my , "atom" , ^ ref } , [ line: 1 ] , nil } } =
151
+ assert { :ok , { { :my , "atom" , ^ ref } , [ line: 1 , column: 1 ] , nil } } =
154
152
Code . string_to_quoted ( "there_is_no_such_var" , static_atoms_encoder: encoder )
155
153
end
156
154
@@ -181,20 +179,21 @@ defmodule Kernel.ParserTest do
181
179
182
180
test "does not encode keywords" do
183
181
encoder = fn atom , _meta -> raise "shouldn't be invoked for #{ atom } " end
182
+ string_to_quoted = & Code . string_to_quoted ( & 1 , static_atoms_encoder: encoder , columns: false )
184
183
185
184
assert { :ok , { :fn , [ line: 1 ] , [ { :-> , [ line: 1 ] , [ [ 1 ] , 2 ] } ] } } =
186
- Code . string_to_quoted ( "fn 1 -> 2 end" , static_atoms_encoder: encoder )
185
+ string_to_quoted . ( "fn 1 -> 2 end" )
187
186
188
- assert { :ok , { :or , [ line: 1 ] , [ true , false ] } } =
189
- Code . string_to_quoted ( "true or false" , static_atoms_encoder: encoder )
187
+ assert { :ok , { :or , [ line: 1 ] , [ true , false ] } } = string_to_quoted . ( "true or false" )
190
188
191
189
encoder = fn atom , _meta -> { :ok , { :encoded , atom } } end
190
+ string_to_quoted = & Code . string_to_quoted ( & 1 , static_atoms_encoder: encoder , columns: false )
192
191
193
192
assert { :ok , [ encoded: "true" , encoded: "do" , encoded: "and" ] } =
194
- Code . string_to_quoted ( "[:true, :do, :and]" , static_atoms_encoder: encoder )
193
+ string_to_quoted . ( "[:true, :do, :and]" )
195
194
196
195
assert { :ok , [ { { :encoded , "do" } , 1 } , { { :encoded , "true" } , 2 } , { { :encoded , "end" } , 3 } ] } =
197
- Code . string_to_quoted ( "[do: 1, true: 2, end: 3]" , static_atoms_encoder: encoder )
196
+ string_to_quoted . ( "[do: 1, true: 2, end: 3]" )
198
197
end
199
198
200
199
test "returns errors on long atoms even when using static_atoms_encoder" do
@@ -304,7 +303,7 @@ defmodule Kernel.ParserTest do
304
303
end
305
304
306
305
test "adds pairing information" do
307
- string_to_quoted = & Code . string_to_quoted! ( & 1 , token_metadata: true )
306
+ string_to_quoted = & Code . string_to_quoted! ( & 1 , token_metadata: true , columns: false )
308
307
309
308
assert string_to_quoted . ( "foo" ) == { :foo , [ line: 1 ] , nil }
310
309
assert string_to_quoted . ( "foo()" ) == { :foo , [ closing: [ line: 1 ] , line: 1 ] , [ ] }
@@ -320,7 +319,12 @@ defmodule Kernel.ParserTest do
320
319
end
321
320
322
321
test "with :literal_encoder" do
323
- opts = [ literal_encoder: & { :ok , { :__block__ , & 2 , [ & 1 ] } } , token_metadata: true ]
322
+ opts = [
323
+ literal_encoder: & { :ok , { :__block__ , & 2 , [ & 1 ] } } ,
324
+ token_metadata: true ,
325
+ columns: false
326
+ ]
327
+
324
328
string_to_quoted = & Code . string_to_quoted! ( & 1 , opts )
325
329
326
330
assert string_to_quoted . ( ~s( "one") ) == { :__block__ , [ delimiter: "\" " , line: 1 ] , [ "one" ] }
@@ -392,7 +396,7 @@ defmodule Kernel.ParserTest do
392
396
end
393
397
394
398
test "adds metadata for the last alias segment" do
395
- string_to_quoted = & Code . string_to_quoted! ( & 1 , token_metadata: true )
399
+ string_to_quoted = & Code . string_to_quoted! ( & 1 , token_metadata: true , columns: false )
396
400
397
401
assert string_to_quoted . ( "Foo" ) == { :__aliases__ , [ last: [ line: 1 ] , line: 1 ] , [ :Foo ] }
398
402
@@ -845,7 +849,7 @@ defmodule Kernel.ParserTest do
845
849
end
846
850
end
847
851
848
- defp parse! ( string ) , do: Code . string_to_quoted! ( string )
852
+ defp parse! ( string ) , do: Code . string_to_quoted! ( string , columns: false )
849
853
850
854
defp assert_token_missing ( given_message , string ) do
851
855
assert_raise TokenMissingError , given_message , fn -> parse! ( string ) end
0 commit comments