parser 2.6.0.0 → 3.1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser/all.rb +3 -0
  3. data/lib/parser/ast/processor.rb +48 -1
  4. data/lib/parser/base.rb +30 -6
  5. data/lib/parser/builders/default.rb +670 -38
  6. data/lib/parser/context.rb +24 -26
  7. data/lib/parser/current.rb +36 -9
  8. data/lib/parser/current_arg_stack.rb +46 -0
  9. data/lib/parser/diagnostic/engine.rb +1 -2
  10. data/lib/parser/diagnostic.rb +1 -1
  11. data/lib/parser/lexer/dedenter.rb +58 -49
  12. data/lib/parser/lexer/explanation.rb +1 -1
  13. data/lib/parser/lexer.rb +13837 -11893
  14. data/lib/parser/macruby.rb +2544 -2489
  15. data/lib/parser/max_numparam_stack.rb +56 -0
  16. data/lib/parser/messages.rb +78 -44
  17. data/lib/parser/meta.rb +13 -3
  18. data/lib/parser/ruby18.rb +2313 -2259
  19. data/lib/parser/ruby19.rb +2537 -2488
  20. data/lib/parser/ruby20.rb +2724 -2673
  21. data/lib/parser/ruby21.rb +2766 -2727
  22. data/lib/parser/ruby22.rb +2683 -2628
  23. data/lib/parser/ruby23.rb +2796 -2755
  24. data/lib/parser/ruby24.rb +2812 -2771
  25. data/lib/parser/ruby25.rb +2703 -2670
  26. data/lib/parser/ruby26.rb +2794 -2747
  27. data/lib/parser/ruby27.rb +7914 -0
  28. data/lib/parser/ruby28.rb +8047 -0
  29. data/lib/parser/ruby30.rb +8096 -0
  30. data/lib/parser/ruby31.rb +8354 -0
  31. data/lib/parser/rubymotion.rb +2527 -2485
  32. data/lib/parser/runner/ruby_parse.rb +2 -2
  33. data/lib/parser/runner/ruby_rewrite.rb +2 -2
  34. data/lib/parser/runner.rb +36 -2
  35. data/lib/parser/source/buffer.rb +53 -28
  36. data/lib/parser/source/comment/associator.rb +31 -8
  37. data/lib/parser/source/comment.rb +14 -1
  38. data/lib/parser/source/map/method_definition.rb +25 -0
  39. data/lib/parser/source/range.rb +19 -3
  40. data/lib/parser/source/tree_rewriter/action.rb +137 -28
  41. data/lib/parser/source/tree_rewriter.rb +144 -14
  42. data/lib/parser/static_environment.rb +23 -0
  43. data/lib/parser/tree_rewriter.rb +3 -3
  44. data/lib/parser/variables_stack.rb +36 -0
  45. data/lib/parser/version.rb +1 -1
  46. data/lib/parser.rb +4 -0
  47. data/parser.gemspec +12 -19
  48. metadata +34 -99
  49. data/.gitignore +0 -32
  50. data/.travis.yml +0 -45
  51. data/.yardopts +0 -21
  52. data/CHANGELOG.md +0 -943
  53. data/CONTRIBUTING.md +0 -17
  54. data/Gemfile +0 -10
  55. data/README.md +0 -301
  56. data/Rakefile +0 -165
  57. data/ci/run_rubocop_specs +0 -14
  58. data/doc/AST_FORMAT.md +0 -1735
  59. data/doc/CUSTOMIZATION.md +0 -37
  60. data/doc/INTERNALS.md +0 -21
  61. data/doc/css/.gitkeep +0 -0
  62. data/doc/css/common.css +0 -68
  63. data/lib/parser/lexer.rl +0 -2383
  64. data/lib/parser/macruby.y +0 -2198
  65. data/lib/parser/ruby18.y +0 -1934
  66. data/lib/parser/ruby19.y +0 -2175
  67. data/lib/parser/ruby20.y +0 -2353
  68. data/lib/parser/ruby21.y +0 -2357
  69. data/lib/parser/ruby22.y +0 -2364
  70. data/lib/parser/ruby23.y +0 -2370
  71. data/lib/parser/ruby24.y +0 -2408
  72. data/lib/parser/ruby25.y +0 -2405
  73. data/lib/parser/ruby26.y +0 -2413
  74. data/lib/parser/rubymotion.y +0 -2182
  75. data/test/bug_163/fixtures/input.rb +0 -5
  76. data/test/bug_163/fixtures/output.rb +0 -5
  77. data/test/bug_163/rewriter.rb +0 -20
  78. data/test/helper.rb +0 -52
  79. data/test/parse_helper.rb +0 -315
  80. data/test/racc_coverage_helper.rb +0 -133
  81. data/test/test_base.rb +0 -31
  82. data/test/test_current.rb +0 -27
  83. data/test/test_diagnostic.rb +0 -96
  84. data/test/test_diagnostic_engine.rb +0 -62
  85. data/test/test_encoding.rb +0 -99
  86. data/test/test_lexer.rb +0 -3543
  87. data/test/test_lexer_stack_state.rb +0 -78
  88. data/test/test_parse_helper.rb +0 -80
  89. data/test/test_parser.rb +0 -7087
  90. data/test/test_runner_rewrite.rb +0 -47
  91. data/test/test_source_buffer.rb +0 -162
  92. data/test/test_source_comment.rb +0 -36
  93. data/test/test_source_comment_associator.rb +0 -367
  94. data/test/test_source_map.rb +0 -15
  95. data/test/test_source_range.rb +0 -172
  96. data/test/test_source_rewriter.rb +0 -541
  97. data/test/test_source_rewriter_action.rb +0 -46
  98. data/test/test_source_tree_rewriter.rb +0 -173
  99. data/test/test_static_environment.rb +0 -45
  100. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  101. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  102. data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
data/test/test_lexer.rb DELETED
@@ -1,3543 +0,0 @@
1
- # encoding: ascii-8bit
2
- # frozen_string_literal: true
3
-
4
- require 'helper'
5
- require 'complex'
6
-
7
- class TestLexer < Minitest::Test
8
- def setup_lexer(version)
9
- @lex = Parser::Lexer.new(version)
10
-
11
- @lex.comments = []
12
- @lex.diagnostics = Parser::Diagnostic::Engine.new
13
- @lex.diagnostics.all_errors_are_fatal = true
14
- # @lex.diagnostics.consumer = lambda { |diag| $stderr.puts "", diag.render }
15
- end
16
-
17
- def setup
18
- setup_lexer 18
19
- end
20
-
21
- #
22
- # Tools
23
- #
24
-
25
- def utf(str)
26
- str.dup.force_encoding(Encoding::UTF_8)
27
- end
28
-
29
- #
30
- # Additional matchers
31
- #
32
-
33
- def refute_scanned(s, *args)
34
- assert_raises Parser::SyntaxError do
35
- assert_scanned(s, *args)
36
- end
37
- end
38
-
39
- def assert_escape(expected, input)
40
- source_buffer = Parser::Source::Buffer.new('(assert_escape)')
41
-
42
- source_buffer.source = "\"\\#{input}\"".encode(input.encoding)
43
-
44
- @lex.reset
45
- @lex.source_buffer = source_buffer
46
-
47
- lex_token, (lex_value, *) = @lex.advance
48
-
49
- lex_value.force_encoding(Encoding::BINARY)
50
-
51
- assert_equal [:tSTRING, expected],
52
- [lex_token, lex_value],
53
- source_buffer.source
54
- end
55
-
56
- def refute_escape(input)
57
- err = assert_raises Parser::SyntaxError do
58
- @lex.state = :expr_beg
59
- assert_scanned "%Q[\\#{input}]"
60
- end
61
- assert_equal :fatal, err.diagnostic.level
62
- end
63
-
64
- def assert_lex_fname(name, type, range)
65
- begin_pos, end_pos = range
66
- assert_scanned("def #{name} ",
67
- :kDEF, 'def', [0, 3],
68
- type, name, [begin_pos + 4, end_pos + 4])
69
-
70
- assert_equal :expr_endfn, @lex.state
71
- end
72
-
73
- def assert_scanned(input, *args)
74
- source_buffer = Parser::Source::Buffer.new('(assert_scanned)')
75
- source_buffer.source = input
76
-
77
- @lex.reset(false)
78
- @lex.source_buffer = source_buffer
79
-
80
- until args.empty? do
81
- token, value, (begin_pos, end_pos) = args.shift(3)
82
-
83
- lex_token, (lex_value, lex_range) = @lex.advance
84
- assert lex_token, 'no more tokens'
85
- assert_operator [lex_token, lex_value], :eql?, [token, value], input
86
- assert_equal begin_pos, lex_range.begin_pos
87
- assert_equal end_pos, lex_range.end_pos
88
- end
89
-
90
- lex_token, (lex_value, *) = @lex.advance
91
- refute lex_token, "must be empty, but had #{[lex_token, lex_value].inspect}"
92
- end
93
-
94
- #
95
- # Tests
96
- #
97
-
98
- def test_read_escape
99
- assert_escape "\\", "\\"
100
- assert_escape "\n", "n"
101
- assert_escape "\t", "t"
102
- assert_escape "\r", "r"
103
- assert_escape "\f", "f"
104
- assert_escape "\13", "v"
105
- assert_escape "\0", "0"
106
- assert_escape "\07", "a"
107
- assert_escape "\007", "a"
108
- assert_escape "\033", "e"
109
- assert_escape "\377", "377"
110
- assert_escape "\377", "xff"
111
- assert_escape "\010", "b"
112
- assert_escape " ", "s"
113
- assert_escape "q", "q" # plain vanilla escape
114
- end
115
-
116
- def test_read_escape_c
117
- assert_escape "\030", "C-x"
118
- assert_escape "\030", "cx"
119
- assert_escape "\230", 'C-\M-x'
120
- assert_escape "\230", 'c\M-x'
121
-
122
- assert_escape "\177", "C-?"
123
- assert_escape "\177", "c?"
124
- assert_escape "\r", "cM"
125
- end
126
-
127
- def test_read_escape_m
128
- assert_escape "\370", "M-x"
129
- assert_escape "\230", 'M-\C-x'
130
- assert_escape "\230", 'M-\cx'
131
- end
132
-
133
- def test_read_escape_errors
134
- refute_escape ""
135
-
136
- refute_escape "M"
137
- refute_escape "M-"
138
- refute_escape "Mx"
139
-
140
- refute_escape "Cx"
141
- refute_escape "C"
142
- refute_escape "C-"
143
-
144
- refute_escape "c"
145
-
146
- refute_escape "x"
147
- end
148
-
149
- def test_read_escape_unicode__19
150
- assert_escape "\x09", 'u{9}'
151
- assert_escape "\x31", 'u{31}'
152
- assert_escape "\x09\x01", 'u{9 1}'
153
-
154
- assert_escape "\xc4\xa3", utf('u0123')
155
- assert_escape "\xc4\xa3\xc3\xb0\xeb\x84\xa3", utf('u{123 f0 B123}')
156
- end
157
-
158
- def test_read_escape_unicode_bad__19
159
- refute_escape 'u123'
160
- refute_escape 'u{}'
161
- refute_escape 'u{123 f0h}'
162
- refute_escape 'u{123 f0'
163
- end
164
-
165
- def test_ambiguous_uminus
166
- assert_scanned("m -3",
167
- :tIDENTIFIER, "m", [0, 1],
168
- :tUNARY_NUM, "-", [2, 3],
169
- :tINTEGER, 3, [3, 4])
170
- end
171
-
172
- def test_ambiguous_uplus
173
- assert_scanned("m +3",
174
- :tIDENTIFIER, "m", [0, 1],
175
- :tUNARY_NUM, "+", [2, 3],
176
- :tINTEGER, 3, [3, 4])
177
- end
178
-
179
- def test_and
180
- assert_scanned "&", :tAMPER, "&", [0, 1]
181
- end
182
-
183
- def test_and2
184
- @lex.state = :expr_end
185
-
186
- assert_scanned "&&", :tANDOP, "&&", [0, 2]
187
- end
188
-
189
- def test_and2_equals
190
- @lex.state = :expr_end
191
-
192
- assert_scanned "&&=", :tOP_ASGN, "&&", [0, 3]
193
- end
194
-
195
- def test_and_arg
196
- @lex.state = :expr_arg
197
-
198
- assert_scanned(" &y",
199
- :tAMPER, "&", [1, 2],
200
- :tIDENTIFIER, "y", [2, 3])
201
- end
202
-
203
- def test_and_equals
204
- @lex.state = :expr_end
205
-
206
- assert_scanned "&=", :tOP_ASGN, "&", [0, 2]
207
- end
208
-
209
- def test_and_expr
210
- @lex.state = :expr_arg
211
-
212
- assert_scanned("x & y",
213
- :tIDENTIFIER, "x", [0, 1],
214
- :tAMPER2, "&", [2, 3],
215
- :tIDENTIFIER, "y", [4, 5])
216
- end
217
-
218
- def test_and_meth
219
- assert_lex_fname "&", :tAMPER2, [0, 1]
220
- end
221
-
222
- def test_and_dot_arg
223
- @lex.state = :expr_arg
224
-
225
- assert_scanned "&.", :tANDDOT, "&.", [0, 2]
226
- end
227
-
228
- def test_and_dot_cmdarg
229
- @lex.state = :expr_cmdarg
230
-
231
- assert_scanned "&.", :tANDDOT, "&.", [0, 2]
232
- end
233
-
234
- def test_assoc
235
- assert_scanned "=>", :tASSOC, "=>", [0, 2]
236
- end
237
-
238
- def test_label__18
239
- assert_scanned("{a:b",
240
- :tLBRACE, "{", [0, 1],
241
- :tIDENTIFIER, "a", [1, 2],
242
- :tSYMBOL, "b", [2, 4])
243
- end
244
-
245
- def test_label_in_params__18
246
- assert_scanned("foo(a:b",
247
- :tIDENTIFIER, "foo", [0, 3],
248
- :tLPAREN2, "(", [3, 4],
249
- :tIDENTIFIER, "a", [4, 5],
250
- :tSYMBOL, "b", [5, 7])
251
- end
252
-
253
- def test_label__19
254
- setup_lexer 19
255
-
256
- assert_scanned("{a:b",
257
- :tLBRACE, "{", [0, 1],
258
- :tLABEL, "a", [1, 3],
259
- :tIDENTIFIER, "b", [3, 4])
260
- end
261
-
262
- def test_label_in_params__19
263
- setup_lexer 19
264
-
265
- assert_scanned("foo(a:b",
266
- :tIDENTIFIER, "foo", [0, 3],
267
- :tLPAREN2, "(", [3, 4],
268
- :tLABEL, "a", [4, 6],
269
- :tIDENTIFIER, "b", [6, 7])
270
- end
271
-
272
- def test_label_fid__19
273
- setup_lexer 19
274
-
275
- assert_scanned("{a?:true",
276
- :tLBRACE, '{', [0, 1],
277
- :tLABEL, 'a?', [1, 4],
278
- :kTRUE, 'true', [4, 8])
279
- end
280
-
281
- def test_label__22
282
- setup_lexer 22
283
-
284
- assert_scanned("{'a':",
285
- :tLBRACE, '{', [0, 1],
286
- :tSTRING_BEG, "'", [1, 2],
287
- :tSTRING_CONTENT, 'a', [2, 3],
288
- :tLABEL_END, "'", [3, 5])
289
- end
290
-
291
- def test_label_nested__22
292
- setup_lexer 22
293
-
294
- assert_scanned("{'a\":':",
295
- :tLBRACE, '{', [0, 1],
296
- :tSTRING_BEG, "'", [1, 2],
297
- :tSTRING_CONTENT, 'a":', [2, 5],
298
- :tLABEL_END, "'", [5, 7])
299
- end
300
-
301
- def test_label_colon2__22
302
- setup_lexer 22
303
-
304
- assert_scanned("{'a'::",
305
- :tLBRACE, '{', [0, 1],
306
- :tSTRING, "a", [1, 4],
307
- :tCOLON2, '::', [4, 6])
308
- end
309
-
310
- def test_pct_string_colon__22
311
- setup_lexer 22
312
-
313
- assert_scanned("{%'a':",
314
- :tLBRACE, '{', [0, 1],
315
- :tSTRING_BEG, "%'", [1, 3],
316
- :tSTRING_CONTENT, 'a', [3, 4],
317
- :tSTRING_END, "'", [4, 5],
318
- :tCOLON, ':', [5, 6])
319
- end
320
-
321
- def test_command_start__19
322
- setup_lexer 19
323
-
324
- %w[case elsif for in until when while
325
- if unless and or].each do |keyword|
326
- token = "k#{keyword.upcase}".to_sym
327
-
328
- @lex.reset
329
- assert_scanned("#{keyword} a:b",
330
- token, keyword, [0, keyword.length],
331
- :tIDENTIFIER, "a", [keyword.length + 1, keyword.length + 2],
332
- :tSYMBOL, "b", [keyword.length + 2, keyword.length + 4])
333
- end
334
- end
335
-
336
- def test_mod_not_command_start__19
337
- setup_lexer 19
338
-
339
- %w[if unless while until rescue].each do |keyword|
340
- token = "k#{keyword.upcase}_MOD".to_sym
341
-
342
- @lex.state = :expr_end
343
- assert_scanned("#{keyword} a:b",
344
- token, keyword, [0, keyword.length],
345
- :tLABEL, "a", [keyword.length + 1, keyword.length + 3],
346
- :tIDENTIFIER, "b", [keyword.length + 3, keyword.length + 4])
347
- end
348
- end
349
-
350
- def test_back_ref
351
- assert_scanned("[$&, $`, $', $+]",
352
- :tLBRACK, "[", [0, 1],
353
- :tBACK_REF, "$&", [1, 3], :tCOMMA, ",", [3, 4],
354
- :tBACK_REF, "$`", [5, 7], :tCOMMA, ",", [7, 8],
355
- :tBACK_REF, "$'", [9, 11], :tCOMMA, ",", [11, 12],
356
- :tBACK_REF, "$+", [13, 15],
357
- :tRBRACK, "]", [15, 16])
358
- end
359
-
360
- def test_backslash
361
- assert_scanned("1 \\\n+ 2",
362
- :tINTEGER, 1, [0, 1],
363
- :tPLUS, "+", [4, 5],
364
- :tINTEGER, 2, [6, 7])
365
- end
366
-
367
- def test_backslash_bad
368
- refute_scanned("1 \\ + 2",
369
- :tINTEGER, 1, [0, 1])
370
- end
371
-
372
- def test_backtick
373
- assert_scanned("`ls`",
374
- :tXSTRING_BEG, "`", [0, 1],
375
- :tSTRING_CONTENT, "ls", [1, 3],
376
- :tSTRING_END, "`", [3, 4])
377
- end
378
-
379
- def test_backtick_cmdarg
380
- @lex.state = :expr_dot
381
- assert_scanned("\n`", :tBACK_REF2, "`", [1, 2]) # \n ensures expr_cmd
382
-
383
- assert_equal :expr_arg, @lex.state
384
- end
385
-
386
- def test_backtick_dot
387
- @lex.state = :expr_dot
388
- assert_scanned("a.`(3)",
389
- :tIDENTIFIER, "a", [0, 1],
390
- :tDOT, ".", [1, 2],
391
- :tBACK_REF2, "`", [2, 3],
392
- :tLPAREN2, "(", [3, 4],
393
- :tINTEGER, 3, [4, 5],
394
- :tRPAREN, ")", [5, 6])
395
- end
396
-
397
- def test_backtick_method
398
- @lex.state = :expr_fname
399
- assert_scanned("`", :tBACK_REF2, "`", [0, 1])
400
- assert_equal :expr_endfn, @lex.state
401
- end
402
-
403
- def test_bad_char
404
- refute_scanned(" \010 ")
405
- end
406
-
407
- def test_bang
408
- assert_scanned "!", :tBANG, "!", [0, 1]
409
- end
410
-
411
- def test_bang_equals
412
- assert_scanned "!=", :tNEQ, "!=", [0, 2]
413
- end
414
-
415
- def test_bang_tilde
416
- assert_scanned "!~", :tNMATCH, "!~", [0, 2]
417
- end
418
-
419
- def test_def_ubang
420
- setup_lexer(20)
421
-
422
- @lex.state = :expr_fname
423
- assert_scanned '!@', :tBANG, '!@', [0, 2]
424
- end
425
-
426
- def test_carat
427
- assert_scanned "^", :tCARET, "^", [0, 1]
428
- end
429
-
430
- def test_carat_equals
431
- assert_scanned "^=", :tOP_ASGN, "^", [0, 2]
432
- end
433
-
434
- def test_colon2
435
- assert_scanned("A::B",
436
- :tCONSTANT, "A", [0, 1],
437
- :tCOLON2, "::", [1, 3],
438
- :tCONSTANT, "B", [3, 4])
439
-
440
- @lex.state = :expr_arg
441
- assert_scanned("::Array",
442
- :tCOLON2, "::", [0, 2],
443
- :tCONSTANT, "Array", [2, 7])
444
- end
445
-
446
- def test_colon3
447
- assert_scanned("::Array",
448
- :tCOLON3, "::", [0, 2],
449
- :tCONSTANT, "Array", [2, 7])
450
-
451
- @lex.state = :expr_arg
452
- assert_scanned(" ::Array",
453
- :tCOLON3, "::", [1, 3],
454
- :tCONSTANT, "Array", [3, 8])
455
- end
456
-
457
- def test_comma
458
- assert_scanned ",", :tCOMMA, ",", [0, 1]
459
- end
460
-
461
- def test_comment
462
- assert_scanned("1 # one\n# two\n2",
463
- :tINTEGER, 1, [0, 1],
464
- :tNL, nil, [7, 8],
465
- :tINTEGER, 2, [14, 15])
466
-
467
- assert_equal 2, @lex.comments.length
468
- assert_equal '# one', @lex.comments[0].text
469
- assert_equal '# two', @lex.comments[1].text
470
- end
471
-
472
- def test_comment_expr_beg
473
- assert_scanned("{#1\n}",
474
- :tLBRACE, "{", [0, 1],
475
- :tRCURLY, "}", [4, 5])
476
- end
477
-
478
- def test_comment_begin
479
- assert_scanned("=begin\nblah\nblah\n=end\n42",
480
- :tINTEGER, 42, [22, 24])
481
- assert_equal 1, @lex.comments.length
482
- assert_equal "=begin\nblah\nblah\n=end\n", @lex.comments[0].text
483
- end
484
-
485
- def test_comment_begin_bad
486
- refute_scanned("=begin\nblah\nblah\n")
487
- end
488
-
489
- def test_comment_begin_not_comment
490
- assert_scanned("beginfoo = 5\np x \\\n=beginfoo",
491
- :tIDENTIFIER, "beginfoo", [0, 8],
492
- :tEQL, "=", [9, 10],
493
- :tINTEGER, 5, [11, 12],
494
- :tNL, nil, [12, 13],
495
- :tIDENTIFIER, "p", [13, 14],
496
- :tIDENTIFIER, "x", [15, 16],
497
- :tEQL, "=", [19, 20],
498
- :tIDENTIFIER, "beginfoo", [20, 28])
499
- end
500
-
501
- def test_comment_begin_space
502
- assert_scanned("=begin blah\nblah\n=end\n")
503
-
504
- assert_equal 1, @lex.comments.length
505
- assert_equal "=begin blah\nblah\n=end\n", @lex.comments[0].text
506
- end
507
-
508
- def test_comment_end_space_and_text
509
- assert_scanned("=begin blah\nblah\n=end blab\n")
510
-
511
- assert_equal 1, @lex.comments.length
512
- assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments[0].text
513
- end
514
-
515
- def test_comment_eos
516
- assert_scanned("# comment")
517
- end
518
-
519
- def test_constant
520
- assert_scanned("ArgumentError",
521
- :tCONSTANT, "ArgumentError", [0, 13])
522
- end
523
-
524
- def test_constant_semi
525
- assert_scanned("ArgumentError;",
526
- :tCONSTANT, "ArgumentError", [0, 13],
527
- :tSEMI, ";", [13, 14])
528
- end
529
-
530
- def test_cvar
531
- assert_scanned "@@blah", :tCVAR, "@@blah", [0, 6]
532
- end
533
-
534
- def test_cvar_bad
535
- refute_scanned "@@1"
536
- end
537
-
538
- def test_div
539
- assert_scanned("a / 2",
540
- :tIDENTIFIER, "a", [0, 1],
541
- :tDIVIDE, "/", [2, 3],
542
- :tINTEGER, 2, [4, 5])
543
- end
544
-
545
- def test_div_equals
546
- assert_scanned("a /= 2",
547
- :tIDENTIFIER, "a", [0, 1],
548
- :tOP_ASGN, "/", [2, 4],
549
- :tINTEGER, 2, [5, 6])
550
- end
551
-
552
- def test_do
553
- assert_scanned("x do 42 end",
554
- :tIDENTIFIER, "x", [0, 1],
555
- :kDO, "do", [2, 4],
556
- :tINTEGER, 42, [5, 7],
557
- :kEND, "end", [8, 11])
558
- end
559
-
560
- def test_do_block
561
- @lex.state = :expr_endarg
562
-
563
- assert_scanned("do 42 end",
564
- :kDO_BLOCK, "do", [0, 2],
565
- :tINTEGER, 42, [3, 5],
566
- :kEND, "end", [6, 9])
567
- end
568
-
569
- def test_do_cond
570
- @lex.cond.push true
571
-
572
- assert_scanned("x do 42 end",
573
- :tIDENTIFIER, "x", [0, 1],
574
- :kDO_COND, "do", [2, 4],
575
- :tINTEGER, 42, [5, 7],
576
- :kEND, "end", [8, 11])
577
- end
578
-
579
- def test_dot
580
- assert_scanned ".", :tDOT, ".", [0, 1]
581
- end
582
-
583
- def test_dot2
584
- assert_scanned "..", :tDOT2, "..", [0, 2]
585
- end
586
-
587
- def test_dot3
588
- assert_scanned "...", :tDOT3, "...", [0, 3]
589
- end
590
-
591
- def test_equals
592
- assert_scanned "=", :tEQL, "=", [0, 1]
593
- end
594
-
595
- def test_equals2
596
- assert_scanned "==", :tEQ, "==", [0, 2]
597
- end
598
-
599
- def test_equals3
600
- assert_scanned "===", :tEQQ, "===", [0, 3]
601
- end
602
-
603
- def test_equals_tilde
604
- assert_scanned "=~", :tMATCH, "=~", [0, 2]
605
- end
606
-
607
- def test_float
608
- assert_scanned "1.0", :tFLOAT, 1.0, [0, 3]
609
- end
610
-
611
- def test_float_bad_no_underscores
612
- refute_scanned "1__0.0"
613
- end
614
-
615
- def test_float_bad_no_zero_leading
616
- refute_scanned ".0"
617
- end
618
-
619
- def test_float_bad_trailing_underscore
620
- refute_scanned "123_.0"
621
- end
622
-
623
- def test_float_call
624
- assert_scanned("1.0.to_s",
625
- :tFLOAT, 1.0, [0, 3],
626
- :tDOT, ".", [3, 4],
627
- :tIDENTIFIER, "to_s", [4, 8])
628
- end
629
-
630
- def test_float_dot_E
631
- assert_scanned "1.0E10", :tFLOAT, 1.0e10, [0, 6]
632
- end
633
-
634
- def test_float_dot_E_neg
635
- assert_scanned("-1.0E10",
636
- :tUNARY_NUM, "-", [0, 1],
637
- :tFLOAT, 1.0e10, [1, 7])
638
- end
639
-
640
- def test_float_dot_E_pos
641
- assert_scanned("+1.0E10",
642
- :tUNARY_NUM, "+", [0, 1],
643
- :tFLOAT, 1.0e10, [1, 7])
644
- end
645
-
646
- def test_float_dot_e
647
- assert_scanned "1.0e10", :tFLOAT, 1.0e10, [0, 6]
648
- end
649
-
650
- def test_float_dot_e_neg
651
- assert_scanned("-1.0e10",
652
- :tUNARY_NUM, "-", [0, 1],
653
- :tFLOAT, 1.0e10, [1, 7])
654
- end
655
-
656
- def test_float_dot_e_pos
657
- assert_scanned("+1.0e10",
658
- :tUNARY_NUM, "+", [0, 1],
659
- :tFLOAT, 1.0e10, [1, 7])
660
- end
661
-
662
- def test_float_e
663
- assert_scanned "1e10", :tFLOAT, 1e10, [0, 4]
664
- end
665
-
666
- def test_float_e_bad_trailing_underscore
667
- refute_scanned "123_e10"
668
- end
669
-
670
- def test_float_e_minus
671
- assert_scanned "1e-10", :tFLOAT, 1e-10, [0, 5]
672
- end
673
-
674
- def test_float_e_neg
675
- assert_scanned("-1e10",
676
- :tUNARY_NUM, "-", [0, 1],
677
- :tFLOAT, 1e10, [1, 5])
678
- end
679
-
680
- def test_float_e_neg_minus
681
- assert_scanned("-1e-10",
682
- :tUNARY_NUM, "-", [0, 1],
683
- :tFLOAT, 1e-10, [1, 6])
684
- end
685
-
686
- def test_float_e_neg_plus
687
- assert_scanned("-1e+10",
688
- :tUNARY_NUM, "-", [0, 1],
689
- :tFLOAT, 1e10, [1, 6])
690
- end
691
-
692
- def test_float_e_pos
693
- assert_scanned("+1e10",
694
- :tUNARY_NUM, "+", [0, 1],
695
- :tFLOAT, 1e10, [1, 5])
696
- end
697
-
698
- def test_float_e_pos_minus
699
- assert_scanned("+1e-10",
700
- :tUNARY_NUM, "+", [0, 1],
701
- :tFLOAT, 1e-10, [1, 6])
702
- end
703
-
704
- def test_float_e_pos_plus
705
- assert_scanned("+1e+10",
706
- :tUNARY_NUM, "+", [0, 1],
707
- :tFLOAT, 1e10, [1, 6])
708
- end
709
-
710
- def test_float_e_plus
711
- assert_scanned "1e+10", :tFLOAT, 1e10, [0, 5]
712
- end
713
-
714
- def test_float_e_zero
715
- assert_scanned "0e0", :tFLOAT, 0e0, [0, 3]
716
- end
717
-
718
- def test_float_e_nothing
719
- [18, 19, 20].each do |version|
720
- setup_lexer version
721
-
722
- refute_scanned "1end"
723
- refute_scanned "1.1end"
724
- end
725
-
726
- setup_lexer 21
727
-
728
- assert_scanned("1end",
729
- :tINTEGER, 1, [0, 1],
730
- :kEND, 'end', [1, 4])
731
- assert_scanned("1.1end",
732
- :tFLOAT, 1.1, [0, 3],
733
- :kEND, 'end', [3, 6])
734
- end
735
-
736
- def test_float_neg
737
- assert_scanned("-1.0",
738
- :tUNARY_NUM, "-", [0, 1],
739
- :tFLOAT, 1.0, [1, 4])
740
- end
741
-
742
- def test_float_pos
743
- assert_scanned("+1.0",
744
- :tUNARY_NUM, "+", [0, 1],
745
- :tFLOAT, 1.0, [1, 4])
746
- end
747
-
748
- def test_ge
749
- assert_scanned("a >= 2",
750
- :tIDENTIFIER, "a", [0, 1],
751
- :tGEQ, ">=", [2, 4],
752
- :tINTEGER, 2, [5, 6])
753
- end
754
-
755
- def test_global
756
- assert_scanned("$blah", :tGVAR, "$blah", [0, 5])
757
- end
758
-
759
- def test_global_backref
760
- assert_scanned("$`", :tBACK_REF, "$`", [0, 2])
761
- end
762
-
763
- # This was removed in 2.1.
764
- # def test_global_dash_nothing
765
- # assert_scanned("$- ", :tGVAR, "$-")
766
- # end
767
-
768
- def test_global_dash_something
769
- assert_scanned("$-x", :tGVAR, "$-x", [0, 3])
770
- end
771
-
772
- def test_global_number
773
- assert_scanned("$10", :tNTH_REF, 10, [0, 3])
774
- end
775
-
776
- def test_global_other
777
- assert_scanned("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
778
- :tLBRACK, "[", [0, 1],
779
- :tGVAR, "$~", [1, 3], :tCOMMA, ",", [3, 4],
780
- :tGVAR, "$*", [5, 7], :tCOMMA, ",", [7, 8],
781
- :tGVAR, "$$", [9, 11], :tCOMMA, ",", [11, 12],
782
- :tGVAR, "$\?", [13, 15], :tCOMMA, ",", [15, 16],
783
- :tGVAR, "$!", [17, 19], :tCOMMA, ",", [19, 20],
784
- :tGVAR, "$@", [21, 23], :tCOMMA, ",", [23, 24],
785
- :tGVAR, "$/", [25, 27], :tCOMMA, ",", [27, 28],
786
- :tGVAR, "$\\", [29, 31], :tCOMMA, ",", [31, 32],
787
- :tGVAR, "$;", [33, 35], :tCOMMA, ",", [35, 36],
788
- :tGVAR, "$,", [37, 39], :tCOMMA, ",", [39, 40],
789
- :tGVAR, "$.", [41, 43], :tCOMMA, ",", [43, 44],
790
- :tGVAR, "$=", [45, 47], :tCOMMA, ",", [47, 48],
791
- :tGVAR, "$:", [49, 51], :tCOMMA, ",", [51, 52],
792
- :tGVAR, "$<", [53, 55], :tCOMMA, ",", [55, 56],
793
- :tGVAR, "$>", [57, 59], :tCOMMA, ",", [59, 60],
794
- :tGVAR, "$\"", [61, 63],
795
- :tRBRACK, "]", [63, 64])
796
- end
797
-
798
- def test_global_underscore
799
- assert_scanned("$_",
800
- :tGVAR, "$_", [0, 2])
801
- end
802
-
803
- def test_global_weird
804
- assert_scanned("$__blah",
805
- :tGVAR, "$__blah", [0, 7])
806
- end
807
-
808
- def test_global_zero
809
- assert_scanned("$0", :tGVAR, "$0", [0, 2])
810
- end
811
-
812
- def test_gt
813
- assert_scanned("a > 2",
814
- :tIDENTIFIER, "a", [0, 1],
815
- :tGT, ">", [2, 3],
816
- :tINTEGER, 2, [4, 5])
817
- end
818
-
819
- def test_heredoc_backtick
820
- assert_scanned("a = <<`EOF`\n blah blah\nEOF\n",
821
- :tIDENTIFIER, "a", [0, 1],
822
- :tEQL, "=", [2, 3],
823
- :tXSTRING_BEG, "<<`", [4, 11],
824
- :tSTRING_CONTENT, " blah blah\n", [12, 24],
825
- :tSTRING_END, "EOF", [24, 27],
826
- :tNL, nil, [11, 12])
827
- end
828
-
829
- def test_heredoc_double
830
- assert_scanned("a = <<\"EOF\"\n blah blah\nEOF\n",
831
- :tIDENTIFIER, "a", [0, 1],
832
- :tEQL, "=", [2, 3],
833
- :tSTRING_BEG, "<<\"", [4, 11],
834
- :tSTRING_CONTENT, " blah blah\n", [12, 24],
835
- :tSTRING_END, "EOF", [24, 27],
836
- :tNL, nil, [11, 12])
837
- end
838
-
839
- def test_heredoc_double_dash
840
- assert_scanned("a = <<-\"EOF\"\n blah blah\n EOF\n",
841
- :tIDENTIFIER, "a", [0, 1],
842
- :tEQL, "=", [2, 3],
843
- :tSTRING_BEG, "<<\"", [4, 12],
844
- :tSTRING_CONTENT, " blah blah\n", [13, 25],
845
- :tSTRING_END, "EOF", [25, 30],
846
- :tNL, nil, [12, 13])
847
- end
848
-
849
- def test_heredoc_double_eos
850
- refute_scanned("a = <<\"EOF\"\nblah",
851
- :tIDENTIFIER, "a", [0, 1],
852
- :tEQL, "=", [2, 3],
853
- :tSTRING_BEG, "<<\"", [4, 7])
854
- end
855
-
856
- def test_heredoc_double_eos_nl
857
- refute_scanned("a = <<\"EOF\"\nblah\n",
858
- :tIDENTIFIER, "a", [0, 1],
859
- :tEQL, "=", [2, 3],
860
- :tSTRING_BEG, "<<\"", [4, 7])
861
- end
862
-
863
- def test_heredoc_double_interp
864
- assert_scanned("a = <<\"EOF\"\n#x a \#@a b \#$b c \#{3} \nEOF\n",
865
- :tIDENTIFIER, "a", [0, 1],
866
- :tEQL, "=", [2, 3],
867
- :tSTRING_BEG, "<<\"", [4, 11],
868
- :tSTRING_CONTENT, "#x a ", [12, 17],
869
- :tSTRING_DVAR, nil, [17, 18],
870
- :tIVAR, "@a", [18, 20],
871
- :tSTRING_CONTENT, " b ", [20, 23],
872
- :tSTRING_DVAR, nil, [23, 24],
873
- :tGVAR, "$b", [24, 26],
874
- :tSTRING_CONTENT, " c ", [26, 29],
875
- :tSTRING_DBEG, '#{', [29, 31],
876
- :tINTEGER, 3, [31, 32],
877
- :tRCURLY, "}", [32, 33],
878
- :tSTRING_CONTENT, " \n", [33, 35],
879
- :tSTRING_END, "EOF", [35, 38],
880
- :tNL, nil, [11, 12])
881
- end
882
-
883
- def test_heredoc_empty
884
- assert_scanned("<<\"\"\n\#{x}\nblah2\n\n",
885
- :tSTRING_BEG, "<<\"", [0, 4],
886
- :tSTRING_DBEG, "\#{", [5, 7],
887
- :tIDENTIFIER, "x", [7, 8],
888
- :tRCURLY, "}", [8, 9],
889
- :tSTRING_CONTENT, "\n", [9, 10],
890
- :tSTRING_CONTENT, "blah2\n", [10, 16],
891
- :tSTRING_END, "", [16, 16],
892
- :tNL, nil, [4, 5])
893
- end
894
-
895
- def test_heredoc_none
896
- assert_scanned("a = <<EOF\nblah\nblah\nEOF",
897
- :tIDENTIFIER, "a", [0, 1],
898
- :tEQL, "=", [2, 3],
899
- :tSTRING_BEG, "<<\"", [4, 9],
900
- :tSTRING_CONTENT, "blah\n", [10, 15],
901
- :tSTRING_CONTENT, "blah\n", [15, 20],
902
- :tSTRING_END, "EOF", [20, 23],
903
- :tNL, nil, [9, 10])
904
- end
905
-
906
- def test_heredoc_none_dash
907
- assert_scanned("a = <<-EOF\nblah\nblah\n EOF",
908
- :tIDENTIFIER, "a", [0, 1],
909
- :tEQL, "=", [2, 3],
910
- :tSTRING_BEG, "<<\"", [4, 10],
911
- :tSTRING_CONTENT, "blah\n", [11, 16],
912
- :tSTRING_CONTENT, "blah\n", [16, 21],
913
- :tSTRING_END, "EOF", [21, 26],
914
- :tNL, nil, [10, 11])
915
- end
916
-
917
- def test_heredoc_single
918
- assert_scanned("a = <<'EOF'\n blah blah\nEOF\n",
919
- :tIDENTIFIER, "a", [0, 1],
920
- :tEQL, "=", [2, 3],
921
- :tSTRING_BEG, "<<'", [4, 11],
922
- :tSTRING_CONTENT, " blah blah\n", [12, 24],
923
- :tSTRING_END, "EOF", [24, 27],
924
- :tNL, nil, [11, 12])
925
- end
926
-
927
- def test_heredoc_single_bad_eos_body
928
- refute_scanned("a = <<'EOF'\nblah",
929
- :tIDENTIFIER, "a", [0, 1],
930
- :tEQL, "=", [2, 3],
931
- :tSTRING_BEG, "'", [6, 7])
932
- end
933
-
934
- def test_heredoc_single_dash
935
- assert_scanned("a = <<-'EOF'\n blah blah\n EOF\n",
936
- :tIDENTIFIER, "a", [0, 1],
937
- :tEQL, "=", [2, 3],
938
- :tSTRING_BEG, "<<'", [4, 12],
939
- :tSTRING_CONTENT, " blah blah\n", [13, 25],
940
- :tSTRING_END, "EOF", [25, 30],
941
- :tNL, nil, [12, 13])
942
- end
943
-
944
- def test_heredoc_one_character
945
- assert_scanned("a = <<E\nABCDEF\nE\n",
946
- :tIDENTIFIER, "a", [0, 1],
947
- :tEQL, "=", [2, 3],
948
- :tSTRING_BEG, "<<\"", [4, 7],
949
- :tSTRING_CONTENT, "ABCDEF\n", [8, 15],
950
- :tSTRING_END, "E", [15, 16],
951
- :tNL, nil, [7, 8])
952
- end
953
-
954
- def test_heredoc_cr
955
- assert_scanned("a = <<E\r\r\nABCDEF\r\r\nE\r\r\r\n",
956
- :tIDENTIFIER, "a", [0, 1],
957
- :tEQL, "=", [2, 3],
958
- :tSTRING_BEG, "<<\"", [4, 7],
959
- :tSTRING_CONTENT, "ABCDEF\r\n", [9, 17],
960
- :tSTRING_END, "E", [17, 20],
961
- :tNL, nil, [8, 9])
962
- end
963
-
964
- def test_heredoc_with_identifier_ending_newline__19
965
- setup_lexer 19
966
- refute_scanned "<<\"EOS\n\"\n123\nEOS\n"
967
- end
968
-
969
- def test_heredoc_with_identifier_ending_newline__24
970
- setup_lexer 24
971
-
972
- assert_scanned("a = <<\"EOS\n\"\nABCDEF\nEOS\n",
973
- :tIDENTIFIER, "a", [0, 1],
974
- :tEQL, "=", [2, 3],
975
- :tSTRING_BEG, "<<\"", [4, 12],
976
- :tSTRING_CONTENT, "ABCDEF\n", [13, 20],
977
- :tSTRING_END, "EOS", [20, 23],
978
- :tNL, nil, [12, 13])
979
- end
980
-
981
- def test_heredoc_with_identifier_containing_newline_inside__19
982
- setup_lexer 19
983
- refute_scanned "<<\"EOS\nEOS\"\n123\nEOS\n"
984
- end
985
-
986
- def test_heredoc_with_identifier_containing_newline_inside__24
987
- setup_lexer 24
988
-
989
- refute_scanned "<<\"EOS\nEOS\"\n123\nEOS\n"
990
- end
991
-
992
- def test_identifier
993
- assert_scanned("identifier",
994
- :tIDENTIFIER, "identifier", [0, 10])
995
- end
996
-
997
- def test_identifier_bang
998
- assert_scanned("identifier!",
999
- :tFID, "identifier!", [0, 11])
1000
-
1001
- assert_scanned("identifier!=",
1002
- :tIDENTIFIER, "identifier", [0, 10],
1003
- :tNEQ, "!=", [10, 12])
1004
- end
1005
-
1006
- def test_identifier_eh
1007
- setup_lexer 19
1008
-
1009
- assert_scanned("identifier?",
1010
- :tFID, "identifier?", [0, 11])
1011
-
1012
- assert_scanned("identifier?=",
1013
- :tIDENTIFIER, "identifier", [0, 10],
1014
- :tCHARACTER, "=", [10, 12])
1015
- end
1016
-
1017
- def test_identifier_cmp
1018
- assert_lex_fname "<=>", :tCMP, [0, 3]
1019
- end
1020
-
1021
- def test_identifier_def
1022
- assert_lex_fname "identifier", :tIDENTIFIER, [0, 10]
1023
- end
1024
-
1025
- def test_identifier_equals_arrow
1026
- assert_scanned(":blah==>",
1027
- :tSYMBOL, "blah=", [0, 6],
1028
- :tASSOC, "=>", [6, 8])
1029
- end
1030
-
1031
- def test_identifier_equals3
1032
- assert_scanned(":a===b",
1033
- :tSYMBOL, "a", [0, 2],
1034
- :tEQQ, "===", [2, 5],
1035
- :tIDENTIFIER, "b", [5, 6])
1036
- end
1037
-
1038
- def test_identifier_equals_equals_arrow
1039
- assert_scanned(":a==>b",
1040
- :tSYMBOL, "a=", [0, 3],
1041
- :tASSOC, "=>", [3, 5],
1042
- :tIDENTIFIER, "b", [5, 6])
1043
- end
1044
-
1045
- def test_identifier_equals_caret
1046
- assert_lex_fname "^", :tCARET, [0, 1]
1047
- end
1048
-
1049
- def test_identifier_equals_def
1050
- assert_lex_fname "identifier=", :tIDENTIFIER, [0, 11]
1051
- end
1052
-
1053
- def test_identifier_equals_def2
1054
- assert_lex_fname "==", :tEQ, [0, 2]
1055
- end
1056
-
1057
- def test_identifier_equals_expr
1058
- @lex.state = :expr_dot
1059
- assert_scanned("y = arg",
1060
- :tIDENTIFIER, "y", [0, 1],
1061
- :tEQL, "=", [2, 3],
1062
- :tIDENTIFIER, "arg", [4, 7])
1063
-
1064
- assert_equal :expr_arg, @lex.state
1065
- end
1066
-
1067
- def test_identifier_equals_or
1068
- assert_lex_fname "|", :tPIPE, [0, 1]
1069
- end
1070
-
1071
- def test_identifier_equals_slash
1072
- assert_lex_fname "/", :tDIVIDE, [0, 1]
1073
- end
1074
-
1075
- def test_identifier_equals_tilde
1076
- @lex.state = :expr_fname
1077
- assert_scanned("identifier=~",
1078
- :tIDENTIFIER, "identifier=", [0, 11],
1079
- :tTILDE, "~", [11, 12])
1080
- end
1081
-
1082
- def test_identifier_gt
1083
- assert_lex_fname ">", :tGT, [0, 1]
1084
- end
1085
-
1086
- def test_identifier_le
1087
- assert_lex_fname "<=", :tLEQ, [0, 2]
1088
- end
1089
-
1090
- def test_identifier_lt
1091
- assert_lex_fname "<", :tLT, [0, 1]
1092
- end
1093
-
1094
- def test_identifier_tilde
1095
- assert_lex_fname "~", :tTILDE, [0, 1]
1096
- end
1097
-
1098
- def test_identifier_defined?
1099
- assert_lex_fname "defined?", :kDEFINED, [0, 8]
1100
- end
1101
-
1102
- def test_index
1103
- assert_lex_fname "[]", :tAREF, [0, 2]
1104
- end
1105
-
1106
- def test_index_equals
1107
- assert_lex_fname "[]=", :tASET, [0, 3]
1108
- end
1109
-
1110
- def test_integer
1111
- assert_scanned "42", :tINTEGER, 42, [0, 2]
1112
- end
1113
-
1114
- def test_integer_bin
1115
- assert_scanned "0b101010", :tINTEGER, 42, [0, 8]
1116
- end
1117
-
1118
- def test_integer_bin_bad_none
1119
- refute_scanned "0b "
1120
- end
1121
-
1122
- def test_integer_bin_bad_underscores
1123
- refute_scanned "0b10__01"
1124
- end
1125
-
1126
- def test_integer_dec
1127
- assert_scanned "42", :tINTEGER, 42, [0, 2]
1128
- end
1129
-
1130
- def test_integer_dec_bad_underscores
1131
- refute_scanned "42__24"
1132
- end
1133
-
1134
- def test_integer_dec_d
1135
- assert_scanned "0d42", :tINTEGER, 42, [0, 4]
1136
- end
1137
-
1138
- def test_integer_dec_d_bad_none
1139
- refute_scanned "0d"
1140
- end
1141
-
1142
- def test_integer_dec_d_bad_underscores
1143
- refute_scanned "0d42__24"
1144
- end
1145
-
1146
- def test_question_eh_a__18
1147
- setup_lexer 18
1148
-
1149
- assert_scanned "?a", :tINTEGER, 97, [0, 2]
1150
- end
1151
-
1152
- def test_question_eh_a__19
1153
- setup_lexer 19
1154
-
1155
- assert_scanned '?a', :tCHARACTER, "a", [0, 2]
1156
- end
1157
-
1158
- def test_question_eh_escape_M_escape_C__18
1159
- setup_lexer 18
1160
-
1161
- assert_scanned '?\M-\C-a', :tINTEGER, 129, [0, 8]
1162
- end
1163
-
1164
- def test_question_eh_escape_M_escape_C__19
1165
- setup_lexer 19
1166
-
1167
- assert_scanned '?\M-\C-a', :tCHARACTER, "\M-\C-a", [0, 8]
1168
- end
1169
-
1170
- def test_question_eh_escape_u_1_digit
1171
- setup_lexer 19
1172
-
1173
- refute_scanned '?\\u1'
1174
- end
1175
-
1176
- def test_question_eh_escape_u_2_digits
1177
- setup_lexer 19
1178
-
1179
- refute_scanned '?\\u12'
1180
- end
1181
-
1182
- def test_question_eh_escape_u_3_digits
1183
- setup_lexer 19
1184
-
1185
- refute_scanned '?\\u123'
1186
- end
1187
-
1188
- def test_question_eh_escape_u_4_digits
1189
- setup_lexer 19
1190
- assert_scanned '?\\u0001', :tCHARACTER, "\u0001", [0, 7]
1191
- end
1192
-
1193
- def test_question_eh_single_unicode_point
1194
- setup_lexer 19
1195
- assert_scanned '?\\u{123}', :tCHARACTER, "\u0123", [0, 8]
1196
-
1197
- setup_lexer 19
1198
- assert_scanned '?\\u{a}', :tCHARACTER, "\n", [0, 6]
1199
- end
1200
-
1201
- def test_question_eh_multiple_unicode_points
1202
- setup_lexer 19
1203
- refute_scanned '?\\u{1 2 3}'
1204
-
1205
- setup_lexer 19
1206
- refute_scanned '?\\u{a b}'
1207
- end
1208
-
1209
- def test_question_eh_escape_u_unclosed_bracket
1210
- setup_lexer 19
1211
-
1212
- refute_scanned '?\\u{123'
1213
- end
1214
-
1215
- def test_question_eh_escape_space_around_unicode_point__19
1216
- setup_lexer 19
1217
- refute_scanned '"\\u{1 }"'
1218
-
1219
- setup_lexer 19
1220
- refute_scanned '"\\u{ 1}"'
1221
-
1222
- setup_lexer 19
1223
- refute_scanned '"\\u{ 1 }"'
1224
-
1225
- setup_lexer 19
1226
- refute_scanned '"\\u{1 2 }"'
1227
-
1228
- setup_lexer 19
1229
- refute_scanned '"\\u{ 1 2}"'
1230
-
1231
- setup_lexer 19
1232
- refute_scanned '"\\u{1 2}"'
1233
- end
1234
-
1235
- def test_question_eh_escape_space_around_unicode_point__24
1236
- setup_lexer 24
1237
- assert_scanned '"\\u{ 1}"', :tSTRING, "\u0001", [0, 8]
1238
-
1239
- setup_lexer 24
1240
- assert_scanned '"\\u{1 }"', :tSTRING, "\u0001", [0, 8]
1241
-
1242
- setup_lexer 24
1243
- assert_scanned '"\\u{ 1 }"', :tSTRING, "\u0001", [0, 9]
1244
-
1245
- setup_lexer 24
1246
- assert_scanned '"\\u{1 2 }"', :tSTRING, "\u0001\u0002", [0, 10]
1247
-
1248
- setup_lexer 24
1249
- assert_scanned '"\\u{ 1 2}"', :tSTRING, "\u0001\u0002", [0, 10]
1250
-
1251
- setup_lexer 24
1252
- assert_scanned '"\\u{1 2}"', :tSTRING, "\u0001\u0002", [0, 10]
1253
- end
1254
-
1255
- def test_integer_hex
1256
- assert_scanned "0x2a", :tINTEGER, 42, [0, 4]
1257
- end
1258
-
1259
- def test_integer_hex_bad_none
1260
- refute_scanned "0x "
1261
- end
1262
-
1263
- def test_integer_hex_bad_underscores
1264
- refute_scanned "0xab__cd"
1265
- end
1266
-
1267
- def test_integer_oct
1268
- assert_scanned "052", :tINTEGER, 42, [0, 3]
1269
- end
1270
-
1271
- def test_integer_oct_bad_range
1272
- refute_scanned "08"
1273
- end
1274
-
1275
- def test_integer_oct_bad_underscores
1276
- refute_scanned "01__23"
1277
- end
1278
-
1279
- def test_integer_oct_O
1280
- assert_scanned "0O52", :tINTEGER, 42, [0, 4]
1281
- end
1282
-
1283
- def test_integer_oct_O_bad_range
1284
- refute_scanned "0O1238"
1285
- end
1286
-
1287
- def test_integer_oct_O_bad_underscores
1288
- refute_scanned "0O1__23"
1289
- end
1290
-
1291
- def test_integer_oct_O_not_bad_none
1292
- assert_scanned "0O ", :tINTEGER, 0, [0, 2]
1293
- end
1294
-
1295
- def test_integer_oct_o
1296
- assert_scanned "0o52", :tINTEGER, 42, [0, 4]
1297
- end
1298
-
1299
- def test_integer_oct_o_bad_range
1300
- refute_scanned "0o1283"
1301
- end
1302
-
1303
- def test_integer_oct_o_bad_underscores
1304
- refute_scanned "0o1__23"
1305
- end
1306
-
1307
- def test_integer_oct_o_not_bad_none
1308
- assert_scanned "0o ", :tINTEGER, 0, [0, 2]
1309
- end
1310
-
1311
- def test_integer_trailing
1312
- assert_scanned("1.to_s",
1313
- :tINTEGER, 1, [0, 1],
1314
- :tDOT, '.', [1, 2],
1315
- :tIDENTIFIER, 'to_s', [2, 6])
1316
- end
1317
-
1318
- def test_integer_underscore
1319
- assert_scanned "4_2", :tINTEGER, 42, [0, 3]
1320
- end
1321
-
1322
- def test_integer_underscore_bad
1323
- refute_scanned "4__2"
1324
- end
1325
-
1326
- def test_integer_zero
1327
- assert_scanned "0", :tINTEGER, 0, [0, 1]
1328
- end
1329
-
1330
- def test_ivar
1331
- assert_scanned "@blah", :tIVAR, "@blah", [0, 5]
1332
- end
1333
-
1334
- def test_ivar_bad
1335
- refute_scanned "@1"
1336
- end
1337
-
1338
- def test_ivar_bad_0_length
1339
- refute_scanned "1+@\n", :tINTEGER, 1, [0, 1], :tPLUS, "+", [1, 2]
1340
- end
1341
-
1342
- def test_keyword_expr
1343
- @lex.state = :expr_endarg
1344
-
1345
- assert_scanned "if", :kIF_MOD, "if", [0, 2]
1346
-
1347
- assert_equal :expr_beg, @lex.state
1348
- end
1349
-
1350
- def test_lt
1351
- assert_scanned "<", :tLT, "<", [0, 1]
1352
- end
1353
-
1354
- def test_lt2
1355
- assert_scanned("a <\< b",
1356
- :tIDENTIFIER, "a", [0, 1],
1357
- :tLSHFT, "<\<", [2, 4],
1358
- :tIDENTIFIER, "b", [5, 6])
1359
-
1360
- end
1361
-
1362
- def test_lt2_equals
1363
- assert_scanned("a <\<= b",
1364
- :tIDENTIFIER, "a", [0, 1],
1365
- :tOP_ASGN, "<\<", [2, 5],
1366
- :tIDENTIFIER, "b", [6, 7])
1367
- end
1368
-
1369
- def test_lt_equals
1370
- assert_scanned "<=", :tLEQ, "<=", [0, 2]
1371
- end
1372
-
1373
- def test_minus
1374
- assert_scanned("1 - 2",
1375
- :tINTEGER, 1, [0, 1],
1376
- :tMINUS, "-", [2, 3],
1377
- :tINTEGER, 2, [4, 5])
1378
- end
1379
-
1380
- def test_minus_equals
1381
- @lex.state = :expr_end
1382
-
1383
- assert_scanned "-=", :tOP_ASGN, "-", [0, 2]
1384
- end
1385
-
1386
- def test_minus_method
1387
- @lex.state = :expr_fname
1388
- assert_scanned "-", :tMINUS, "-", [0, 1]
1389
- end
1390
-
1391
- def test_minus_unary_method
1392
- @lex.state = :expr_fname
1393
- assert_scanned "-@", :tUMINUS, "-@", [0, 2]
1394
- end
1395
-
1396
- def test_minus_unary_number
1397
- assert_scanned("-42",
1398
- :tUNARY_NUM, "-", [0, 1],
1399
- :tINTEGER, 42, [1, 3])
1400
- end
1401
-
1402
- def test_minus_unary_whitespace_number
1403
- assert_scanned("- 42",
1404
- :tUNARY_NUM, "-", [0, 1],
1405
- :tINTEGER, 42, [2, 4])
1406
- end
1407
-
1408
- def test_nth_ref
1409
- assert_scanned('[$1, $2, $3]',
1410
- :tLBRACK, "[", [0, 1],
1411
- :tNTH_REF, 1, [1, 3], :tCOMMA, ",", [3, 4],
1412
- :tNTH_REF, 2, [5, 7], :tCOMMA, ",", [7, 8],
1413
- :tNTH_REF, 3, [9, 11],
1414
- :tRBRACK, "]", [11, 12])
1415
- end
1416
-
1417
- def test_open_bracket
1418
- assert_scanned("(", :tLPAREN, "(", [0, 1])
1419
- end
1420
-
1421
- def test_open_bracket_cmdarg
1422
- assert_scanned("m (", :tIDENTIFIER, "m", [0, 1],
1423
- :tLPAREN_ARG, "(", [2, 3])
1424
- end
1425
-
1426
- def test_open_bracket_exprarg
1427
- assert_scanned("m(", :tIDENTIFIER, "m", [0, 1],
1428
- :tLPAREN2, "(", [1, 2])
1429
- end
1430
-
1431
- def test_open_curly_bracket
1432
- assert_scanned("{",
1433
- :tLBRACE, "{", [0, 1])
1434
- end
1435
-
1436
- def test_open_curly_bracket_arg
1437
- assert_scanned("m { 3 }",
1438
- :tIDENTIFIER, "m", [0, 1],
1439
- :tLCURLY, "{", [2, 3],
1440
- :tINTEGER, 3, [4, 5],
1441
- :tRCURLY, "}", [6, 7])
1442
- end
1443
-
1444
- def test_open_curly_bracket_block
1445
- @lex.state = :expr_endarg # seen m(3)
1446
-
1447
- assert_scanned("{ 4 }",
1448
- :tLBRACE_ARG, "{", [0, 1],
1449
- :tINTEGER, 4, [2, 3],
1450
- :tRCURLY, "}", [4, 5])
1451
- end
1452
-
1453
- def test_open_square_bracket_arg
1454
- assert_scanned("m [ 3 ]",
1455
- :tIDENTIFIER, "m", [0, 1],
1456
- :tLBRACK, "[", [2, 3],
1457
- :tINTEGER, 3, [4, 5],
1458
- :tRBRACK, "]", [6, 7])
1459
- end
1460
-
1461
- def test_open_square_bracket_ary
1462
- assert_scanned("[1, 2, 3]",
1463
- :tLBRACK, "[", [0, 1],
1464
- :tINTEGER, 1, [1, 2],
1465
- :tCOMMA, ",", [2, 3],
1466
- :tINTEGER, 2, [4, 5],
1467
- :tCOMMA, ",", [5, 6],
1468
- :tINTEGER, 3, [7, 8],
1469
- :tRBRACK, "]", [8, 9])
1470
- end
1471
-
1472
- def test_open_square_bracket_meth
1473
- assert_scanned("m[3]",
1474
- :tIDENTIFIER, "m", [0, 1],
1475
- :tLBRACK2, "[", [1, 2],
1476
- :tINTEGER, 3, [2, 3],
1477
- :tRBRACK, "]", [3, 4])
1478
- end
1479
-
1480
- def test_or
1481
- assert_scanned "|", :tPIPE, "|", [0, 1]
1482
- end
1483
-
1484
- def test_or2
1485
- assert_scanned "||", :tOROP, "||", [0, 2]
1486
- end
1487
-
1488
- def test_or2_equals
1489
- assert_scanned "||=", :tOP_ASGN, "||", [0, 3]
1490
- end
1491
-
1492
- def test_or_equals
1493
- assert_scanned "|=", :tOP_ASGN, "|", [0, 2]
1494
- end
1495
-
1496
- def test_percent
1497
- assert_scanned("a % 2",
1498
- :tIDENTIFIER, "a", [0, 1],
1499
- :tPERCENT, "%", [2, 3],
1500
- :tINTEGER, 2, [4, 5])
1501
- end
1502
-
1503
- def test_percent_equals
1504
- assert_scanned("a %= 2",
1505
- :tIDENTIFIER, "a", [0, 1],
1506
- :tOP_ASGN, "%", [2, 4],
1507
- :tINTEGER, 2, [5, 6])
1508
- end
1509
-
1510
- def test_plus
1511
- assert_scanned("1 + 1",
1512
- :tINTEGER, 1, [0, 1],
1513
- :tPLUS, "+", [2, 3],
1514
- :tINTEGER, 1, [4, 5])
1515
- end
1516
-
1517
- def test_plus_equals
1518
- @lex.state = :expr_end
1519
-
1520
- assert_scanned "+=", :tOP_ASGN, "+", [0, 2]
1521
- end
1522
-
1523
- def test_plus_method
1524
- @lex.state = :expr_fname
1525
- assert_scanned "+", :tPLUS, "+", [0, 1]
1526
- end
1527
-
1528
- def test_plus_unary_method
1529
- @lex.state = :expr_fname
1530
- assert_scanned "+@", :tUPLUS, "+@", [0, 2]
1531
- end
1532
-
1533
- def test_plus_unary_number
1534
- assert_scanned("+42",
1535
- :tUNARY_NUM, "+", [0, 1],
1536
- :tINTEGER, 42, [1, 3])
1537
- end
1538
-
1539
- def test_plus_unary_whitespace_number
1540
- assert_scanned("+ 42",
1541
- :tUNARY_NUM, "+", [0, 1],
1542
- :tINTEGER, 42, [2, 4])
1543
- end
1544
-
1545
- def test_numbers
1546
- assert_scanned "0b10", :tINTEGER, 2, [0, 4]
1547
- assert_scanned "0B10", :tINTEGER, 2, [0, 4]
1548
-
1549
- assert_scanned "0d10", :tINTEGER, 10, [0, 4]
1550
- assert_scanned "0D10", :tINTEGER, 10, [0, 4]
1551
-
1552
- assert_scanned "0x10", :tINTEGER, 16, [0, 4]
1553
- assert_scanned "0X10", :tINTEGER, 16, [0, 4]
1554
-
1555
- assert_scanned "0o10", :tINTEGER, 8, [0, 4]
1556
- assert_scanned "0O10", :tINTEGER, 8, [0, 4]
1557
- assert_scanned "0o", :tINTEGER, 0, [0, 2]
1558
- assert_scanned "0O", :tINTEGER, 0, [0, 2]
1559
-
1560
- assert_scanned "0o", :tINTEGER, 0, [0, 2]
1561
- assert_scanned "0O", :tINTEGER, 0, [0, 2]
1562
-
1563
- assert_scanned "0777_333", :tINTEGER, 261851, [0, 8]
1564
-
1565
- assert_scanned "0", :tINTEGER, 0, [0, 1]
1566
-
1567
- refute_scanned "0x"
1568
- refute_scanned "0X"
1569
- refute_scanned "0b"
1570
- refute_scanned "0B"
1571
- refute_scanned "0d"
1572
- refute_scanned "0D"
1573
-
1574
- refute_scanned "08"
1575
- refute_scanned "09"
1576
- refute_scanned "0o8"
1577
- refute_scanned "0o9"
1578
- refute_scanned "0O8"
1579
- refute_scanned "0O9"
1580
-
1581
- refute_scanned "1_e1"
1582
- refute_scanned "1_.1"
1583
- refute_scanned "1__1"
1584
-
1585
- refute_scanned "1end"
1586
- refute_scanned "1.1end"
1587
- end
1588
-
1589
- def test_question__18
1590
- setup_lexer 18
1591
-
1592
- assert_scanned "?*", :tINTEGER, 42, [0, 2]
1593
- end
1594
-
1595
- def test_question__19
1596
- setup_lexer 19
1597
-
1598
- assert_scanned "?*", :tCHARACTER, "*", [0, 2]
1599
- end
1600
-
1601
- def test_question_bad_eos
1602
- refute_scanned "?"
1603
- end
1604
-
1605
- def test_question_bad_ws
1606
- assert_scanned "? ", :tEH, "?", [0, 1]
1607
- assert_scanned "?\n", :tEH, "?", [0, 1]
1608
- assert_scanned "?\t", :tEH, "?", [0, 1]
1609
- assert_scanned "?\v", :tEH, "?", [0, 1]
1610
- assert_scanned "?\r", :tEH, "?", [0, 1]
1611
- assert_scanned "?\f", :tEH, "?", [0, 1]
1612
- end
1613
-
1614
- def test_question_ws_backslashed__18
1615
- setup_lexer 18
1616
-
1617
- @lex.state = :expr_beg
1618
- assert_scanned "?\\ ", :tINTEGER, 32, [0, 3]
1619
- @lex.state = :expr_beg
1620
- assert_scanned "?\\n", :tINTEGER, 10, [0, 3]
1621
- @lex.state = :expr_beg
1622
- assert_scanned "?\\t", :tINTEGER, 9, [0, 3]
1623
- @lex.state = :expr_beg
1624
- assert_scanned "?\\v", :tINTEGER, 11, [0, 3]
1625
- @lex.state = :expr_beg
1626
- assert_scanned "?\\r", :tINTEGER, 13, [0, 3]
1627
- @lex.state = :expr_beg
1628
- assert_scanned "?\\f", :tINTEGER, 12, [0, 3]
1629
- end
1630
-
1631
- def test_question_ws_backslashed__19
1632
- setup_lexer 19
1633
-
1634
- @lex.state = :expr_beg
1635
- assert_scanned "?\\ ", :tCHARACTER, " ", [0, 3]
1636
- @lex.state = :expr_beg
1637
- assert_scanned "?\\n", :tCHARACTER, "\n", [0, 3]
1638
- @lex.state = :expr_beg
1639
- assert_scanned "?\\t", :tCHARACTER, "\t", [0, 3]
1640
- @lex.state = :expr_beg
1641
- assert_scanned "?\\v", :tCHARACTER, "\v", [0, 3]
1642
- @lex.state = :expr_beg
1643
- assert_scanned "?\\r", :tCHARACTER, "\r", [0, 3]
1644
- @lex.state = :expr_beg
1645
- assert_scanned "?\\f", :tCHARACTER, "\f", [0, 3]
1646
- end
1647
-
1648
- def test_rbracket
1649
- assert_scanned "]", :tRBRACK, "]", [0, 1]
1650
- end
1651
-
1652
- def test_rcurly
1653
- assert_scanned "}", :tRCURLY, "}", [0, 1]
1654
- end
1655
-
1656
- def test_regexp
1657
- assert_scanned("/regexp/",
1658
- :tREGEXP_BEG, "/", [0, 1],
1659
- :tSTRING_CONTENT, "regexp", [1, 7],
1660
- :tSTRING_END, "/", [7, 8],
1661
- :tREGEXP_OPT, "", [8, 8])
1662
- end
1663
-
1664
- def test_regexp_ambiguous
1665
- assert_scanned("method /regexp/",
1666
- :tIDENTIFIER, "method", [0, 6],
1667
- :tREGEXP_BEG, "/", [7, 8],
1668
- :tSTRING_CONTENT, "regexp", [8, 14],
1669
- :tSTRING_END, "/", [14, 15],
1670
- :tREGEXP_OPT, "", [15, 15])
1671
- end
1672
-
1673
- def test_regexp_bad
1674
- refute_scanned("/.*/xyz",
1675
- :tREGEXP_BEG, "/", [0, 1],
1676
- :tSTRING_CONTENT, ".*", [1, 3],
1677
- :tSTRING_END, "/", [3, 4])
1678
- end
1679
-
1680
- def test_regexp_escape_C
1681
- assert_scanned('/regex\\C-x/',
1682
- :tREGEXP_BEG, "/", [0, 1],
1683
- :tSTRING_CONTENT, "regex\\C-x", [1, 10],
1684
- :tSTRING_END, "/", [10, 11],
1685
- :tREGEXP_OPT, "", [11, 11])
1686
- end
1687
-
1688
- def test_regexp_escape_C_M
1689
- assert_scanned('/regex\\C-\\M-x/',
1690
- :tREGEXP_BEG, "/", [0, 1],
1691
- :tSTRING_CONTENT, "regex\\C-\\M-x", [1, 13],
1692
- :tSTRING_END, "/", [13, 14],
1693
- :tREGEXP_OPT, "", [14, 14])
1694
- end
1695
-
1696
- def test_regexp_escape_C_M_craaaazy
1697
- assert_scanned("/regex\\C-\\\n\\M-x/",
1698
- :tREGEXP_BEG, "/", [0, 1],
1699
- :tSTRING_CONTENT, "regex\\C-\\M-x", [1, 15],
1700
- :tSTRING_END, "/", [15, 16],
1701
- :tREGEXP_OPT, "", [16, 16])
1702
- end
1703
-
1704
- def test_regexp_escape_C_bad_dash
1705
- refute_scanned '/regex\\Cx/', :tREGEXP_BEG, "/", [0, 1]
1706
- end
1707
-
1708
- def test_regexp_escape_C_bad_dash_eos
1709
- refute_scanned '/regex\\C-/', :tREGEXP_BEG, "/", [0, 1]
1710
- end
1711
-
1712
- def test_regexp_escape_C_bad_dash_eos2
1713
- refute_scanned '/regex\\C-', :tREGEXP_BEG, "/", [0, 1]
1714
- end
1715
-
1716
- def test_regexp_escape_C_bad_eos
1717
- refute_scanned '/regex\\C/', :tREGEXP_BEG, "/", [0, 1]
1718
- end
1719
-
1720
- def test_regexp_escape_C_bad_eos2
1721
- refute_scanned '/regex\\c', :tREGEXP_BEG, "/", [0, 1]
1722
- end
1723
-
1724
- def test_regexp_escape_M
1725
- assert_scanned('/regex\\M-x/',
1726
- :tREGEXP_BEG, "/", [0, 1],
1727
- :tSTRING_CONTENT, "regex\\M-x", [1, 10],
1728
- :tSTRING_END, "/", [10, 11],
1729
- :tREGEXP_OPT, "", [11, 11])
1730
- end
1731
-
1732
- def test_regexp_escape_M_C
1733
- assert_scanned('/regex\\M-\\C-x/',
1734
- :tREGEXP_BEG, "/", [0, 1],
1735
- :tSTRING_CONTENT, "regex\\M-\\C-x", [1, 13],
1736
- :tSTRING_END, "/", [13, 14],
1737
- :tREGEXP_OPT, "", [14, 14])
1738
- end
1739
-
1740
- def test_regexp_escape_M_bad_dash
1741
- refute_scanned '/regex\\Mx/', :tREGEXP_BEG, "/", [0, 1]
1742
- end
1743
-
1744
- def test_regexp_escape_M_bad_dash_eos
1745
- refute_scanned '/regex\\M-/', :tREGEXP_BEG, "/", [0, 1]
1746
- end
1747
-
1748
- def test_regexp_escape_M_bad_dash_eos2
1749
- refute_scanned '/regex\\M-', :tREGEXP_BEG, "/", [0, 1]
1750
- end
1751
-
1752
- def test_regexp_escape_M_bad_eos
1753
- refute_scanned '/regex\\M/', :tREGEXP_BEG, "/", [0, 1]
1754
- end
1755
-
1756
- def test_regexp_escape_backslash_slash
1757
- assert_scanned('/\\//',
1758
- :tREGEXP_BEG, "/", [0, 1],
1759
- :tSTRING_CONTENT, '/', [1, 3],
1760
- :tSTRING_END, "/", [3, 4],
1761
- :tREGEXP_OPT, "", [4, 4])
1762
- end
1763
-
1764
- def test_regexp_escape_backslash_terminator
1765
- assert_scanned('%r%blah\\%blah%',
1766
- :tREGEXP_BEG, "%r%", [0, 3],
1767
- :tSTRING_CONTENT, "blah%blah", [3, 13],
1768
- :tSTRING_END, "%", [13, 14],
1769
- :tREGEXP_OPT, "", [14, 14])
1770
- end
1771
-
1772
- def test_regexp_escape_backslash_terminator_meta1
1773
- assert_scanned('%r{blah\\}blah}',
1774
- :tREGEXP_BEG, "%r{", [0, 3],
1775
- :tSTRING_CONTENT, "blah\\}blah", [3, 13],
1776
- :tSTRING_END, "}", [13, 14],
1777
- :tREGEXP_OPT, "", [14, 14])
1778
- end
1779
-
1780
- def test_regexp_escape_backslash_terminator_meta2
1781
- assert_scanned('%r/blah\\/blah/',
1782
- :tREGEXP_BEG, "%r/", [0, 3],
1783
- :tSTRING_CONTENT, "blah/blah", [3, 13],
1784
- :tSTRING_END, "/", [13, 14],
1785
- :tREGEXP_OPT, "", [14, 14])
1786
- end
1787
-
1788
- def test_regexp_escape_backslash_terminator_meta3
1789
- assert_scanned('%r/blah\\%blah/',
1790
- :tREGEXP_BEG, "%r/", [0, 3],
1791
- :tSTRING_CONTENT, "blah\\%blah", [3, 13],
1792
- :tSTRING_END, "/", [13, 14],
1793
- :tREGEXP_OPT, "", [14, 14])
1794
- end
1795
-
1796
- def test_regexp_escape_bad_eos
1797
- refute_scanned '/regex\\', :tREGEXP_BEG, "/", [0, 1]
1798
- end
1799
-
1800
- def test_regexp_escape_bs
1801
- assert_scanned('/regex\\\\regex/',
1802
- :tREGEXP_BEG, "/", [0, 1],
1803
- :tSTRING_CONTENT, "regex\\\\regex", [1, 13],
1804
- :tSTRING_END, "/", [13, 14],
1805
- :tREGEXP_OPT, "", [14, 14])
1806
- end
1807
-
1808
- def test_regexp_escape_c
1809
- assert_scanned('/regex\\cxxx/',
1810
- :tREGEXP_BEG, "/", [0, 1],
1811
- :tSTRING_CONTENT, "regex\\cxxx", [1, 11],
1812
- :tSTRING_END, "/", [11, 12],
1813
- :tREGEXP_OPT, "", [12, 12])
1814
- end
1815
-
1816
- def test_regexp_escape_c_backslash
1817
- assert_scanned('/regex\\c\\n/',
1818
- :tREGEXP_BEG, "/", [0, 1],
1819
- :tSTRING_CONTENT, "regex\\c\\n", [1, 10],
1820
- :tSTRING_END, "/", [10, 11],
1821
- :tREGEXP_OPT, "", [11, 11])
1822
- end
1823
-
1824
- def test_regexp_escape_chars
1825
- assert_scanned('/re\\tge\\nxp/',
1826
- :tREGEXP_BEG, "/", [0, 1],
1827
- :tSTRING_CONTENT, "re\\tge\\nxp", [1, 11],
1828
- :tSTRING_END, "/", [11, 12],
1829
- :tREGEXP_OPT, "", [12, 12])
1830
- end
1831
-
1832
- def test_regexp_escape_double_backslash
1833
- assert_scanned('/[\\/\\\\]$/',
1834
- :tREGEXP_BEG, "/", [0, 1],
1835
- :tSTRING_CONTENT,'[/\\\\]$', [1, 8],
1836
- :tSTRING_END, "/", [8, 9],
1837
- :tREGEXP_OPT, "", [9, 9])
1838
- end
1839
-
1840
- def test_regexp_escape_hex
1841
- assert_scanned('/regex\\x61xp/',
1842
- :tREGEXP_BEG, "/", [0, 1],
1843
- :tSTRING_CONTENT, "regex\\x61xp", [1, 12],
1844
- :tSTRING_END, "/", [12, 13],
1845
- :tREGEXP_OPT, "", [13, 13])
1846
- end
1847
-
1848
- def test_regexp_escape_hex_bad
1849
- refute_scanned '/regex\\xzxp/', :tREGEXP_BEG, "/", [0, 1]
1850
- end
1851
-
1852
- def test_regexp_escape_hex_one
1853
- assert_scanned('/^[\\xd\\xa]{2}/on',
1854
- :tREGEXP_BEG, '/', [0, 1],
1855
- :tSTRING_CONTENT, '^[\\xd\\xa]{2}', [1, 13],
1856
- :tSTRING_END, "/", [13, 14],
1857
- :tREGEXP_OPT, 'on', [14, 16])
1858
- end
1859
-
1860
- def test_regexp_escape_oct1
1861
- assert_scanned('/regex\\0xp/',
1862
- :tREGEXP_BEG, "/", [0, 1],
1863
- :tSTRING_CONTENT, "regex\\0xp", [1, 10],
1864
- :tSTRING_END, "/", [10, 11],
1865
- :tREGEXP_OPT, "", [11, 11])
1866
- end
1867
-
1868
- def test_regexp_escape_oct2
1869
- assert_scanned('/regex\\07xp/',
1870
- :tREGEXP_BEG, "/", [0, 1],
1871
- :tSTRING_CONTENT, "regex\\07xp", [1, 11],
1872
- :tSTRING_END, "/", [11, 12],
1873
- :tREGEXP_OPT, "", [12, 12])
1874
- end
1875
-
1876
- def test_regexp_escape_oct3
1877
- assert_scanned('/regex\\10142/',
1878
- :tREGEXP_BEG, "/", [0, 1],
1879
- :tSTRING_CONTENT, "regex\\10142", [1, 12],
1880
- :tSTRING_END, "/", [12, 13],
1881
- :tREGEXP_OPT, "", [13, 13])
1882
- end
1883
-
1884
- def test_regexp_escape_return
1885
- assert_scanned("/regex\\\nregex/",
1886
- :tREGEXP_BEG, "/", [0, 1],
1887
- :tSTRING_CONTENT, "regexregex", [1, 13],
1888
- :tSTRING_END, "/", [13, 14],
1889
- :tREGEXP_OPT, "", [14, 14])
1890
- end
1891
-
1892
- def test_regexp_escape_delimiter_meta
1893
- assert_scanned("%r(\\))",
1894
- :tREGEXP_BEG, "%r(", [0, 3],
1895
- :tSTRING_CONTENT, "\\)", [3, 5],
1896
- :tSTRING_END, ")", [5, 6],
1897
- :tREGEXP_OPT, "", [6, 6])
1898
- end
1899
-
1900
- def test_regexp_escape_delimiter_nonmeta
1901
- assert_scanned("%r'\\''",
1902
- :tREGEXP_BEG, "%r'", [0, 3],
1903
- :tSTRING_CONTENT, "'", [3, 5],
1904
- :tSTRING_END, "'", [5, 6],
1905
- :tREGEXP_OPT, "", [6, 6])
1906
- end
1907
-
1908
- def test_regexp_escape_other_meta
1909
- assert_scanned("/\\.\\$\\*\\+\\.\\?\\|/",
1910
- :tREGEXP_BEG, "/", [0, 1],
1911
- :tSTRING_CONTENT, "\\.\\$\\*\\+\\.\\?\\|", [1, 15],
1912
- :tSTRING_END, "/", [15, 16],
1913
- :tREGEXP_OPT, "", [16, 16])
1914
- end
1915
-
1916
- def test_regexp_nm
1917
- assert_scanned("/.*/nm",
1918
- :tREGEXP_BEG, "/", [0, 1],
1919
- :tSTRING_CONTENT, ".*", [1, 3],
1920
- :tSTRING_END, "/", [3, 4],
1921
- :tREGEXP_OPT, "nm", [4, 6])
1922
- end
1923
-
1924
- def test_rparen
1925
- assert_scanned ")", :tRPAREN, ")", [0, 1]
1926
- end
1927
-
1928
- def test_rshft
1929
- assert_scanned("a >> 2",
1930
- :tIDENTIFIER, "a", [0, 1],
1931
- :tRSHFT, ">>", [2, 4],
1932
- :tINTEGER, 2, [5, 6])
1933
- end
1934
-
1935
- def test_rshft_equals
1936
- assert_scanned("a >>= 2",
1937
- :tIDENTIFIER, "a", [0, 1],
1938
- :tOP_ASGN, ">>", [2, 5],
1939
- :tINTEGER, 2, [6, 7])
1940
- end
1941
-
1942
- def test_star
1943
- assert_scanned("a * ",
1944
- :tIDENTIFIER, "a", [0, 1],
1945
- :tSTAR2, "*", [2, 3])
1946
-
1947
- assert_equal :expr_value, @lex.state
1948
- end
1949
-
1950
- def test_star2
1951
- assert_scanned("a ** ",
1952
- :tIDENTIFIER, "a", [0, 1],
1953
- :tPOW, "**", [2, 4])
1954
-
1955
- assert_equal :expr_value, @lex.state
1956
- end
1957
-
1958
- def test_star2_equals
1959
- assert_scanned("a **= ",
1960
- :tIDENTIFIER, "a", [0, 1],
1961
- :tOP_ASGN, "**", [2, 5])
1962
-
1963
- assert_equal :expr_beg, @lex.state
1964
- end
1965
-
1966
- def test_star2_beg
1967
- assert_scanned("** ",
1968
- :tDSTAR, "**", [0, 2])
1969
-
1970
- assert_equal :expr_beg, @lex.state
1971
- end
1972
-
1973
- def test_star_arg
1974
- @lex.state = :expr_arg
1975
-
1976
- assert_scanned(" *a",
1977
- :tSTAR, "*", [1, 2],
1978
- :tIDENTIFIER, "a", [2, 3])
1979
-
1980
- assert_equal :expr_arg, @lex.state
1981
- end
1982
-
1983
- def test_star_arg_beg
1984
- @lex.state = :expr_beg
1985
-
1986
- assert_scanned("*a",
1987
- :tSTAR, "*", [0, 1],
1988
- :tIDENTIFIER, "a", [1, 2])
1989
-
1990
- assert_equal :expr_arg, @lex.state
1991
- end
1992
-
1993
- def test_star_arg_beg_fname
1994
- @lex.state = :expr_fname
1995
-
1996
- assert_scanned("*a",
1997
- :tSTAR2, "*", [0, 1],
1998
- :tIDENTIFIER, "a", [1, 2])
1999
-
2000
- assert_equal :expr_arg, @lex.state
2001
- end
2002
-
2003
- def test_star_equals
2004
- assert_scanned("a *= ",
2005
- :tIDENTIFIER, "a", [0, 1],
2006
- :tOP_ASGN, "*", [2, 4])
2007
-
2008
- assert_equal :expr_beg, @lex.state
2009
- end
2010
-
2011
- def test_string_bad_eos
2012
- refute_scanned('%',
2013
- :tSTRING_BEG, '%', [0, 1])
2014
- end
2015
-
2016
- def test_string_bad_eos_quote
2017
- refute_scanned('%{nest',
2018
- :tSTRING_BEG, '%}', [0, 2])
2019
- end
2020
-
2021
- def test_string_double
2022
- assert_scanned('"string"',
2023
- :tSTRING, "string", [0, 8])
2024
- end
2025
-
2026
- def test_string_double_escape_C
2027
- assert_scanned('"\\C-a"',
2028
- :tSTRING, "\001", [0, 6])
2029
- end
2030
-
2031
- def test_string_double_escape_C_backslash
2032
- assert_scanned('"\\C-\\\\"',
2033
- :tSTRING, "\034", [0, 7])
2034
- end
2035
-
2036
- def test_string_double_escape_C_escape
2037
- assert_scanned('"\\C-\\M-a"',
2038
- :tSTRING, "\201", [0, 9])
2039
- end
2040
-
2041
- def test_string_double_escape_C_question
2042
- assert_scanned('"\\C-?"',
2043
- :tSTRING, "\177", [0, 6])
2044
- end
2045
-
2046
- def test_string_double_escape_M
2047
- assert_scanned('"\\M-a"',
2048
- :tSTRING, "\341", [0, 6])
2049
- end
2050
-
2051
- def test_string_double_escape_M_backslash
2052
- assert_scanned('"\\M-\\\\"',
2053
- :tSTRING, "\334", [0, 7])
2054
- end
2055
-
2056
- def test_string_double_escape_M_escape
2057
- assert_scanned('"\\M-\\C-a"',
2058
- :tSTRING, "\201", [0, 9])
2059
- end
2060
-
2061
- def test_string_double_escape_bs1
2062
- assert_scanned('"a\\a\\a"',
2063
- :tSTRING, "a\a\a", [0, 7])
2064
- end
2065
-
2066
- def test_string_double_escape_bs2
2067
- assert_scanned('"a\\\\a"',
2068
- :tSTRING, "a\\a", [0, 6])
2069
- end
2070
-
2071
- def test_string_double_escape_c
2072
- assert_scanned('"\\ca"',
2073
- :tSTRING, "\001", [0, 5])
2074
- end
2075
-
2076
- def test_string_double_escape_c_escape
2077
- assert_scanned('"\\c\\M-a"',
2078
- :tSTRING, "\201", [0, 8])
2079
- end
2080
-
2081
- def test_string_double_escape_c_question
2082
- assert_scanned('"\\c?"',
2083
- :tSTRING, "\177", [0, 5])
2084
- end
2085
-
2086
- def test_string_double_escape_chars
2087
- assert_scanned('"s\\tri\\ng"',
2088
- :tSTRING, "s\tri\ng", [0, 10])
2089
- end
2090
-
2091
- def test_string_double_escape_hex
2092
- assert_scanned('"n = \\x61\\x62\\x63"',
2093
- :tSTRING, "n = abc", [0, 18])
2094
- end
2095
-
2096
- def test_string_double_escape_octal
2097
- assert_scanned('"n = \\101\\102\\103"',
2098
- :tSTRING, "n = ABC", [0, 18])
2099
- end
2100
-
2101
- def test_string_double_escape_octal_wrap
2102
- assert_scanned('"\\753"',
2103
- :tSTRING, "\xEB", [0, 6])
2104
- end
2105
-
2106
- def test_string_double_interp
2107
- assert_scanned("\"blah #x a \#@a b \#$b c \#{3} # \"",
2108
- :tSTRING_BEG, "\"", [0, 1],
2109
- :tSTRING_CONTENT, "blah #x a ", [1, 11],
2110
- :tSTRING_DVAR, nil, [11, 12],
2111
- :tIVAR, "@a", [12, 14],
2112
- :tSTRING_CONTENT, " b ", [14, 17],
2113
- :tSTRING_DVAR, nil, [17, 18],
2114
- :tGVAR, "$b", [18, 20],
2115
- :tSTRING_CONTENT, " c ", [20, 23],
2116
- :tSTRING_DBEG, '#{', [23, 25],
2117
- :tINTEGER, 3, [25, 26],
2118
- :tRCURLY, "}", [26, 27],
2119
- :tSTRING_CONTENT, " # ", [27, 30],
2120
- :tSTRING_END, "\"", [30, 31])
2121
- end
2122
-
2123
- def test_string_double_interp_label
2124
- assert_scanned('"#{foo:bar}"',
2125
- :tSTRING_BEG, '"', [0, 1],
2126
- :tSTRING_DBEG, '#{', [1, 3],
2127
- :tIDENTIFIER, 'foo', [3, 6],
2128
- :tSYMBOL, 'bar', [6, 10],
2129
- :tRCURLY, '}', [10, 11],
2130
- :tSTRING_END, '"', [11, 12])
2131
- end
2132
-
2133
- def test_string_double_nested_curlies
2134
- assert_scanned('%{nest{one{two}one}nest}',
2135
- :tSTRING_BEG, '%{', [0, 2],
2136
- :tSTRING_CONTENT, "nest{one{two}one}nest", [2, 23],
2137
- :tSTRING_END, '}', [23, 24])
2138
- end
2139
-
2140
- def test_string_double_no_interp
2141
- assert_scanned("\"# blah\"", # pound first
2142
- :tSTRING, "# blah", [0, 8])
2143
-
2144
- assert_scanned("\"blah # blah\"", # pound not first
2145
- :tSTRING, "blah # blah", [0, 13])
2146
- end
2147
-
2148
- def test_string_escape_x_single
2149
- assert_scanned('"\\x0"',
2150
- :tSTRING, "\000", [0, 5])
2151
- end
2152
-
2153
- def test_string_pct_Q
2154
- assert_scanned("%Q[s1 s2]",
2155
- :tSTRING_BEG, '%Q[', [0, 3],
2156
- :tSTRING_CONTENT, "s1 s2", [3, 8],
2157
- :tSTRING_END, ']', [8, 9])
2158
- end
2159
-
2160
- def test_string_pct_W
2161
- assert_scanned("%W[s1 s2\ns3]",
2162
- :tWORDS_BEG, "%W[", [0, 3],
2163
- :tSTRING_CONTENT, "s1", [3, 5],
2164
- :tSPACE, nil, [5, 6],
2165
- :tSTRING_CONTENT, "s2", [6, 8],
2166
- :tSPACE, nil, [8, 9],
2167
- :tSTRING_CONTENT, "s3", [9, 11],
2168
- :tSPACE, nil, [11, 11],
2169
- :tSTRING_END, ']', [11, 12])
2170
- end
2171
-
2172
- def test_string_pct_W_bs_nl
2173
- assert_scanned("%W[s1 \\\ns2]",
2174
- :tWORDS_BEG, "%W[", [0, 3],
2175
- :tSTRING_CONTENT, "s1", [3, 5],
2176
- :tSPACE, nil, [5, 6],
2177
- :tSTRING_CONTENT, "\ns2", [6, 10],
2178
- :tSPACE, nil, [10, 10],
2179
- :tSTRING_END, ']', [10, 11])
2180
- end
2181
-
2182
- def test_string_pct_W_interp
2183
- assert_scanned('%W[#{1}#{2} #@a]',
2184
- :tWORDS_BEG, '%W[', [0, 3],
2185
- :tSTRING_DBEG, '#{', [3, 5],
2186
- :tINTEGER, 1, [5, 6],
2187
- :tRCURLY, '}', [6, 7],
2188
- :tSTRING_DBEG, '#{', [7, 9],
2189
- :tINTEGER, 2, [9, 10],
2190
- :tRCURLY, '}', [10, 11],
2191
- :tSPACE, nil, [11, 12],
2192
- :tSTRING_DVAR, nil, [12, 13],
2193
- :tIVAR, '@a', [13, 15],
2194
- :tSPACE, nil, [15, 15],
2195
- :tSTRING_END, ']', [15, 16])
2196
- end
2197
-
2198
- def test_string_pct_I
2199
- assert_scanned("%I(s1 s2)",
2200
- :tSYMBOLS_BEG, "%I(", [0, 3],
2201
- :tSTRING_CONTENT, "s1", [3, 5],
2202
- :tSPACE, nil, [5, 6],
2203
- :tSTRING_CONTENT, "s2", [6, 8],
2204
- :tSPACE, nil, [8, 8],
2205
- :tSTRING_END, ')', [8, 9])
2206
- end
2207
-
2208
- def test_string_pct_angle
2209
- assert_scanned("%<blah>",
2210
- :tSTRING_BEG, '%<', [0, 2],
2211
- :tSTRING_CONTENT, "blah", [2, 6],
2212
- :tSTRING_END, '>', [6, 7])
2213
- end
2214
-
2215
- def test_string_pct_pct
2216
- assert_scanned("%%blah%",
2217
- :tSTRING_BEG, '%%', [0, 2],
2218
- :tSTRING_CONTENT, "blah", [2, 6],
2219
- :tSTRING_END, '%', [6, 7])
2220
- end
2221
-
2222
- def test_string_pct_w
2223
- assert_scanned("%w[s1 s2 ]",
2224
- :tQWORDS_BEG, "%w[", [0, 3],
2225
- :tSTRING_CONTENT, "s1", [3, 5],
2226
- :tSPACE, nil, [5, 6],
2227
- :tSTRING_CONTENT, "s2", [6, 8],
2228
- :tSPACE, nil, [8, 9],
2229
- :tSTRING_END, "]", [9, 10])
2230
- end
2231
-
2232
- def test_string_pct_w_incomplete
2233
- refute_scanned("%w[s1 ",
2234
- :tQWORDS_BEG, "%w[", [0, 3],
2235
- :tSTRING_CONTENT, "s1", [3, 5],
2236
- :tSPACE, nil, [5, 6])
2237
- end
2238
-
2239
- def test_string_pct_w_bs_nl
2240
- assert_scanned("%w[s1 \\\ns2]",
2241
- :tQWORDS_BEG, "%w[", [0, 3],
2242
- :tSTRING_CONTENT, "s1", [3, 5],
2243
- :tSPACE, nil, [5, 6],
2244
- :tSTRING_CONTENT, "\ns2", [6, 10],
2245
- :tSPACE, nil, [10, 10],
2246
- :tSTRING_END, ']', [10, 11])
2247
- end
2248
-
2249
- def test_string_pct_w_bs_sp
2250
- assert_scanned("%w[s\\ 1 s\\ 2]",
2251
- :tQWORDS_BEG, "%w[", [0, 3],
2252
- :tSTRING_CONTENT, "s 1", [3, 7],
2253
- :tSPACE, nil, [7, 8],
2254
- :tSTRING_CONTENT, "s 2", [8, 12],
2255
- :tSPACE, nil, [12, 12],
2256
- :tSTRING_END, ']', [12, 13])
2257
- end
2258
-
2259
- def test_string_pct_w_tab
2260
- assert_scanned("%w[abc\tdef]",
2261
- :tQWORDS_BEG, "%w[", [0, 3],
2262
- :tSTRING_CONTENT, "abc", [3, 6],
2263
- :tSPACE, nil, [6, 7],
2264
- :tSTRING_CONTENT, "def", [7, 10],
2265
- :tSPACE, nil, [10, 10],
2266
- :tSTRING_END, ']', [10, 11])
2267
- end
2268
-
2269
- def test_string_pct_i
2270
- assert_scanned("%i(s1 s2)",
2271
- :tQSYMBOLS_BEG, "%i(", [0, 3],
2272
- :tSTRING_CONTENT, "s1", [3, 5],
2273
- :tSPACE, nil, [5, 6],
2274
- :tSTRING_CONTENT, "s2", [6, 8],
2275
- :tSPACE, nil, [8, 8],
2276
- :tSTRING_END, ')', [8, 9])
2277
- end
2278
-
2279
- def test_string_pct_backslash
2280
- assert_scanned("%\\a\\",
2281
- :tSTRING_BEG, "%\\", [0, 2],
2282
- :tSTRING_CONTENT, "a", [2, 3],
2283
- :tSTRING_END, "\\", [3, 4])
2284
- end
2285
-
2286
- def test_string_pct_w_backslash
2287
- assert_scanned("%w\\s1 s2 \\",
2288
- :tQWORDS_BEG, "%w\\", [0, 3],
2289
- :tSTRING_CONTENT, "s1", [3, 5],
2290
- :tSPACE, nil, [5, 6],
2291
- :tSTRING_CONTENT, "s2", [6, 8],
2292
- :tSPACE, nil, [8, 9],
2293
- :tSTRING_END, "\\", [9, 10])
2294
- end
2295
-
2296
- def test_string_pct_w_backslash_nl
2297
- assert_scanned("%w\\s1 s2 \\\n",
2298
- :tQWORDS_BEG, "%w\\", [0, 3],
2299
- :tSTRING_CONTENT, "s1", [3, 5],
2300
- :tSPACE, nil, [5, 6],
2301
- :tSTRING_CONTENT, "s2", [6, 8],
2302
- :tSPACE, nil, [8, 9],
2303
- :tSTRING_END, "\\", [9, 10],
2304
- :tNL, nil, [10, 11])
2305
- end
2306
-
2307
- def test_string_pct_w_backslash_interp_nl
2308
- assert_scanned("%W\\blah #x a \#@a b \#$b c \#{3} # \\",
2309
- :tWORDS_BEG, "%W\\", [0, 3],
2310
- :tSTRING_CONTENT, "blah", [3, 7],
2311
- :tSPACE, nil, [7, 8],
2312
- :tSTRING_CONTENT, "#x", [8, 10],
2313
- :tSPACE, nil, [10, 11],
2314
- :tSTRING_CONTENT, "a", [11, 12],
2315
- :tSPACE, nil, [12, 13],
2316
- :tSTRING_DVAR, nil, [13, 14],
2317
- :tIVAR, "@a", [14, 16],
2318
- :tSPACE, nil, [16, 17],
2319
- :tSTRING_CONTENT, "b", [17, 18],
2320
- :tSPACE, nil, [18, 19],
2321
- :tSTRING_DVAR, nil, [19, 20],
2322
- :tGVAR, "$b", [20, 22],
2323
- :tSPACE, nil, [22, 23],
2324
- :tSTRING_CONTENT, "c", [23, 24],
2325
- :tSPACE, nil, [24, 25],
2326
- :tSTRING_DBEG, '#{', [25, 27],
2327
- :tINTEGER, 3, [27, 28],
2328
- :tRCURLY, "}", [28, 29],
2329
- :tSPACE, nil, [29, 30],
2330
- :tSTRING_CONTENT, "#", [30, 31],
2331
- :tSPACE, nil, [31, 32],
2332
- :tSTRING_END, "\\", [32, 33])
2333
- end
2334
-
2335
- def test_string_pct_backslash_with_bad_escape
2336
- # No escapes are allowed in a backslash-delimited string
2337
- refute_scanned("%\\a\\n\\",
2338
- :tSTRING_BEG, "%\\", [0, 2],
2339
- :tSTRING_CONTENT, "a", [2, 3],
2340
- :tSTRING_END, "\\", [3, 4],
2341
- :tIDENTIFIER, "n", [4, 5])
2342
- end
2343
-
2344
- def test_string_pct_intertwined_with_heredoc
2345
- assert_scanned("<<-foo + %\\a\nbar\nfoo\nb\\",
2346
- :tSTRING_BEG, "<<\"", [0, 6],
2347
- :tSTRING_CONTENT, "bar\n", [13, 17],
2348
- :tSTRING_END, "foo", [17, 20],
2349
- :tPLUS, "+", [7, 8],
2350
- :tSTRING_BEG, "%\\", [9, 11],
2351
- :tSTRING_CONTENT, "a\n", [11, 13],
2352
- :tSTRING_CONTENT, "b", [21, 22],
2353
- :tSTRING_END, "\\", [22, 23])
2354
- end
2355
-
2356
- def test_string_pct_q_backslash
2357
- assert_scanned("%q\\a\\",
2358
- :tSTRING_BEG, "%q\\", [0, 3],
2359
- :tSTRING_CONTENT, "a", [3, 4],
2360
- :tSTRING_END, "\\", [4, 5])
2361
- end
2362
-
2363
- def test_string_pct_Q_backslash
2364
- assert_scanned("%Q\\a\\",
2365
- :tSTRING_BEG, "%Q\\", [0, 3],
2366
- :tSTRING_CONTENT, "a", [3, 4],
2367
- :tSTRING_END, "\\", [4, 5])
2368
- end
2369
-
2370
- def test_string_single
2371
- assert_scanned("'string'",
2372
- :tSTRING, "string", [0, 8])
2373
- end
2374
-
2375
- def test_string_single_escape_chars
2376
- assert_scanned("'s\\tri\\ng'",
2377
- :tSTRING, "s\\tri\\ng", [0, 10])
2378
- end
2379
-
2380
- def test_string_single_nl
2381
- assert_scanned("'blah\\\nblah'",
2382
- :tSTRING_BEG, "'", [0, 1],
2383
- :tSTRING_CONTENT, "blah\\\n", [1, 7],
2384
- :tSTRING_CONTENT, "blah", [7, 11],
2385
- :tSTRING_END, "'", [11, 12])
2386
- end
2387
-
2388
- def test_symbol
2389
- assert_scanned(":symbol",
2390
- :tSYMBOL, "symbol", [0, 7])
2391
- end
2392
-
2393
- def test_symbol_double
2394
- assert_scanned(":\"symbol\"",
2395
- :tSYMBEG, ":\"", [0, 2],
2396
- :tSTRING_CONTENT, "symbol", [2, 8],
2397
- :tSTRING_END, "\"", [8, 9])
2398
- end
2399
-
2400
- def test_symbol_single
2401
- assert_scanned(":'symbol'",
2402
- :tSYMBEG, ":'", [0, 2],
2403
- :tSTRING_CONTENT, "symbol", [2, 8],
2404
- :tSTRING_END, "'", [8, 9])
2405
- end
2406
-
2407
- def test_ternary
2408
- assert_scanned("a ? b : c",
2409
- :tIDENTIFIER, "a", [0, 1],
2410
- :tEH, "?", [2, 3],
2411
- :tIDENTIFIER, "b", [4, 5],
2412
- :tCOLON, ":", [6, 7],
2413
- :tIDENTIFIER, "c", [8, 9])
2414
-
2415
- assert_scanned("a ?b : c",
2416
- :tIDENTIFIER, "a", [0, 1],
2417
- :tINTEGER, 98, [2, 4],
2418
- :tCOLON, ":", [5, 6],
2419
- :tIDENTIFIER, "c", [7, 8])
2420
-
2421
- assert_scanned("a ?bb : c", # GAH! MATZ!!!
2422
- :tIDENTIFIER, "a", [0, 1],
2423
- :tEH, "?", [2, 3],
2424
- :tIDENTIFIER, "bb", [3, 5],
2425
- :tCOLON, ":", [6, 7],
2426
- :tIDENTIFIER, "c", [8, 9])
2427
-
2428
- assert_scanned("42 ?", # 42 forces expr_end
2429
- :tINTEGER, 42, [0, 2],
2430
- :tEH, "?", [3, 4])
2431
- end
2432
-
2433
- def test_tilde
2434
- assert_scanned "~", :tTILDE, "~", [0, 1]
2435
- end
2436
-
2437
- def test_tilde_unary
2438
- @lex.state = :expr_fname
2439
- assert_scanned "~@", :tTILDE, "~@", [0, 2]
2440
- end
2441
-
2442
- def test_uminus
2443
- assert_scanned("-blah",
2444
- :tUMINUS, "-", [0, 1],
2445
- :tIDENTIFIER, "blah", [1, 5])
2446
- end
2447
-
2448
- def test_underscore
2449
- assert_scanned("_var", :tIDENTIFIER, "_var", [0, 4])
2450
- end
2451
-
2452
- def test_underscore_end
2453
- assert_scanned("__END__\n")
2454
- assert_scanned("__END__")
2455
- assert_scanned("__END__ foo",
2456
- :tIDENTIFIER, '__END__', [0, 7],
2457
- :tIDENTIFIER, 'foo', [8, 11])
2458
- assert_scanned("__END__\rfoo",
2459
- :tIDENTIFIER, '__END__', [0, 7],
2460
- :tIDENTIFIER, 'foo', [8, 11])
2461
- end
2462
-
2463
- def test_uplus
2464
- assert_scanned("+blah",
2465
- :tUPLUS, "+", [0, 1],
2466
- :tIDENTIFIER, "blah", [1, 5])
2467
- end
2468
-
2469
- def test_if_unless_mod
2470
- assert_scanned("return if true unless false",
2471
- :kRETURN, "return", [0, 6],
2472
- :kIF_MOD, "if", [7, 9],
2473
- :kTRUE, "true", [10, 14],
2474
- :kUNLESS_MOD, "unless", [15, 21],
2475
- :kFALSE, "false", [22, 27])
2476
- end
2477
-
2478
- def test_if_stmt
2479
- assert_scanned("if true\n return end",
2480
- :kIF, "if", [0, 2],
2481
- :kTRUE, "true", [3, 7],
2482
- :tNL, nil, [7, 8],
2483
- :kRETURN, "return", [9, 15],
2484
- :kEND, "end", [16, 19])
2485
- end
2486
-
2487
- def test_sclass_label
2488
- setup_lexer 20
2489
- assert_scanned("class << a:b",
2490
- :kCLASS, 'class', [0, 5],
2491
- :tLSHFT, '<<', [6, 8],
2492
- :tIDENTIFIER, 'a', [9, 10],
2493
- :tSYMBOL, 'b', [10, 12])
2494
- end
2495
-
2496
- def test_fname_pct_s__22
2497
- setup_lexer 22
2498
- @lex.state = :expr_fname
2499
- assert_scanned("%s(a)",
2500
- :tPERCENT, '%', [0, 1],
2501
- :tIDENTIFIER, 's', [1, 2],
2502
- :tLPAREN2, '(', [2, 3],
2503
- :tIDENTIFIER, 'a', [3, 4],
2504
- :tRPAREN, ')', [4, 5])
2505
- end
2506
-
2507
- def test_fname_pct_s__23
2508
- setup_lexer 23
2509
- @lex.state = :expr_fname
2510
- assert_scanned("%s(a)",
2511
- :tSYMBEG, '%s(', [0, 3],
2512
- :tSTRING_CONTENT, 'a', [3, 4],
2513
- :tSTRING_END, ')', [4, 5])
2514
- end
2515
-
2516
- def test_static_env
2517
- env = Parser::StaticEnvironment.new
2518
- env.declare "a"
2519
-
2520
- @lex.static_env = env
2521
- assert_scanned("a [42]",
2522
- :tIDENTIFIER, "a", [0, 1],
2523
- :tLBRACK2, "[", [2, 3],
2524
- :tINTEGER, 42, [3, 5],
2525
- :tRBRACK, "]", [5, 6])
2526
- end
2527
-
2528
- def test_int_suffix
2529
- [18, 19, 20].each do |version|
2530
- setup_lexer version
2531
-
2532
- assert_scanned("42r",
2533
- :tINTEGER, 42, [0, 2],
2534
- :tIDENTIFIER, 'r', [2, 3])
2535
-
2536
- assert_scanned("42if",
2537
- :tINTEGER, 42, [0, 2],
2538
- :kIF_MOD, 'if', [2, 4])
2539
- end
2540
-
2541
- setup_lexer 21
2542
-
2543
- assert_scanned("42r", :tRATIONAL, Rational(42), [0, 3])
2544
- assert_scanned("42i", :tIMAGINARY, Complex(0, 42), [0, 3])
2545
- assert_scanned("42ri", :tIMAGINARY, Complex(0, Rational(42)), [0, 4])
2546
- end
2547
-
2548
- def test_float_suffix
2549
- [18, 19, 20].each do |version|
2550
- setup_lexer version
2551
-
2552
- assert_scanned("42.1r",
2553
- :tFLOAT, 42.1, [0, 4],
2554
- :tIDENTIFIER, 'r', [4, 5])
2555
-
2556
- assert_scanned("42.1if",
2557
- :tFLOAT, 42.1, [0, 4],
2558
- :kIF_MOD, 'if', [4, 6])
2559
-
2560
- assert_scanned("1e1r",
2561
- :tFLOAT, 1e1, [0, 3],
2562
- :tIDENTIFIER, 'r', [3, 4])
2563
- end
2564
-
2565
- begin
2566
- # Feature-check.
2567
- Rational("10")
2568
-
2569
- setup_lexer 21
2570
-
2571
- assert_scanned("42.1r", :tRATIONAL, Rational(421, 10), [0, 5])
2572
- assert_scanned("42.1i", :tIMAGINARY, Complex(0, 42.1), [0, 5])
2573
- assert_scanned("42.1ri", :tIMAGINARY, Complex(0, Rational(421, 10)), [0, 6])
2574
- assert_scanned("42.1ir",
2575
- :tIMAGINARY, Complex(0, 42.1), [0, 5],
2576
- :tIDENTIFIER, 'r', [5, 6])
2577
-
2578
- assert_scanned("1e1i", :tIMAGINARY, Complex(0, 1e1), [0, 4])
2579
- assert_scanned("1e1r",
2580
- :tFLOAT, 1e1, [0, 3],
2581
- :tIDENTIFIER, 'r', [3, 4])
2582
- assert_scanned("1e1ri",
2583
- :tFLOAT, 1e1, [0, 3],
2584
- :tIDENTIFIER, 'ri', [3, 5])
2585
- assert_scanned("1e1ir",
2586
- :tIMAGINARY, Complex(0, 1e1), [0, 4],
2587
- :tIDENTIFIER, 'r', [4, 5])
2588
- rescue NoMethodError
2589
- # Ruby not modern enough
2590
- end
2591
- end
2592
-
2593
- def test_eof
2594
- assert_scanned("self",
2595
- :kSELF, "self", [0, 4])
2596
- assert_equal([false, ["$eof", Parser::Source::Range.new(@lex.source_buffer, 4, 4)]],
2597
- @lex.advance)
2598
- end
2599
-
2600
- #
2601
- # Test for 'fluent interface'
2602
- #
2603
-
2604
- def test_fluent_dot
2605
- assert_scanned("x\n.y",
2606
- :tIDENTIFIER, 'x', [0, 1],
2607
- :tDOT, '.', [2, 3],
2608
- :tIDENTIFIER, 'y', [3, 4])
2609
-
2610
- assert_scanned("x\n .y",
2611
- :tIDENTIFIER, 'x', [0, 1],
2612
- :tDOT, '.', [4, 5],
2613
- :tIDENTIFIER, 'y', [5, 6])
2614
-
2615
- assert_scanned("x # comment\n .y",
2616
- :tIDENTIFIER, 'x', [0, 1],
2617
- :tDOT, '.', [14, 15],
2618
- :tIDENTIFIER, 'y', [15, 16])
2619
- end
2620
-
2621
- def test_fluent_and_dot
2622
- assert_scanned("x\n&.y",
2623
- :tIDENTIFIER, 'x', [0, 1],
2624
- :tANDDOT, '&.', [2, 4],
2625
- :tIDENTIFIER, 'y', [4, 5])
2626
- end
2627
-
2628
- #
2629
- # Tests for whitespace.
2630
- #
2631
-
2632
- def test_whitespace_fname
2633
- @lex.state = :expr_fname
2634
- assert_scanned('class',
2635
- :kCLASS, 'class', [0, 5])
2636
-
2637
- @lex.state = :expr_fname
2638
- assert_scanned(' class',
2639
- :kCLASS, 'class', [1, 6])
2640
-
2641
- @lex.state = :expr_fname
2642
- assert_scanned("\nclass",
2643
- :kCLASS, 'class', [1, 6])
2644
-
2645
- @lex.state = :expr_fname
2646
- assert_scanned("\\\nclass",
2647
- :kCLASS, 'class', [2, 7])
2648
-
2649
- @lex.state = :expr_fname
2650
- assert_scanned("#foo\nclass",
2651
- :kCLASS, 'class', [5, 10])
2652
- end
2653
-
2654
- def test_whitespace_endfn
2655
- setup_lexer(21)
2656
-
2657
- @lex.state = :expr_endfn
2658
- assert_scanned('foo:',
2659
- :tLABEL, 'foo', [0, 4])
2660
-
2661
- @lex.state = :expr_endfn
2662
- assert_scanned(' foo:',
2663
- :tLABEL, 'foo', [1, 5])
2664
-
2665
- @lex.state = :expr_endfn
2666
- assert_scanned("\nfoo:",
2667
- :tNL, nil, [0, 1],
2668
- :tIDENTIFIER, 'foo', [1, 4],
2669
- :tCOLON, ':', [4, 5])
2670
-
2671
- @lex.state = :expr_endfn
2672
- assert_scanned("\nfoo: ",
2673
- :tNL, nil, [0, 1],
2674
- :tIDENTIFIER, 'foo', [1, 4],
2675
- :tCOLON, ':', [4, 5])
2676
-
2677
- @lex.state = :expr_endfn
2678
- assert_scanned("\\\nfoo:",
2679
- :tLABEL, 'foo', [2, 6])
2680
-
2681
- @lex.state = :expr_endfn
2682
- assert_scanned("#foo\nfoo:",
2683
- :tNL, nil, [4, 5],
2684
- :tIDENTIFIER, 'foo', [5, 8],
2685
- :tCOLON, ':', [8, 9])
2686
-
2687
- @lex.state = :expr_endfn
2688
- assert_scanned("#foo\nfoo: ",
2689
- :tNL, nil, [4, 5],
2690
- :tIDENTIFIER, 'foo', [5, 8],
2691
- :tCOLON, ':', [8, 9])
2692
- end
2693
-
2694
- def test_whitespace_dot
2695
- @lex.state = :expr_dot
2696
- assert_scanned('class',
2697
- :tIDENTIFIER, 'class', [0, 5])
2698
-
2699
- @lex.state = :expr_dot
2700
- assert_scanned(' class',
2701
- :tIDENTIFIER, 'class', [1, 6])
2702
-
2703
- @lex.state = :expr_dot
2704
- assert_scanned("\nclass",
2705
- :tIDENTIFIER, 'class', [1, 6])
2706
-
2707
- @lex.state = :expr_dot
2708
- assert_scanned("\\\nclass",
2709
- :tIDENTIFIER, 'class', [2, 7])
2710
-
2711
- @lex.state = :expr_dot
2712
- assert_scanned("#foo\nclass",
2713
- :tIDENTIFIER, 'class', [5, 10])
2714
- end
2715
-
2716
- def test_whitespace_arg
2717
- @lex.state = :expr_arg
2718
- assert_scanned('+',
2719
- :tPLUS, '+', [0, 1])
2720
-
2721
- @lex.state = :expr_arg
2722
- assert_scanned(' +',
2723
- :tUPLUS, '+', [1, 2])
2724
-
2725
- @lex.state = :expr_arg
2726
- assert_scanned("\n+",
2727
- :tNL, nil, [0, 1],
2728
- :tUPLUS, '+', [1, 2])
2729
-
2730
- @lex.state = :expr_arg
2731
- assert_scanned("\\\n+",
2732
- :tUPLUS, '+', [2, 3])
2733
-
2734
- @lex.state = :expr_arg
2735
- assert_scanned("\\\n +",
2736
- :tUPLUS, '+', [3, 4])
2737
-
2738
- @lex.state = :expr_arg
2739
- assert_scanned("#foo\n+",
2740
- :tNL, nil, [4, 5],
2741
- :tUPLUS, '+', [5, 6])
2742
- end
2743
-
2744
- def test_whitespace_endarg
2745
- @lex.state = :expr_endarg
2746
- assert_scanned('{',
2747
- :tLBRACE_ARG, '{', [0, 1])
2748
-
2749
- @lex.state = :expr_endarg
2750
- assert_scanned(' {',
2751
- :tLBRACE_ARG, '{', [1, 2])
2752
-
2753
- @lex.state = :expr_endarg
2754
- assert_scanned("\n{",
2755
- :tNL, nil, [0, 1],
2756
- :tLBRACE, '{', [1, 2])
2757
-
2758
- @lex.state = :expr_endarg
2759
- assert_scanned("\\\n{",
2760
- :tLBRACE_ARG, '{', [2, 3])
2761
-
2762
- @lex.state = :expr_endarg
2763
- assert_scanned("#foo\n{",
2764
- :tNL, nil, [4, 5],
2765
- :tLBRACE, '{', [5, 6])
2766
- end
2767
-
2768
- def test_whitespace_mid
2769
- @lex.state = :expr_mid
2770
- assert_scanned('+',
2771
- :tUPLUS, '+', [0, 1])
2772
-
2773
- @lex.state = :expr_mid
2774
- assert_scanned(' +',
2775
- :tUPLUS, '+', [1, 2])
2776
-
2777
- @lex.state = :expr_mid
2778
- assert_scanned("\n+",
2779
- :tNL, nil, [0, 1],
2780
- :tUPLUS, '+', [1, 2])
2781
-
2782
- @lex.state = :expr_mid
2783
- assert_scanned("\\\n+",
2784
- :tUPLUS, '+', [2, 3])
2785
-
2786
- @lex.state = :expr_mid
2787
- assert_scanned("#foo\n+",
2788
- :tNL, nil, [4, 5],
2789
- :tUPLUS, '+', [5, 6])
2790
- end
2791
-
2792
- def test_whitespace_beg
2793
- @lex.state = :expr_beg
2794
- assert_scanned('+',
2795
- :tUPLUS, '+', [0, 1])
2796
-
2797
- @lex.state = :expr_beg
2798
- assert_scanned(' +',
2799
- :tUPLUS, '+', [1, 2])
2800
-
2801
- @lex.state = :expr_beg
2802
- assert_scanned("\n+",
2803
- :tUPLUS, '+', [1, 2])
2804
-
2805
- @lex.state = :expr_beg
2806
- assert_scanned("\\\n+",
2807
- :tUPLUS, '+', [2, 3])
2808
-
2809
- @lex.state = :expr_beg
2810
- assert_scanned("#foo\n+",
2811
- :tUPLUS, '+', [5, 6])
2812
- end
2813
-
2814
- def test_whitespace_value
2815
- setup_lexer(20)
2816
-
2817
- @lex.state = :expr_value
2818
- assert_scanned('a:b',
2819
- :tIDENTIFIER, 'a', [0, 1],
2820
- :tSYMBOL, 'b', [1, 3])
2821
-
2822
- @lex.state = :expr_value
2823
- assert_scanned(' a:b',
2824
- :tIDENTIFIER, 'a', [1, 2],
2825
- :tSYMBOL, 'b', [2, 4])
2826
-
2827
- @lex.state = :expr_value
2828
- assert_scanned("\na:b",
2829
- :tIDENTIFIER, 'a', [1, 2],
2830
- :tSYMBOL, 'b', [2, 4])
2831
-
2832
- @lex.state = :expr_value
2833
- assert_scanned("\\\na:b",
2834
- :tIDENTIFIER, 'a', [2, 3],
2835
- :tSYMBOL, 'b', [3, 5])
2836
-
2837
- @lex.state = :expr_value
2838
- assert_scanned("#foo\na:b",
2839
- :tIDENTIFIER, 'a', [5, 6],
2840
- :tSYMBOL, 'b', [6, 8])
2841
- end
2842
-
2843
- def test_whitespace_end
2844
- @lex.state = :expr_end
2845
- assert_scanned('+ 1',
2846
- :tPLUS, '+', [0, 1],
2847
- :tINTEGER, 1, [2, 3])
2848
-
2849
- @lex.state = :expr_end
2850
- assert_scanned(' + 1',
2851
- :tPLUS, '+', [1, 2],
2852
- :tINTEGER, 1, [3, 4])
2853
-
2854
- @lex.state = :expr_end
2855
- assert_scanned("\n+ 1",
2856
- :tNL, nil, [0, 1],
2857
- :tUNARY_NUM, '+', [1, 2],
2858
- :tINTEGER, 1, [3, 4])
2859
-
2860
- @lex.state = :expr_end
2861
- assert_scanned("\\\n+ 1",
2862
- :tPLUS, '+', [2, 3],
2863
- :tINTEGER, 1, [4, 5])
2864
-
2865
- @lex.state = :expr_end
2866
- assert_scanned("#foo\n+ 1",
2867
- :tNL, nil, [4, 5],
2868
- :tUNARY_NUM, '+', [5, 6],
2869
- :tINTEGER, 1, [7, 8])
2870
- end
2871
-
2872
- def test_whitespace_cr
2873
- setup_lexer(20)
2874
- assert_scanned("<<E\nfoo\nE\rO",
2875
- :tSTRING_BEG, '<<"', [0, 3],
2876
- :tSTRING_CONTENT, "foo\n", [4, 8],
2877
- :tSTRING_END, 'E', [8, 11],
2878
- :tNL, nil, [3, 4])
2879
-
2880
- setup_lexer(21)
2881
- refute_scanned("<<E\nfoo\nE\rO",
2882
- :tSTRING_BEG, '<<"', [0, 3],
2883
- :tSTRING_CONTENT, "foo\n", [4, 8])
2884
- end
2885
-
2886
- #
2887
- # Handling of encoding-related issues.
2888
- #
2889
-
2890
- def test_transcoded_source_is_converted_back_to_original_encoding
2891
- setup_lexer(19)
2892
- @lex.force_utf32 = true
2893
- @lex.tokens = []
2894
- assert_scanned(utf('"a" + "b"'),
2895
- :tSTRING, "a", [0, 3],
2896
- :tPLUS, "+", [4, 5],
2897
- :tSTRING, "b", [6, 9])
2898
-
2899
- @lex.tokens.each do |_type, (str, _range)|
2900
- assert_equal Encoding::UTF_8, str.encoding
2901
- end
2902
- end
2903
-
2904
- #
2905
- # Tests for bugs.
2906
- #
2907
- # These tests should be moved from nursery and properly
2908
- # categorized when it's clear how to do that.
2909
- #
2910
-
2911
- def test_bug_sclass_joined
2912
- assert_scanned("class<<self",
2913
- :kCLASS, "class", [0, 5],
2914
- :tLSHFT, "<<", [5, 7],
2915
- :kSELF, "self", [7, 11])
2916
- end
2917
-
2918
- def test_bug_const_expr_end
2919
- assert_scanned("Option",
2920
- :tCONSTANT, 'Option', [0, 6])
2921
-
2922
- assert_equal :expr_cmdarg, @lex.state
2923
- end
2924
-
2925
- def test_bug_expr_beg_div
2926
- @lex.state = :expr_beg
2927
- assert_scanned("/=/",
2928
- :tREGEXP_BEG, "/", [0, 1],
2929
- :tSTRING_CONTENT, "=", [1, 2],
2930
- :tSTRING_END, "/", [2, 3],
2931
- :tREGEXP_OPT, "", [3, 3])
2932
-
2933
- @lex.state = :expr_beg
2934
- assert_scanned("/ = /",
2935
- :tREGEXP_BEG, "/", [0, 1],
2936
- :tSTRING_CONTENT, " = ", [1, 4],
2937
- :tSTRING_END, "/", [4, 5],
2938
- :tREGEXP_OPT, "", [5, 5])
2939
- end
2940
-
2941
- def test_bug_expr_beg_percent
2942
- @lex.state = :expr_beg
2943
- assert_scanned("%=foo=",
2944
- :tSTRING_BEG, "%=", [0, 2],
2945
- :tSTRING_CONTENT, 'foo', [2, 5],
2946
- :tSTRING_END, "=", [5, 6])
2947
-
2948
- @lex.state = :expr_beg
2949
- assert_scanned("% = ",
2950
- :tSTRING_BEG, "% ", [0, 2],
2951
- :tSTRING_CONTENT, '=', [2, 3],
2952
- :tSTRING_END, ' ', [3, 4])
2953
- end
2954
-
2955
- def test_bug_expr_beg_document
2956
- @lex.state = :expr_beg
2957
- assert_scanned(" \n=begin\n=end\nend",
2958
- :kEND, "end", [14, 17])
2959
-
2960
- end
2961
-
2962
- def test_bug_expr_beg_number
2963
- @lex.state = :expr_beg
2964
- assert_scanned("86400_000_000",
2965
- :tINTEGER, 86400_000_000, [0, 13])
2966
- end
2967
-
2968
- def test_bug_expr_beg_backspace_nl
2969
- @lex.state = :expr_beg
2970
- assert_scanned("\n/foo/",
2971
- :tREGEXP_BEG, "/", [1, 2],
2972
- :tSTRING_CONTENT, "foo", [2, 5],
2973
- :tSTRING_END, "/", [5, 6],
2974
- :tREGEXP_OPT, "", [6, 6])
2975
- end
2976
-
2977
- def test_bug_expr_beg_heredoc
2978
- assert_scanned("<<EOL % [\nfoo\nEOL\n]",
2979
- :tSTRING_BEG, '<<"', [0, 5],
2980
- :tSTRING_CONTENT, "foo\n", [10, 14],
2981
- :tSTRING_END, 'EOL', [14, 17],
2982
- :tPERCENT, '%', [6, 7],
2983
- :tLBRACK, '[', [8, 9],
2984
- :tRBRACK, ']', [18, 19])
2985
- end
2986
-
2987
- def test_bug_expr_beg_fid
2988
- assert_scanned("Rainbows!",
2989
- :tFID, 'Rainbows!', [0, 9])
2990
- end
2991
-
2992
- def test_bug_expr_beg_rescue_assoc
2993
- assert_scanned("rescue=>",
2994
- :kRESCUE, 'rescue', [0, 6],
2995
- :tASSOC, '=>', [6, 8])
2996
- end
2997
-
2998
- def test_bug_expr_arg_percent
2999
- @lex.state = :expr_arg
3000
- assert_scanned("%[",
3001
- :tPERCENT, "%", [0, 1],
3002
- :tLBRACK, "[", [1, 2])
3003
-
3004
- @lex.state = :expr_arg
3005
- assert_scanned("%=1",
3006
- :tOP_ASGN, "%", [0, 2],
3007
- :tINTEGER, 1, [2, 3])
3008
-
3009
- @lex.state = :expr_arg
3010
- assert_scanned(" %[1]",
3011
- :tSTRING_BEG, "%[", [1, 3],
3012
- :tSTRING_CONTENT, '1', [3, 4],
3013
- :tSTRING_END, ']', [4, 5])
3014
-
3015
- @lex.state = :expr_arg
3016
- assert_scanned(" %=1=",
3017
- :tOP_ASGN, "%", [1, 3],
3018
- :tINTEGER, 1, [3, 4],
3019
- :tEQL, "=", [4, 5])
3020
-
3021
- @lex.state = :expr_arg
3022
- assert_scanned(" %\n",
3023
- :tPERCENT, '%', [1, 2])
3024
- end
3025
-
3026
- def test_bug_expr_arg_lt_lt
3027
- @lex.state = :expr_arg
3028
- assert_scanned("<<EOS\nEOS",
3029
- :tLSHFT, "<<", [0, 2],
3030
- :tCONSTANT, "EOS", [2, 5],
3031
- :tNL, nil, [5, 6],
3032
- :tCONSTANT, "EOS", [6, 9])
3033
-
3034
- @lex.state = :expr_arg
3035
- assert_scanned(" <<EOS\nEOS",
3036
- :tSTRING_BEG, "<<\"", [1, 6],
3037
- :tSTRING_END, "EOS", [7, 10],
3038
- :tNL, nil, [6, 7])
3039
- end
3040
-
3041
- def test_bug_expr_arg_slash
3042
- @lex.state = :expr_arg
3043
- assert_scanned("/1",
3044
- :tDIVIDE, "/", [0, 1],
3045
- :tINTEGER, 1, [1, 2])
3046
-
3047
- @lex.state = :expr_arg
3048
- assert_scanned("/ 1",
3049
- :tDIVIDE, "/", [0, 1],
3050
- :tINTEGER, 1, [2, 3])
3051
-
3052
- @lex.state = :expr_arg
3053
- assert_scanned(" /1/",
3054
- :tREGEXP_BEG, "/", [1, 2],
3055
- :tSTRING_CONTENT, "1", [2, 3],
3056
- :tSTRING_END, "/", [3, 4],
3057
- :tREGEXP_OPT, "", [4, 4])
3058
-
3059
- @lex.state = :expr_arg
3060
- assert_scanned(" / 1",
3061
- :tDIVIDE, "/", [1, 2],
3062
- :tINTEGER, 1, [3, 4])
3063
- end
3064
-
3065
- def test_bug_expr_arg_label
3066
- setup_lexer 19
3067
-
3068
- @lex.state = :expr_arg
3069
- assert_scanned(" unless:",
3070
- :tLABEL, 'unless', [1, 8])
3071
-
3072
- @lex.state = :expr_arg
3073
- assert_scanned(" unless: ",
3074
- :tLABEL, 'unless', [1, 8])
3075
- end
3076
-
3077
- def test_bug_heredoc_continuation
3078
- @lex.state = :expr_arg
3079
- assert_scanned(" <<EOS\nEOS\nend",
3080
- :tSTRING_BEG, "<<\"", [1, 6],
3081
- :tSTRING_END, "EOS", [7, 10],
3082
- :tNL, nil, [6, 7],
3083
- :kEND, "end", [11, 14])
3084
- end
3085
-
3086
- def test_bug_heredoc_cr_lf
3087
- assert_scanned("<<FIN\r\nfoo\r\nFIN\r\n",
3088
- :tSTRING_BEG, "<<\"", [0, 5],
3089
- :tSTRING_CONTENT, "foo\n", [6, 10],
3090
- :tSTRING_END, "FIN", [10, 13],
3091
- :tNL, nil, [5, 6])
3092
- end
3093
-
3094
- def test_bug_eh_symbol_no_newline
3095
- assert_scanned("?\"\nfoo",
3096
- :tINTEGER, 34, [0, 2],
3097
- :tNL, nil, [2, 3],
3098
- :tIDENTIFIER, "foo", [3, 6])
3099
- end
3100
-
3101
- def test_bug_expr_arg_newline
3102
- @lex.state = :expr_arg
3103
- assert_scanned("\nfoo",
3104
- :tNL, nil, [0, 1],
3105
- :tIDENTIFIER, "foo", [1, 4])
3106
-
3107
- @lex.state = :expr_arg
3108
- assert_scanned(" \nfoo",
3109
- :tNL, nil, [1, 2],
3110
- :tIDENTIFIER, "foo", [2, 5])
3111
-
3112
- @lex.state = :expr_arg
3113
- assert_scanned("#foo\nfoo",
3114
- :tNL, nil, [4, 5],
3115
- :tIDENTIFIER, "foo", [5, 8])
3116
- end
3117
-
3118
- def test_bug_expr_arg_comment_newline
3119
- @lex.state = :expr_arg
3120
- assert_scanned(" #\nfoo",
3121
- :tNL, nil, [2, 3],
3122
- :tIDENTIFIER, 'foo', [3, 6])
3123
- end
3124
-
3125
- def test_bug_expr_arg_eh_crlf
3126
- @lex.state = :expr_arg
3127
- assert_scanned(" ?\r\n",
3128
- :tEH, '?', [1, 2])
3129
- end
3130
-
3131
- def test_bug_heredoc_backspace_nl
3132
- assert_scanned(" <<'XXX'\nf \\\nXXX\n",
3133
- :tSTRING_BEG, "<<'", [1, 8],
3134
- :tSTRING_CONTENT, "f \\\n", [9, 13],
3135
- :tSTRING_END, "XXX", [13, 16],
3136
- :tNL, nil, [8, 9])
3137
- end
3138
-
3139
- def test_bug_heredoc_lshft
3140
- assert_scanned("<<RULES << CLEANINGS\nRULES",
3141
- :tSTRING_BEG, '<<"', [0, 7],
3142
- :tSTRING_END, 'RULES', [21, 26],
3143
- :tLSHFT, '<<', [8, 10],
3144
- :tCONSTANT, 'CLEANINGS', [11, 20])
3145
- end
3146
-
3147
- def test_bug_sclass_comment_lshft_label
3148
- assert_scanned("class # foo\n<< a:b;end",
3149
- :kCLASS, 'class', [0, 5],
3150
- :tLSHFT, '<<', [12, 14],
3151
- :tIDENTIFIER, 'a', [15, 16],
3152
- :tSYMBOL, 'b', [16, 18],
3153
- :tSEMI, ';', [18, 19],
3154
- :kEND, 'end', [19, 22])
3155
- end
3156
-
3157
- def test_bug_expr_dot_comment
3158
- assert_scanned("foo. #bar\nbaz",
3159
- :tIDENTIFIER, 'foo', [0, 3],
3160
- :tDOT, '.', [3, 4],
3161
- :tIDENTIFIER, 'baz', [10, 13])
3162
- end
3163
-
3164
- def test_bug_expr_dot_fid
3165
- assert_scanned("foo.S?",
3166
- :tIDENTIFIER, 'foo', [0, 3],
3167
- :tDOT, '.', [3, 4],
3168
- :tFID, 'S?', [4, 6])
3169
- end
3170
-
3171
- def test_bug_expr_dot_id_eq
3172
- assert_scanned("foo.x= 1",
3173
- :tIDENTIFIER, 'foo', [0, 3],
3174
- :tDOT, '.', [3, 4],
3175
- :tIDENTIFIER, 'x', [4, 5],
3176
- :tEQL, '=', [5, 6],
3177
- :tINTEGER, 1, [7, 8])
3178
- end
3179
-
3180
- def test_bug_expr_dot_fid_mod
3181
- assert_scanned("foo.x!if 1",
3182
- :tIDENTIFIER, 'foo', [0, 3],
3183
- :tDOT, '.', [3, 4],
3184
- :tFID, 'x!', [4, 6],
3185
- :kIF_MOD, 'if', [6, 8],
3186
- :tINTEGER, 1, [9, 10])
3187
- end
3188
-
3189
- def test_bug_expr_mid_comment
3190
- assert_scanned("rescue #bar\nprint",
3191
- :kRESCUE, 'rescue', [0, 6],
3192
- :tNL, nil, [11, 12],
3193
- :tIDENTIFIER, 'print', [12, 17])
3194
- end
3195
-
3196
- def test_bug_expr_mid_bareword
3197
- assert_scanned("begin; rescue rescue1",
3198
- :kBEGIN, 'begin', [0, 5],
3199
- :tSEMI, ';', [5, 6],
3200
- :kRESCUE, 'rescue', [7, 13],
3201
- :tIDENTIFIER, 'rescue1', [14, 21])
3202
- end
3203
-
3204
- def test_bug_expr_value_document
3205
- assert_scanned("1;\n=begin\n=end",
3206
- :tINTEGER, 1, [0, 1],
3207
- :tSEMI, ';', [1, 2])
3208
- end
3209
-
3210
- def test_bug_expr_end_colon
3211
- assert_scanned("'foo':'bar'",
3212
- :tSTRING, 'foo', [0, 5],
3213
- :tCOLON, ':', [5, 6],
3214
- :tSTRING, 'bar', [6, 11])
3215
- end
3216
-
3217
- def test_bug_expr_value_rescue_colon2
3218
- @lex.state = :expr_value
3219
- assert_scanned("rescue::Exception",
3220
- :kRESCUE, 'rescue', [0, 6],
3221
- :tCOLON3, '::', [6, 8],
3222
- :tCONSTANT, 'Exception', [8, 17])
3223
- end
3224
-
3225
- def test_bug_expr_endarg_braces
3226
- assert_scanned("let [] {",
3227
- :tIDENTIFIER, 'let', [0, 3],
3228
- :tLBRACK, '[', [4, 5],
3229
- :tRBRACK, ']', [5, 6],
3230
- :tLBRACE_ARG, '{', [7, 8])
3231
- end
3232
-
3233
- def test_bug_line_begin_label
3234
- setup_lexer(19)
3235
- assert_scanned("foo:bar",
3236
- :tIDENTIFIER, 'foo', [0, 3],
3237
- :tSYMBOL, 'bar', [3, 7])
3238
- end
3239
-
3240
- def test_bug_interp_expr_value
3241
- assert_scanned('"#{f:a}"',
3242
- :tSTRING_BEG, '"', [0, 1],
3243
- :tSTRING_DBEG, '#{', [1, 3],
3244
- :tIDENTIFIER, 'f', [3, 4],
3245
- :tSYMBOL, 'a', [4, 6],
3246
- :tRCURLY, '}', [6, 7],
3247
- :tSTRING_END, '"', [7, 8])
3248
- end
3249
-
3250
- def test_bug_const_e
3251
- assert_scanned('E10',
3252
- :tCONSTANT, 'E10', [0, 3])
3253
- assert_scanned('E4U',
3254
- :tCONSTANT, 'E4U', [0, 3])
3255
- end
3256
-
3257
- def test_bug_symbol_newline
3258
- assert_scanned(":foo\n",
3259
- :tSYMBOL, 'foo', [0, 4],
3260
- :tNL, nil, [4, 5])
3261
-
3262
- assert_scanned(":foo=\n",
3263
- :tSYMBOL, 'foo=', [0, 5],
3264
- :tNL, nil, [5, 6])
3265
- end
3266
-
3267
- def test_bug_interleaved_heredoc
3268
- assert_scanned(%Q{<<w; "\nfoo\nw\n"},
3269
- :tSTRING_BEG, '<<"', [0, 3],
3270
- :tSTRING_CONTENT, "foo\n", [7, 11],
3271
- :tSTRING_END, 'w', [11, 12],
3272
- :tSEMI, ';', [3, 4],
3273
- :tSTRING_BEG, '"', [5, 6],
3274
- :tSTRING_CONTENT, "\n", [6, 7],
3275
- :tSTRING_END, '"', [13, 14])
3276
-
3277
- @lex.state = :expr_beg
3278
- assert_scanned(%Q{<<w; %w[\nfoo\nw\n1]},
3279
- :tSTRING_BEG, '<<"', [0, 3],
3280
- :tSTRING_CONTENT, "foo\n", [9, 13],
3281
- :tSTRING_END, 'w', [13, 14],
3282
- :tSEMI, ';', [3, 4],
3283
- :tQWORDS_BEG, '%w[', [5, 8],
3284
- :tSTRING_CONTENT, "1", [15, 16],
3285
- :tSPACE, nil, [16, 16],
3286
- :tSTRING_END, ']', [16, 17])
3287
-
3288
- @lex.state = :expr_beg
3289
- assert_scanned(%Q{<<w; "\#{\nfoo\nw\n}"},
3290
- :tSTRING_BEG, '<<"', [0, 3],
3291
- :tSTRING_CONTENT, "foo\n", [9, 13],
3292
- :tSTRING_END, 'w', [13, 14],
3293
- :tSEMI, ';', [3, 4],
3294
- :tSTRING_BEG, '"', [5, 6],
3295
- :tSTRING_DBEG, '#{', [6, 8],
3296
- :tRCURLY, '}', [15, 16],
3297
- :tSTRING_END, '"', [16, 17])
3298
- end
3299
-
3300
- def test_bug_fid_char
3301
- setup_lexer(19)
3302
- assert_scanned('eof??a',
3303
- :tFID, 'eof?', [0, 4],
3304
- :tCHARACTER, 'a', [4, 6])
3305
- end
3306
-
3307
- def test_bug_nonlabel_context__18
3308
- env = Parser::StaticEnvironment.new
3309
- env.declare "a"
3310
-
3311
- @lex.static_env = env
3312
- assert_scanned("1+a:a",
3313
- :tINTEGER, 1, [0, 1],
3314
- :tPLUS, '+', [1, 2],
3315
- :tIDENTIFIER, 'a', [2, 3],
3316
- :tCOLON, ':', [3, 4],
3317
- :tIDENTIFIER, 'a', [4, 5])
3318
- end
3319
-
3320
- def test_bug_string_percent_newline
3321
- assert_scanned(%Q{%\nfoo\n},
3322
- :tSTRING_BEG, "%\n", [0, 2],
3323
- :tSTRING_CONTENT, 'foo', [2, 5],
3324
- :tSTRING_END, "\n", [5, 6])
3325
- end
3326
-
3327
- def test_bug_string_percent_zero
3328
- assert_scanned(%Q{%\0foo\0},
3329
- :tSTRING_BEG, "%\0", [0, 2],
3330
- :tSTRING_CONTENT, 'foo', [2, 5],
3331
- :tSTRING_END, "\0", [5, 6])
3332
- end
3333
-
3334
- def test_bug_string_utf_escape_composition
3335
- assert_scanned(%q{"\xE2\x80\x99"},
3336
- :tSTRING, "\xE2\x80\x99", [0, 14])
3337
-
3338
- assert_scanned(utf(%q{"\xE2\x80\x99"}),
3339
- :tSTRING, utf('’'), [0, 14])
3340
- assert_scanned(utf(%q{"\342\200\231"}),
3341
- :tSTRING, utf('’'), [0, 14])
3342
- assert_scanned(utf(%q{"\M-b\C-\M-@\C-\M-Y"}),
3343
- :tSTRING, utf('’'), [0, 20])
3344
- end
3345
-
3346
- def test_bug_string_utf_escape_noop
3347
- assert_scanned(utf(%q{"\あ"}),
3348
- :tSTRING, utf("あ"), [0, 4])
3349
- end
3350
-
3351
- def test_bug_string_non_utf
3352
- assert_scanned(%Q{"caf\xE9"},
3353
- :tSTRING, "caf\xE9", [0, 6])
3354
- assert_scanned(%Q{"caf\xC3\xA9"},
3355
- :tSTRING, "caf\xC3\xA9", [0, 7])
3356
-
3357
- assert_scanned(utf(%q{"café"}),
3358
- :tSTRING, utf("café"), [0, 6])
3359
- end
3360
-
3361
- def test_bug_semi__END__
3362
- assert_scanned(%Q{foo;\n__END__},
3363
- :tIDENTIFIER, 'foo', [0, 3],
3364
- :tSEMI, ';', [3, 4])
3365
- end
3366
-
3367
- def test_bug_eql_end
3368
- assert_scanned(%Q{=begin\n#=end\n=end})
3369
- end
3370
-
3371
- def test_bug_hidden_eof
3372
- @lex.state = :expr_beg
3373
- assert_scanned(%Q{"foo\0\x1a\x04bar"},
3374
- :tSTRING_BEG, '"', [0, 1],
3375
- :tSTRING_CONTENT, "foo\0", [1, 5],
3376
- :tSTRING_CONTENT, "\x1a", [5, 6],
3377
- :tSTRING_CONTENT, "\x04", [6, 7],
3378
- :tSTRING_CONTENT, "bar", [7, 10],
3379
- :tSTRING_END, '"', [10, 11])
3380
-
3381
- @lex.state = :expr_beg
3382
- assert_scanned(%Q{'foo\0\x1a\x04bar'},
3383
- :tSTRING_BEG, "'", [0, 1],
3384
- :tSTRING_CONTENT, "foo\0", [1, 5],
3385
- :tSTRING_CONTENT, "\x1a", [5, 6],
3386
- :tSTRING_CONTENT, "\x04", [6, 7],
3387
- :tSTRING_CONTENT, "bar", [7, 10],
3388
- :tSTRING_END, "'", [10, 11])
3389
-
3390
- @lex.state = :expr_beg
3391
- assert_scanned(%Q{%w[foo\0\x1a\x04bar]},
3392
- :tQWORDS_BEG, '%w[', [0, 3],
3393
- :tSTRING_CONTENT, "foo\0", [3, 7],
3394
- :tSTRING_CONTENT, "\x1a", [7, 8],
3395
- :tSTRING_CONTENT, "\x04", [8, 9],
3396
- :tSTRING_CONTENT, "bar", [9, 12],
3397
- :tSPACE, nil, [12, 12],
3398
- :tSTRING_END, ']', [12, 13])
3399
-
3400
- @lex.state = :expr_beg
3401
- assert_scanned(%Q{%W[foo\0\x1a\x04bar]},
3402
- :tWORDS_BEG, '%W[', [0, 3],
3403
- :tSTRING_CONTENT, "foo\0", [3, 7],
3404
- :tSTRING_CONTENT, "\x1a", [7, 8],
3405
- :tSTRING_CONTENT, "\x04", [8, 9],
3406
- :tSTRING_CONTENT, "bar", [9, 12],
3407
- :tSPACE, nil, [12, 12],
3408
- :tSTRING_END, ']', [12, 13])
3409
-
3410
- @lex.state = :expr_beg
3411
- assert_scanned(%Q{# foo\0\nbar},
3412
- :tIDENTIFIER, 'bar', [7, 10])
3413
-
3414
- @lex.state = :line_begin
3415
- assert_scanned(%Q{=begin\n\0\n=end\nbar},
3416
- :tIDENTIFIER, 'bar', [14, 17])
3417
- end
3418
-
3419
- def test_bug_num_adj_kw
3420
- assert_scanned('1if',
3421
- :tINTEGER, 1, [0, 1],
3422
- :kIF_MOD, 'if', [1, 3])
3423
-
3424
- assert_scanned('1.0if',
3425
- :tFLOAT, 1.0, [0, 3],
3426
- :kIF_MOD, 'if', [3, 5])
3427
- end
3428
-
3429
- def test_bug_unicode_in_literal
3430
- setup_lexer(19)
3431
- assert_scanned('"\u00a4"',
3432
- :tSTRING, "\u00a4", [0, 8])
3433
- end
3434
-
3435
- def test_bug_utf32le_leak
3436
- setup_lexer(19)
3437
- @lex.force_utf32 = true
3438
- assert_scanned('"F0"',
3439
- :tSTRING, "F0", [0, 4])
3440
- end
3441
-
3442
- def test_bug_ragel_stack
3443
- assert_scanned("\"\#{$2 ? $2 : 1}\"",
3444
- :tSTRING_BEG, "\"", [0, 1],
3445
- :tSTRING_DBEG, "\#{", [1, 3],
3446
- :tNTH_REF, 2, [3, 5],
3447
- :tEH, "?", [6, 7],
3448
- :tNTH_REF, 2, [8, 10],
3449
- :tCOLON, ":", [11, 12],
3450
- :tINTEGER, 1, [13, 14],
3451
- :tRCURLY, "}", [14, 15],
3452
- :tSTRING_END, "\"", [15, 16])
3453
- end
3454
-
3455
- def test_bug_423
3456
- @lex.state = :expr_beg
3457
- assert_scanned(':&&',
3458
- :tSYMBEG, ':', [0, 1],
3459
- :tANDOP, '&&', [1, 3])
3460
-
3461
- @lex.state = :expr_beg
3462
- assert_scanned(':||',
3463
- :tSYMBEG, ':', [0, 1],
3464
- :tOROP, '||', [1, 3])
3465
- end
3466
-
3467
- def test_bug_418
3468
- setup_lexer 19
3469
-
3470
- assert_scanned("{\n=begin\nx: 1,\n=end\ny: 2}",
3471
- :tLBRACE, '{', [0, 1],
3472
- :tLABEL, 'y', [20, 22],
3473
- :tINTEGER, 2, [23, 24],
3474
- :tRCURLY, '}', [24, 25])
3475
- end
3476
-
3477
- def test_bug_407
3478
- setup_lexer(21)
3479
-
3480
- assert_scanned('123if cond',
3481
- :tINTEGER, 123, [0, 3],
3482
- :kIF_MOD, 'if', [3, 5],
3483
- :tIDENTIFIER, 'cond', [6, 10])
3484
-
3485
- assert_scanned('1.23if cond',
3486
- :tFLOAT, 1.23, [0, 4],
3487
- :kIF_MOD, 'if', [4, 6],
3488
- :tIDENTIFIER, 'cond', [7, 11])
3489
-
3490
- assert_scanned('123rescue cond',
3491
- :tINTEGER, 123, [0, 3],
3492
- :kRESCUE_MOD, 'rescue', [3, 9],
3493
- :tIDENTIFIER, 'cond', [10, 14])
3494
-
3495
- assert_scanned('1.23rescue cond',
3496
- :tFLOAT, 1.23, [0, 4],
3497
- :kRESCUE_MOD, 'rescue', [4, 10],
3498
- :tIDENTIFIER, 'cond', [11, 15])
3499
- end
3500
-
3501
- def test_parser_bug_486
3502
- setup_lexer(19)
3503
- assert_scanned(':!@',
3504
- :tSYMBOL, '!', [0, 3])
3505
-
3506
- setup_lexer(19)
3507
- assert_scanned(':~@',
3508
- :tSYMBOL, '~', [0, 3])
3509
- end
3510
-
3511
- def test_slash_only_in_heredocs
3512
- setup_lexer(23)
3513
- refute_scanned(%Q{<<~E\n\\\nE})
3514
-
3515
- setup_lexer(23)
3516
- refute_scanned(%Q{<<-E\n\\\nE})
3517
- end
3518
-
3519
- def test_escapes_in_squiggly_heredoc
3520
- setup_lexer(23)
3521
-
3522
- assert_scanned(%Q{<<~E\n\a\b\e\f\r\t\\\v\nE},
3523
- :tSTRING_BEG, '<<"', [0, 4],
3524
- :tSTRING_CONTENT, "\a\b\e\f\r\t\v\n", [5, 14],
3525
- :tSTRING_END, 'E', [14, 15],
3526
- :tNL, nil, [4, 5])
3527
-
3528
- setup_lexer(23)
3529
-
3530
- assert_scanned(%Q{<<-E\n\a\b\e\f\r\t\\\v\nE},
3531
- :tSTRING_BEG, '<<"', [0, 4],
3532
- :tSTRING_CONTENT, "\a\b\e\f\r\t\v\n", [5, 14],
3533
- :tSTRING_END, 'E', [14, 15],
3534
- :tNL, nil, [4, 5])
3535
- end
3536
-
3537
- def test_ambiguous_integer_re
3538
- assert_scanned('1re',
3539
- :tINTEGER, 1, [0, 1],
3540
- :tIDENTIFIER, 're', [1, 3])
3541
- end
3542
-
3543
- end