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