rb-ruby_parser 2.0.4.1

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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Ray Baxter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ = rb-ruby_parser
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2009 Ray Baxter. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rb-ruby_parser"
8
+ gem.summary = %Q{Fork of ParseTree/ruby_parser}
9
+ gem.description = %Q{This version respects text after block comment =end}
10
+ gem.email = "ray.baxter@gmail.com"
11
+ gem.homepage = "http://github.com/raybaxter/rb-ruby_parser"
12
+ gem.authors = ["Ray Baxter"]
13
+ gem.add_development_dependency "minitest", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rb-ruby_parser #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
File without changes
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'minitest/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'rb-ruby_parser'
7
+
8
+ class MiniTest::Unit::TestCase
9
+ end
10
+
11
+ MiniTest::Unit.autorun
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRbRubyParser < MiniTest::Unit::TestCase
4
+ def test_something_for_real
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,1829 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'minitest/autorun'
5
+ require 'ruby_lexer'
6
+ require 'ruby_parser'
7
+
8
+ class TestRubyLexer < MiniTest::Unit::TestCase
9
+ alias :deny :refute
10
+
11
+ def setup
12
+ p = RubyParser.new
13
+ @lex = p.lexer
14
+ @lex.src = "blah blah"
15
+ @lex.lex_state = :expr_beg
16
+ end
17
+
18
+ def test_advance
19
+ assert @lex.advance # blah
20
+ assert @lex.advance # blah
21
+ deny @lex.advance # nada
22
+ end
23
+
24
+ def test_read_escape
25
+ util_escape "\\", "\\"
26
+ util_escape "\n", "n"
27
+ util_escape "\t", "t"
28
+ util_escape "\r", "r"
29
+ util_escape "\f", "f"
30
+ util_escape "\13", "v"
31
+ util_escape "\0", "0"
32
+ util_escape "\07", "a"
33
+ util_escape "\007", "a"
34
+ util_escape "\033", "e"
35
+ util_escape "\377", "377"
36
+ util_escape "\377", "xff"
37
+ util_escape "\010", "b"
38
+ util_escape " ", "s"
39
+ util_escape "q", "q" # plain vanilla escape
40
+ end
41
+
42
+ def test_read_escape_c
43
+ util_escape "\030", "C-x"
44
+ util_escape "\030", "cx"
45
+ util_escape "\230", 'C-\M-x'
46
+ util_escape "\230", 'c\M-x'
47
+
48
+ util_escape "\177", "C-?"
49
+ util_escape "\177", "c?"
50
+ end
51
+
52
+ def test_read_escape_errors
53
+ util_escape_bad ""
54
+
55
+ util_escape_bad "M"
56
+ util_escape_bad "M-"
57
+ util_escape_bad "Mx"
58
+
59
+ util_escape_bad "Cx"
60
+ util_escape_bad "C"
61
+ util_escape_bad "C-"
62
+
63
+ util_escape_bad "c"
64
+ end
65
+
66
+ def test_read_escape_m
67
+ util_escape "\370", "M-x"
68
+ util_escape "\230", 'M-\C-x'
69
+ util_escape "\230", 'M-\cx'
70
+ end
71
+
72
+ def test_yylex_ambiguous_uminus
73
+ util_lex_token("m -3",
74
+ :tIDENTIFIER, "m",
75
+ :tUMINUS_NUM, "-",
76
+ :tINTEGER, 3)
77
+ # TODO: verify warning
78
+ end
79
+
80
+ def test_yylex_ambiguous_uplus
81
+ util_lex_token("m +3",
82
+ :tIDENTIFIER, "m",
83
+ :tINTEGER, 3)
84
+ # TODO: verify warning
85
+ end
86
+
87
+ def test_yylex_and
88
+ util_lex_token "&", :tAMPER, "&"
89
+ end
90
+
91
+ def test_yylex_and2
92
+ util_lex_token "&&", :tANDOP, "&&"
93
+ end
94
+
95
+ def test_yylex_and2_equals
96
+ util_lex_token "&&=", :tOP_ASGN, "&&"
97
+ end
98
+
99
+ def test_yylex_and_arg
100
+ @lex.lex_state = :expr_arg
101
+
102
+ util_lex_token(" &y",
103
+ :tAMPER, "&",
104
+ :tIDENTIFIER, "y")
105
+ end
106
+
107
+ def test_yylex_and_equals
108
+ util_lex_token "&=", :tOP_ASGN, "&"
109
+ end
110
+
111
+ def test_yylex_and_expr
112
+ @lex.lex_state = :expr_arg
113
+
114
+ util_lex_token("x & y",
115
+ :tIDENTIFIER, "x",
116
+ :tAMPER2, "&",
117
+ :tIDENTIFIER, "y")
118
+ end
119
+
120
+ def test_yylex_and_meth
121
+ util_lex_fname "&", :tAMPER2
122
+ end
123
+
124
+ def test_yylex_assoc
125
+ util_lex_token "=>", :tASSOC, "=>"
126
+ end
127
+
128
+ def test_yylex_back_ref
129
+ util_lex_token("[$&, $`, $', $+]",
130
+ :tLBRACK, "[",
131
+ :tBACK_REF, :"&", :tCOMMA, ",",
132
+ :tBACK_REF, :"`", :tCOMMA, ",",
133
+ :tBACK_REF, :"'", :tCOMMA, ",",
134
+ :tBACK_REF, :"+",
135
+ :tRBRACK, "]")
136
+ end
137
+
138
+ def test_yylex_backslash
139
+ util_lex_token("1 \\\n+ 2",
140
+ :tINTEGER, 1,
141
+ :tPLUS, "+",
142
+ :tINTEGER, 2)
143
+ end
144
+
145
+ def test_yylex_backslash_bad
146
+ util_bad_token("1 \\ + 2",
147
+ :tINTEGER, 1)
148
+ end
149
+
150
+ def test_yylex_backtick
151
+ util_lex_token("`ls`",
152
+ :tXSTRING_BEG, "`",
153
+ :tSTRING_CONTENT, "ls",
154
+ :tSTRING_END, "`")
155
+ end
156
+
157
+ def test_yylex_backtick_cmdarg
158
+ @lex.lex_state = :expr_dot
159
+ util_lex_token("\n`", :tBACK_REF2, "`") # \n ensures expr_cmd
160
+
161
+ assert_equal :expr_cmdarg, @lex.lex_state
162
+ end
163
+
164
+ def test_yylex_backtick_dot
165
+ @lex.lex_state = :expr_dot
166
+ util_lex_token("a.`(3)",
167
+ :tIDENTIFIER, "a",
168
+ :tDOT, ".",
169
+ :tBACK_REF2, "`",
170
+ :tLPAREN2, "(",
171
+ :tINTEGER, 3,
172
+ :tRPAREN, ")")
173
+ end
174
+
175
+ def test_yylex_backtick_method
176
+ @lex.lex_state = :expr_fname
177
+ util_lex_token("`", :tBACK_REF2, "`")
178
+ assert_equal :expr_end, @lex.lex_state
179
+ end
180
+
181
+ def test_yylex_bad_char
182
+ util_bad_token(" \010 ")
183
+ end
184
+
185
+ def test_yylex_bang
186
+ util_lex_token "!", :tBANG, "!"
187
+ end
188
+
189
+ def test_yylex_bang_equals
190
+ util_lex_token "!=", :tNEQ, "!="
191
+ end
192
+
193
+ def test_yylex_bang_tilde
194
+ util_lex_token "!~", :tNMATCH, "!~"
195
+ end
196
+
197
+ def test_yylex_carat
198
+ util_lex_token "^", :tCARET, "^"
199
+ end
200
+
201
+ def test_yylex_carat_equals
202
+ util_lex_token "^=", :tOP_ASGN, "^"
203
+ end
204
+
205
+ def test_yylex_colon2
206
+ util_lex_token("A::B",
207
+ :tCONSTANT, "A",
208
+ :tCOLON2, "::",
209
+ :tCONSTANT, "B")
210
+ end
211
+
212
+ def test_yylex_colon3
213
+ util_lex_token("::Array",
214
+ :tCOLON3, "::",
215
+ :tCONSTANT, "Array")
216
+ end
217
+
218
+ def test_yylex_comma
219
+ util_lex_token ",", :tCOMMA, ","
220
+ end
221
+
222
+ def test_yylex_comment
223
+ util_lex_token("1 # one\n# two\n2",
224
+ :tINTEGER, 1,
225
+ :tNL, nil,
226
+ :tINTEGER, 2)
227
+ assert_equal "# one\n# two\n", @lex.comments
228
+ end
229
+
230
+ def test_yylex_comment_begin
231
+ util_lex_token("=begin\nblah\nblah\n=end\n42",
232
+ :tINTEGER, 42)
233
+ assert_equal "=begin\nblah\nblah\n=end\n", @lex.comments
234
+ end
235
+
236
+ def test_yylex_comment_begin_bad
237
+ util_bad_token("=begin\nblah\nblah\n")
238
+ assert_equal "", @lex.comments
239
+ end
240
+
241
+ def test_yylex_comment_begin_not_comment
242
+ util_lex_token("beginfoo = 5\np x \\\n=beginfoo",
243
+ :tIDENTIFIER, "beginfoo",
244
+ :tEQL, "=",
245
+ :tINTEGER, 5,
246
+ :tNL, nil,
247
+ :tIDENTIFIER, "p",
248
+ :tIDENTIFIER, "x",
249
+ :tEQL, "=",
250
+ :tIDENTIFIER, "beginfoo")
251
+ end
252
+
253
+ def test_yylex_comment_begin_space
254
+ util_lex_token("=begin blah\nblah\n=end\n")
255
+ assert_equal "=begin blah\nblah\n=end\n", @lex.comments
256
+ end
257
+
258
+ def test_yylex_comment_end_space_and_text
259
+ util_lex_token("=begin blah\nblah\n=end blab\n")
260
+ assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments
261
+ end
262
+
263
+ def test_yylex_comment_eos
264
+ util_lex_token("# comment")
265
+ end
266
+
267
+ def test_yylex_constant
268
+ util_lex_token("ArgumentError",
269
+ :tCONSTANT, "ArgumentError")
270
+ end
271
+
272
+ def test_yylex_constant_semi
273
+ util_lex_token("ArgumentError;",
274
+ :tCONSTANT, "ArgumentError",
275
+ :tSEMI, ";")
276
+ end
277
+
278
+ def test_yylex_cvar
279
+ util_lex_token "@@blah", :tCVAR, "@@blah"
280
+ end
281
+
282
+ def test_yylex_cvar_bad
283
+ assert_raises SyntaxError do
284
+ util_lex_token "@@1"
285
+ end
286
+ end
287
+
288
+ def test_yylex_def_bad_name
289
+ @lex.lex_state = :expr_fname
290
+ util_bad_token("def [ ", :kDEF, "def")
291
+ end
292
+
293
+ def test_yylex_div
294
+ util_lex_token("a / 2",
295
+ :tIDENTIFIER, "a",
296
+ :tDIVIDE, "/",
297
+ :tINTEGER, 2)
298
+ end
299
+
300
+ def test_yylex_div_equals
301
+ util_lex_token("a /= 2",
302
+ :tIDENTIFIER, "a",
303
+ :tOP_ASGN, "/",
304
+ :tINTEGER, 2)
305
+ end
306
+
307
+ def test_yylex_do
308
+ util_lex_token("x do 42 end",
309
+ :tIDENTIFIER, "x",
310
+ :kDO, "do",
311
+ :tINTEGER, 42,
312
+ :kEND, "end")
313
+ end
314
+
315
+ def test_yylex_do_block
316
+ @lex.lex_state = :expr_endarg
317
+ @lex.cmdarg.push true
318
+
319
+ util_lex_token("x.y do 42 end",
320
+ :tIDENTIFIER, "x",
321
+ :tDOT, ".",
322
+ :tIDENTIFIER, "y",
323
+ :kDO_BLOCK, "do",
324
+ :tINTEGER, 42,
325
+ :kEND, "end")
326
+ end
327
+
328
+ def test_yylex_do_block2
329
+ @lex.lex_state = :expr_endarg
330
+
331
+ util_lex_token("do 42 end",
332
+ :kDO_BLOCK, "do",
333
+ :tINTEGER, 42,
334
+ :kEND, "end")
335
+ end
336
+
337
+ def test_yylex_do_cond
338
+ @lex.cond.push true
339
+
340
+ util_lex_token("x do 42 end",
341
+ :tIDENTIFIER, "x",
342
+ :kDO_COND, "do",
343
+ :tINTEGER, 42,
344
+ :kEND, "end")
345
+ end
346
+
347
+ def test_yylex_dollar
348
+ util_lex_token("$", "$", "$") # FIX: wtf is this?!?
349
+ end
350
+
351
+ def test_yylex_dot # HINT message sends
352
+ util_lex_token ".", :tDOT, "."
353
+ end
354
+
355
+ def test_yylex_dot2
356
+ util_lex_token "..", :tDOT2, ".."
357
+ end
358
+
359
+ def test_yylex_dot3
360
+ util_lex_token "...", :tDOT3, "..."
361
+ end
362
+
363
+ def test_yylex_equals
364
+ util_lex_token "=", :tEQL, "=" # FIX: this sucks
365
+ end
366
+
367
+ def test_yylex_equals2
368
+ util_lex_token "==", :tEQ, "=="
369
+ end
370
+
371
+ def test_yylex_equals3
372
+ util_lex_token "===", :tEQQ, "==="
373
+ end
374
+
375
+ def test_yylex_equals_tilde
376
+ util_lex_token "=~", :tMATCH, "=~"
377
+ end
378
+
379
+ def test_yylex_float
380
+ util_lex_token "1.0", :tFLOAT, 1.0
381
+ end
382
+
383
+ def test_yylex_float_bad_no_underscores
384
+ util_bad_token "1__0.0"
385
+ end
386
+
387
+ def test_yylex_float_bad_no_zero_leading
388
+ util_bad_token ".0"
389
+ end
390
+
391
+ def test_yylex_float_bad_trailing_underscore
392
+ util_bad_token "123_.0"
393
+ end
394
+
395
+ def test_yylex_float_call
396
+ util_lex_token("1.0.to_s",
397
+ :tFLOAT, 1.0,
398
+ :tDOT, ".",
399
+ :tIDENTIFIER, "to_s")
400
+ end
401
+
402
+ def test_yylex_float_dot_E
403
+ util_lex_token "1.0E10", :tFLOAT, 1.0e10
404
+ end
405
+
406
+ def test_yylex_float_dot_E_neg
407
+ util_lex_token("-1.0E10",
408
+ :tUMINUS_NUM, "-",
409
+ :tFLOAT, 1.0e10)
410
+ end
411
+
412
+ def test_yylex_float_dot_e
413
+ util_lex_token "1.0e10", :tFLOAT, 1.0e10
414
+ end
415
+
416
+ def test_yylex_float_dot_e_neg
417
+ util_lex_token("-1.0e10",
418
+ :tUMINUS_NUM, "-",
419
+ :tFLOAT, 1.0e10)
420
+ end
421
+
422
+ def test_yylex_float_e
423
+ util_lex_token "1e10", :tFLOAT, 1e10
424
+ end
425
+
426
+ def test_yylex_float_e_bad_double_e
427
+ util_bad_token "1e2e3"
428
+ end
429
+
430
+ def test_yylex_float_e_bad_trailing_underscore
431
+ util_bad_token "123_e10"
432
+ end
433
+
434
+ def test_yylex_float_e_minus
435
+ util_lex_token "1e-10", :tFLOAT, 1e-10
436
+ end
437
+
438
+ def test_yylex_float_e_neg
439
+ util_lex_token("-1e10",
440
+ :tUMINUS_NUM, "-",
441
+ :tFLOAT, 1e10)
442
+ end
443
+
444
+ def test_yylex_float_e_neg_minus
445
+ util_lex_token("-1e-10",
446
+ :tUMINUS_NUM, "-",
447
+ :tFLOAT, 1e-10)
448
+ end
449
+
450
+ def test_yylex_float_e_neg_plus
451
+ util_lex_token("-1e+10",
452
+ :tUMINUS_NUM, "-",
453
+ :tFLOAT, 1e10)
454
+ end
455
+
456
+ def test_yylex_float_e_plus
457
+ util_lex_token "1e+10", :tFLOAT, 1e10
458
+ end
459
+
460
+ def test_yylex_float_e_zero
461
+ util_lex_token "0e0", :tFLOAT, 0e0
462
+ end
463
+
464
+ def test_yylex_float_neg
465
+ util_lex_token("-1.0",
466
+ :tUMINUS_NUM, "-",
467
+ :tFLOAT, 1.0)
468
+ end
469
+
470
+ def test_yylex_ge
471
+ util_lex_token("a >= 2",
472
+ :tIDENTIFIER, "a",
473
+ :tGEQ, ">=",
474
+ :tINTEGER, 2)
475
+ end
476
+
477
+ def test_yylex_global
478
+ util_lex_token("$blah", :tGVAR, "$blah")
479
+ end
480
+
481
+ def test_yylex_global_backref
482
+ @lex.lex_state = :expr_fname
483
+ util_lex_token("$`", :tGVAR, "$`")
484
+ end
485
+
486
+ def test_yylex_global_dash_nothing
487
+ util_lex_token("$- ", :tGVAR, "$-")
488
+ end
489
+
490
+ def test_yylex_global_dash_something
491
+ util_lex_token("$-x", :tGVAR, "$-x")
492
+ end
493
+
494
+ def test_yylex_global_number
495
+ @lex.lex_state = :expr_fname
496
+ util_lex_token("$1", :tGVAR, "$1")
497
+ end
498
+
499
+ def test_yylex_global_number_big
500
+ @lex.lex_state = :expr_fname
501
+ util_lex_token("$1234", :tGVAR, "$1234")
502
+ end
503
+
504
+ def test_yylex_global_other
505
+ util_lex_token("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
506
+ :tLBRACK, "[",
507
+ :tGVAR, "$~", :tCOMMA, ",",
508
+ :tGVAR, "$*", :tCOMMA, ",",
509
+ :tGVAR, "$$", :tCOMMA, ",",
510
+ :tGVAR, "$\?", :tCOMMA, ",",
511
+ :tGVAR, "$!", :tCOMMA, ",",
512
+ :tGVAR, "$@", :tCOMMA, ",",
513
+ :tGVAR, "$/", :tCOMMA, ",",
514
+ :tGVAR, "$\\", :tCOMMA, ",",
515
+ :tGVAR, "$;", :tCOMMA, ",",
516
+ :tGVAR, "$,", :tCOMMA, ",",
517
+ :tGVAR, "$.", :tCOMMA, ",",
518
+ :tGVAR, "$=", :tCOMMA, ",",
519
+ :tGVAR, "$:", :tCOMMA, ",",
520
+ :tGVAR, "$<", :tCOMMA, ",",
521
+ :tGVAR, "$>", :tCOMMA, ",",
522
+ :tGVAR, "$\"",
523
+ :tRBRACK, "]")
524
+ end
525
+
526
+ def test_yylex_global_underscore
527
+ util_lex_token("$_",
528
+ :tGVAR, "$_")
529
+ end
530
+
531
+ def test_yylex_global_wierd
532
+ util_lex_token("$__blah",
533
+ :tGVAR, "$__blah")
534
+ end
535
+
536
+ def test_yylex_global_zero
537
+ util_lex_token("$0", :tGVAR, "$0")
538
+ end
539
+
540
+ def test_yylex_gt
541
+ util_lex_token("a > 2",
542
+ :tIDENTIFIER, "a",
543
+ :tGT, ">",
544
+ :tINTEGER, 2)
545
+ end
546
+
547
+ def test_yylex_heredoc_backtick
548
+ util_lex_token("a = <<`EOF`\n blah blah\nEOF\n",
549
+ :tIDENTIFIER, "a",
550
+ :tEQL, "=",
551
+ :tXSTRING_BEG, "`",
552
+ :tSTRING_CONTENT, " blah blah\n",
553
+ :tSTRING_END, "EOF",
554
+ :tNL, nil)
555
+ end
556
+
557
+ def test_yylex_heredoc_double
558
+ util_lex_token("a = <<\"EOF\"\n blah blah\nEOF\n",
559
+ :tIDENTIFIER, "a",
560
+ :tEQL, "=",
561
+ :tSTRING_BEG, "\"",
562
+ :tSTRING_CONTENT, " blah blah\n",
563
+ :tSTRING_END, "EOF",
564
+ :tNL, nil)
565
+ end
566
+
567
+ def test_yylex_heredoc_double_dash
568
+ util_lex_token("a = <<-\"EOF\"\n blah blah\n EOF\n",
569
+ :tIDENTIFIER, "a",
570
+ :tEQL, "=",
571
+ :tSTRING_BEG, "\"",
572
+ :tSTRING_CONTENT, " blah blah\n",
573
+ :tSTRING_END, "EOF",
574
+ :tNL, nil)
575
+ end
576
+
577
+ def test_yylex_heredoc_double_eos
578
+ util_bad_token("a = <<\"EOF\"\nblah",
579
+ :tIDENTIFIER, "a",
580
+ :tEQL, "=",
581
+ :tSTRING_BEG, "\"")
582
+ end
583
+
584
+ def test_yylex_heredoc_double_eos_nl
585
+ util_bad_token("a = <<\"EOF\"\nblah\n",
586
+ :tIDENTIFIER, "a",
587
+ :tEQL, "=",
588
+ :tSTRING_BEG, "\"")
589
+ end
590
+
591
+ def test_yylex_heredoc_double_interp
592
+ util_lex_token("a = <<\"EOF\"\n#x a \#@a b \#$b c \#{3} \nEOF\n",
593
+ :tIDENTIFIER, "a",
594
+ :tEQL, "=",
595
+ :tSTRING_BEG, "\"",
596
+ :tSTRING_CONTENT, "#x a ",
597
+ :tSTRING_DVAR, "\#@",
598
+ :tSTRING_CONTENT, "@a b ", # HUH?
599
+ :tSTRING_DVAR, "\#$",
600
+ :tSTRING_CONTENT, "$b c ", # HUH?
601
+ :tSTRING_DBEG, "\#{",
602
+ :tSTRING_CONTENT, "3} \n", # HUH?
603
+ :tSTRING_END, "EOF",
604
+ :tNL, nil)
605
+ end
606
+
607
+ def test_yylex_heredoc_none
608
+ util_lex_token("a = <<EOF\nblah\nblah\nEOF",
609
+ :tIDENTIFIER, "a",
610
+ :tEQL, "=",
611
+ :tSTRING_BEG, "\"",
612
+ :tSTRING_CONTENT, "blah\nblah\n",
613
+ :tSTRING_CONTENT, "",
614
+ :tSTRING_END, "EOF",
615
+ :tNL, nil)
616
+ end
617
+
618
+ def test_yylex_heredoc_none_bad_eos
619
+ util_bad_token("a = <<EOF",
620
+ :tIDENTIFIER, "a",
621
+ :tEQL, "=",
622
+ :tSTRING_BEG, "\"")
623
+ end
624
+
625
+ def test_yylex_heredoc_none_dash
626
+ util_lex_token("a = <<-EOF\nblah\nblah\n EOF",
627
+ :tIDENTIFIER, "a",
628
+ :tEQL, "=",
629
+ :tSTRING_BEG, "\"",
630
+ :tSTRING_CONTENT, "blah\nblah\n",
631
+ :tSTRING_CONTENT, "",
632
+ :tSTRING_END, "EOF",
633
+ :tNL, nil)
634
+ end
635
+
636
+ def test_yylex_heredoc_single
637
+ util_lex_token("a = <<'EOF'\n blah blah\nEOF\n",
638
+ :tIDENTIFIER, "a",
639
+ :tEQL, "=",
640
+ :tSTRING_BEG, "\"",
641
+ :tSTRING_CONTENT, " blah blah\n",
642
+ :tSTRING_END, "EOF",
643
+ :tNL, nil)
644
+ end
645
+
646
+ def test_yylex_heredoc_single_bad_eos_body
647
+ util_bad_token("a = <<'EOF'\nblah",
648
+ :tIDENTIFIER, "a",
649
+ :tEQL, "=",
650
+ :tSTRING_BEG, "\"")
651
+ end
652
+
653
+ def test_yylex_heredoc_single_bad_eos_empty
654
+ util_bad_token("a = <<''\n",
655
+ :tIDENTIFIER, "a",
656
+ :tEQL, "=",
657
+ :tSTRING_BEG, "\"")
658
+ end
659
+
660
+ def test_yylex_heredoc_single_bad_eos_term
661
+ util_bad_token("a = <<'EOF",
662
+ :tIDENTIFIER, "a",
663
+ :tEQL, "=",
664
+ :tSTRING_BEG, "\"")
665
+ end
666
+
667
+ def test_yylex_heredoc_single_bad_eos_term_nl
668
+ util_bad_token("a = <<'EOF\ns = 'blah blah'",
669
+ :tIDENTIFIER, "a",
670
+ :tEQL, "=",
671
+ :tSTRING_BEG, "\"")
672
+ end
673
+
674
+ def test_yylex_heredoc_single_dash
675
+ util_lex_token("a = <<-'EOF'\n blah blah\n EOF\n",
676
+ :tIDENTIFIER, "a",
677
+ :tEQL, "=",
678
+ :tSTRING_BEG, "\"",
679
+ :tSTRING_CONTENT, " blah blah\n",
680
+ :tSTRING_END, "EOF",
681
+ :tNL, nil)
682
+ end
683
+
684
+ def test_yylex_identifier
685
+ util_lex_token("identifier", :tIDENTIFIER, "identifier")
686
+ end
687
+
688
+ def test_yylex_identifier_bang
689
+ util_lex_token("identifier!", :tFID, "identifier!")
690
+ end
691
+
692
+ def test_yylex_identifier_cmp
693
+ util_lex_fname "<=>", :tCMP
694
+ end
695
+
696
+ def test_yylex_identifier_def
697
+ util_lex_fname "identifier", :tIDENTIFIER, :expr_end
698
+ end
699
+
700
+ def test_yylex_identifier_eh
701
+ util_lex_token("identifier?", :tFID, "identifier?")
702
+ end
703
+
704
+ def test_yylex_identifier_equals_arrow
705
+ @lex.lex_state = :expr_fname
706
+ util_lex_token(":blah==>",
707
+ :tSYMBOL, "blah=",
708
+ :tASSOC, "=>")
709
+ end
710
+
711
+ def test_yylex_identifier_equals_caret
712
+ util_lex_fname "^", :tCARET
713
+ end
714
+
715
+ def test_yylex_identifier_equals_def
716
+ util_lex_fname "identifier=", :tIDENTIFIER, :expr_end
717
+ end
718
+
719
+ def test_yylex_identifier_equals_def2
720
+ util_lex_fname "==", :tEQ
721
+ end
722
+
723
+ def test_yylex_identifier_equals_expr
724
+ @lex.lex_state = :expr_dot
725
+ util_lex_token("y = arg",
726
+ :tIDENTIFIER, "y",
727
+ :tEQL, "=",
728
+ :tIDENTIFIER, "arg")
729
+
730
+ assert_equal :expr_arg, @lex.lex_state
731
+ end
732
+
733
+ def test_yylex_identifier_equals_or
734
+ util_lex_fname "|", :tPIPE
735
+ end
736
+
737
+ def test_yylex_identifier_equals_slash
738
+ util_lex_fname "/", :tDIVIDE
739
+ end
740
+
741
+ def test_yylex_identifier_equals_tilde
742
+ @lex.lex_state = :expr_fname # can only set via parser's defs
743
+ util_lex_token("identifier=~",
744
+ :tIDENTIFIER, "identifier",
745
+ :tMATCH, "=~")
746
+ end
747
+
748
+ def test_yylex_identifier_gt
749
+ util_lex_fname ">", :tGT
750
+ end
751
+
752
+ def test_yylex_identifier_le
753
+ util_lex_fname "<=", :tLEQ
754
+ end
755
+
756
+ def test_yylex_identifier_lt
757
+ util_lex_fname "<", :tLT
758
+ end
759
+
760
+ def test_yylex_identifier_tilde
761
+ util_lex_fname "~", :tTILDE
762
+ end
763
+
764
+ def test_yylex_index
765
+ util_lex_fname "[]", :tAREF
766
+ end
767
+
768
+ def test_yylex_index_equals
769
+ util_lex_fname "[]=", :tASET
770
+ end
771
+
772
+ def test_yylex_integer
773
+ util_lex_token "42", :tINTEGER, 42
774
+ end
775
+
776
+ def test_yylex_integer_bin
777
+ util_lex_token "0b101010", :tINTEGER, 42
778
+ end
779
+
780
+ def test_yylex_integer_bin_bad_none
781
+ util_bad_token "0b "
782
+ end
783
+
784
+ def test_yylex_integer_bin_bad_underscores
785
+ util_bad_token "0b10__01"
786
+ end
787
+
788
+ def test_yylex_integer_dec
789
+ util_lex_token "42", :tINTEGER, 42
790
+ end
791
+
792
+ def test_yylex_integer_dec_bad_underscores
793
+ util_bad_token "42__24"
794
+ end
795
+
796
+ def test_yylex_integer_dec_d
797
+ util_lex_token "0d42", :tINTEGER, 42
798
+ end
799
+
800
+ def test_yylex_integer_dec_d_bad_none
801
+ util_bad_token "0d"
802
+ end
803
+
804
+ def test_yylex_integer_dec_d_bad_underscores
805
+ util_bad_token "0d42__24"
806
+ end
807
+
808
+ def test_yylex_integer_eh_a
809
+ util_lex_token '?a', :tINTEGER, 97
810
+ end
811
+
812
+ def test_yylex_integer_eh_escape_M_escape_C
813
+ util_lex_token '?\M-\C-a', :tINTEGER, 129
814
+ end
815
+
816
+ def test_yylex_integer_hex
817
+ util_lex_token "0x2a", :tINTEGER, 42
818
+ end
819
+
820
+ def test_yylex_integer_hex_bad_none
821
+ util_bad_token "0x "
822
+ end
823
+
824
+ def test_yylex_integer_hex_bad_underscores
825
+ util_bad_token "0xab__cd"
826
+ end
827
+
828
+ def test_yylex_integer_oct
829
+ util_lex_token "052", :tINTEGER, 42
830
+ end
831
+
832
+ def test_yylex_integer_oct_bad_range
833
+ util_bad_token "08"
834
+ end
835
+
836
+ def test_yylex_integer_oct_bad_underscores
837
+ util_bad_token "01__23"
838
+ end
839
+
840
+ def test_yylex_integer_oct_O
841
+ util_lex_token "0O52", :tINTEGER, 42
842
+ end
843
+
844
+ def test_yylex_integer_oct_O_bad_range
845
+ util_bad_token "0O8"
846
+ end
847
+
848
+ def test_yylex_integer_oct_O_bad_underscores
849
+ util_bad_token "0O1__23"
850
+ end
851
+
852
+ def test_yylex_integer_oct_O_not_bad_none
853
+ util_lex_token "0O ", :tINTEGER, 0
854
+ end
855
+
856
+ def test_yylex_integer_oct_o
857
+ util_lex_token "0o52", :tINTEGER, 42
858
+ end
859
+
860
+ def test_yylex_integer_oct_o_bad_range
861
+ util_bad_token "0o8"
862
+ end
863
+
864
+ def test_yylex_integer_oct_o_bad_underscores
865
+ util_bad_token "0o1__23"
866
+ end
867
+
868
+ def test_yylex_integer_oct_o_not_bad_none
869
+ util_lex_token "0o ", :tINTEGER, 0
870
+ end
871
+
872
+ def test_yylex_integer_trailing
873
+ util_lex_token("1.to_s",
874
+ :tINTEGER, 1,
875
+ :tDOT, '.',
876
+ :tIDENTIFIER, 'to_s')
877
+ end
878
+
879
+ def test_yylex_integer_underscore
880
+ util_lex_token "4_2", :tINTEGER, 42
881
+ end
882
+
883
+ def test_yylex_integer_underscore_bad
884
+ util_bad_token "4__2"
885
+ end
886
+
887
+ def test_yylex_integer_zero
888
+ util_lex_token "0", :tINTEGER, 0
889
+ end
890
+
891
+ def test_yylex_ivar
892
+ util_lex_token "@blah", :tIVAR, "@blah"
893
+ end
894
+
895
+ def test_yylex_ivar_bad
896
+ util_bad_token "@1"
897
+ end
898
+
899
+ def test_yylex_keyword_expr
900
+ @lex.lex_state = :expr_endarg
901
+
902
+ util_lex_token("if", :kIF_MOD, "if")
903
+
904
+ assert_equal :expr_beg, @lex.lex_state
905
+ end
906
+
907
+ def test_yylex_lt
908
+ util_lex_token "<", :tLT, "<"
909
+ end
910
+
911
+ def test_yylex_lt2
912
+ util_lex_token("a <\< b",
913
+ :tIDENTIFIER, "a",
914
+ :tLSHFT, "<\<",
915
+ :tIDENTIFIER, "b")
916
+
917
+ end
918
+
919
+ def test_yylex_lt2_equals
920
+ util_lex_token("a <\<= b",
921
+ :tIDENTIFIER, "a",
922
+ :tOP_ASGN, "<\<",
923
+ :tIDENTIFIER, "b")
924
+ end
925
+
926
+ def test_yylex_lt_equals
927
+ util_lex_token "<=", :tLEQ, "<="
928
+ end
929
+
930
+ def test_yylex_minus
931
+ util_lex_token("1 - 2",
932
+ :tINTEGER, 1,
933
+ :tMINUS, "-",
934
+ :tINTEGER, 2)
935
+ end
936
+
937
+ def test_yylex_minus_equals
938
+ util_lex_token "-=", :tOP_ASGN, "-"
939
+ end
940
+
941
+ def test_yylex_minus_method
942
+ @lex.lex_state = :expr_fname
943
+ util_lex_token "-", :tMINUS, "-"
944
+ end
945
+
946
+ def test_yylex_minus_unary_method
947
+ @lex.lex_state = :expr_fname
948
+ util_lex_token "-@", :tUMINUS, "-@"
949
+ end
950
+
951
+ def test_yylex_minus_unary_number
952
+ util_lex_token("-42",
953
+ :tUMINUS_NUM, "-",
954
+ :tINTEGER, 42)
955
+ end
956
+
957
+ def test_yylex_nth_ref
958
+ util_lex_token('[$1, $2, $3, $4, $5, $6, $7, $8, $9]',
959
+ :tLBRACK, "[",
960
+ :tNTH_REF, 1, :tCOMMA, ",",
961
+ :tNTH_REF, 2, :tCOMMA, ",",
962
+ :tNTH_REF, 3, :tCOMMA, ",",
963
+ :tNTH_REF, 4, :tCOMMA, ",",
964
+ :tNTH_REF, 5, :tCOMMA, ",",
965
+ :tNTH_REF, 6, :tCOMMA, ",",
966
+ :tNTH_REF, 7, :tCOMMA, ",",
967
+ :tNTH_REF, 8, :tCOMMA, ",",
968
+ :tNTH_REF, 9,
969
+ :tRBRACK, "]")
970
+ end
971
+
972
+ def test_yylex_open_bracket
973
+ util_lex_token("(", :tLPAREN, "(")
974
+ end
975
+
976
+ def test_yylex_open_bracket_cmdarg
977
+ @lex.lex_state = :expr_cmdarg
978
+ util_lex_token(" (", :tLPAREN_ARG, "(")
979
+ end
980
+
981
+ def test_yylex_open_bracket_exprarg
982
+ @lex.lex_state = :expr_arg
983
+ util_lex_token(" (", :tLPAREN2, "(")
984
+ end
985
+
986
+ def test_yylex_open_curly_bracket
987
+ util_lex_token("{",
988
+ :tLBRACE, "{")
989
+ end
990
+
991
+ def test_yylex_open_curly_bracket_arg
992
+ @lex.lex_state = :expr_arg
993
+ util_lex_token("m { 3 }",
994
+ :tIDENTIFIER, "m",
995
+ :tLCURLY, "{",
996
+ :tINTEGER, 3,
997
+ :tRCURLY, "}")
998
+ end
999
+
1000
+ def test_yylex_open_curly_bracket_block
1001
+ @lex.lex_state = :expr_endarg # seen m(3)
1002
+ util_lex_token("{ 4 }",
1003
+ :tLBRACE_ARG, "{",
1004
+ :tINTEGER, 4,
1005
+ :tRCURLY, "}")
1006
+ end
1007
+
1008
+ def test_yylex_open_square_bracket_arg
1009
+ @lex.lex_state = :expr_arg
1010
+ util_lex_token("m [ 3 ]",
1011
+ :tIDENTIFIER, "m",
1012
+ :tLBRACK, "[",
1013
+ :tINTEGER, 3,
1014
+ :tRBRACK, "]")
1015
+ end
1016
+
1017
+ def test_yylex_open_square_bracket_ary
1018
+ util_lex_token("[1, 2, 3]",
1019
+ :tLBRACK, "[",
1020
+ :tINTEGER, 1,
1021
+ :tCOMMA, ",",
1022
+ :tINTEGER, 2,
1023
+ :tCOMMA, ",",
1024
+ :tINTEGER, 3,
1025
+ :tRBRACK, "]")
1026
+ end
1027
+
1028
+ def test_yylex_open_square_bracket_meth
1029
+ util_lex_token("m[3]",
1030
+ :tIDENTIFIER, "m",
1031
+ "[", "[",
1032
+ :tINTEGER, 3,
1033
+ :tRBRACK, "]")
1034
+ end
1035
+
1036
+ def test_yylex_or
1037
+ util_lex_token "|", :tPIPE, "|"
1038
+ end
1039
+
1040
+ def test_yylex_or2
1041
+ util_lex_token "||", :tOROP, "||"
1042
+ end
1043
+
1044
+ def test_yylex_or2_equals
1045
+ util_lex_token "||=", :tOP_ASGN, "||"
1046
+ end
1047
+
1048
+ def test_yylex_or_equals
1049
+ util_lex_token "|=", :tOP_ASGN, "|"
1050
+ end
1051
+
1052
+ def test_yylex_percent
1053
+ util_lex_token("a % 2",
1054
+ :tIDENTIFIER, "a",
1055
+ :tPERCENT, "%",
1056
+ :tINTEGER, 2)
1057
+ end
1058
+
1059
+ def test_yylex_percent_equals
1060
+ util_lex_token("a %= 2",
1061
+ :tIDENTIFIER, "a",
1062
+ :tOP_ASGN, "%",
1063
+ :tINTEGER, 2)
1064
+ end
1065
+
1066
+ def test_yylex_plus
1067
+ util_lex_token("1 + 1", # TODO lex_state?
1068
+ :tINTEGER, 1,
1069
+ :tPLUS, "+",
1070
+ :tINTEGER, 1)
1071
+ end
1072
+
1073
+ def test_yylex_plus_equals
1074
+ util_lex_token "+=", :tOP_ASGN, "+"
1075
+ end
1076
+
1077
+ def test_yylex_plus_method
1078
+ @lex.lex_state = :expr_fname
1079
+ util_lex_token "+", :tPLUS, "+"
1080
+ end
1081
+
1082
+ def test_yylex_plus_unary_method
1083
+ @lex.lex_state = :expr_fname
1084
+ util_lex_token "+@", :tUPLUS, "+@"
1085
+ end
1086
+
1087
+ def test_yylex_plus_unary_number
1088
+ util_lex_token("+42",
1089
+ :tINTEGER, 42)
1090
+ end
1091
+
1092
+ def test_yylex_question
1093
+ util_lex_token "?*", :tINTEGER, 42
1094
+ end
1095
+
1096
+ def test_yylex_question_bad_eos
1097
+ util_bad_token "?"
1098
+ end
1099
+
1100
+ def test_yylex_question_ws
1101
+ util_lex_token "? ", :tEH, "?"
1102
+ util_lex_token "?\n", :tEH, "?"
1103
+ util_lex_token "?\t", :tEH, "?"
1104
+ util_lex_token "?\v", :tEH, "?"
1105
+ util_lex_token "?\r", :tEH, "?"
1106
+ util_lex_token "?\f", :tEH, "?"
1107
+ end
1108
+
1109
+ def test_yylex_question_ws_backslashed
1110
+ @lex.lex_state = :expr_beg
1111
+ util_lex_token "?\\ ", :tINTEGER, 32
1112
+ @lex.lex_state = :expr_beg
1113
+ util_lex_token "?\\n", :tINTEGER, 10
1114
+ @lex.lex_state = :expr_beg
1115
+ util_lex_token "?\\t", :tINTEGER, 9
1116
+ @lex.lex_state = :expr_beg
1117
+ util_lex_token "?\\v", :tINTEGER, 11
1118
+ @lex.lex_state = :expr_beg
1119
+ util_lex_token "?\\r", :tINTEGER, 13
1120
+ @lex.lex_state = :expr_beg
1121
+ util_lex_token "?\\f", :tINTEGER, 12
1122
+ end
1123
+
1124
+ def test_yylex_rbracket
1125
+ util_lex_token "]", :tRBRACK, "]"
1126
+ end
1127
+
1128
+ def test_yylex_rcurly
1129
+ util_lex_token "}", :tRCURLY, "}"
1130
+ end
1131
+
1132
+ def test_yylex_regexp
1133
+ util_lex_token("/regexp/",
1134
+ :tREGEXP_BEG, "/",
1135
+ :tSTRING_CONTENT, "regexp",
1136
+ :tREGEXP_END, "")
1137
+ end
1138
+
1139
+ def test_yylex_regexp_ambiguous
1140
+ util_lex_token("method /regexp/",
1141
+ :tIDENTIFIER, "method",
1142
+ :tREGEXP_BEG, "/",
1143
+ :tSTRING_CONTENT, "regexp",
1144
+ :tREGEXP_END, "")
1145
+ end
1146
+
1147
+ def test_yylex_regexp_bad
1148
+ util_bad_token("/.*/xyz",
1149
+ :tREGEXP_BEG, "/",
1150
+ :tSTRING_CONTENT, ".*")
1151
+ end
1152
+
1153
+ def test_yylex_regexp_escape_C
1154
+ util_lex_token('/regex\\C-x/',
1155
+ :tREGEXP_BEG, "/",
1156
+ :tSTRING_CONTENT, "regex\\C-x",
1157
+ :tREGEXP_END, "")
1158
+ end
1159
+
1160
+ def test_yylex_regexp_escape_C_M
1161
+ util_lex_token('/regex\\C-\\M-x/',
1162
+ :tREGEXP_BEG, "/",
1163
+ :tSTRING_CONTENT, "regex\\C-\\M-x",
1164
+ :tREGEXP_END, "")
1165
+ end
1166
+
1167
+ def test_yylex_regexp_escape_C_M_craaaazy
1168
+ util_lex_token("/regex\\C-\\\n\\M-x/",
1169
+ :tREGEXP_BEG, "/",
1170
+ :tSTRING_CONTENT, "regex\\C-\\M-x",
1171
+ :tREGEXP_END, "")
1172
+ end
1173
+
1174
+ def test_yylex_regexp_escape_C_bad_dash
1175
+ util_bad_token '/regex\\Cx/', :tREGEXP_BEG, "/"
1176
+ end
1177
+
1178
+ def test_yylex_regexp_escape_C_bad_dash_eos
1179
+ util_bad_token '/regex\\C-/', :tREGEXP_BEG, "/"
1180
+ end
1181
+
1182
+ def test_yylex_regexp_escape_C_bad_dash_eos2
1183
+ util_bad_token '/regex\\C-', :tREGEXP_BEG, "/"
1184
+ end
1185
+
1186
+ def test_yylex_regexp_escape_C_bad_eos
1187
+ util_bad_token '/regex\\C/', :tREGEXP_BEG, "/"
1188
+ end
1189
+
1190
+ def test_yylex_regexp_escape_C_bad_eos2
1191
+ util_bad_token '/regex\\c', :tREGEXP_BEG, "/"
1192
+ end
1193
+
1194
+ def test_yylex_regexp_escape_M
1195
+ util_lex_token('/regex\\M-x/',
1196
+ :tREGEXP_BEG, "/",
1197
+ :tSTRING_CONTENT, "regex\\M-x",
1198
+ :tREGEXP_END, "")
1199
+ end
1200
+
1201
+ def test_yylex_regexp_escape_M_C
1202
+ util_lex_token('/regex\\M-\\C-x/',
1203
+ :tREGEXP_BEG, "/",
1204
+ :tSTRING_CONTENT, "regex\\M-\\C-x",
1205
+ :tREGEXP_END, "")
1206
+ end
1207
+
1208
+ def test_yylex_regexp_escape_M_bad_dash
1209
+ util_bad_token '/regex\\Mx/', :tREGEXP_BEG, "/"
1210
+ end
1211
+
1212
+ def test_yylex_regexp_escape_M_bad_dash_eos
1213
+ util_bad_token '/regex\\M-/', :tREGEXP_BEG, "/"
1214
+ end
1215
+
1216
+ def test_yylex_regexp_escape_M_bad_dash_eos2
1217
+ util_bad_token '/regex\\M-', :tREGEXP_BEG, "/"
1218
+ end
1219
+
1220
+ def test_yylex_regexp_escape_M_bad_eos
1221
+ util_bad_token '/regex\\M/', :tREGEXP_BEG, "/"
1222
+ end
1223
+
1224
+ def test_yylex_regexp_escape_backslash_slash
1225
+ util_lex_token('/\\//',
1226
+ :tREGEXP_BEG, "/",
1227
+ :tSTRING_CONTENT, '\\/',
1228
+ :tREGEXP_END, "")
1229
+ end
1230
+
1231
+ def test_yylex_regexp_escape_backslash_terminator
1232
+ util_lex_token('%r%blah\\%blah%',
1233
+ :tREGEXP_BEG, "%r\000", # FIX ?!?
1234
+ :tSTRING_CONTENT, "blah\\%blah",
1235
+ :tREGEXP_END, "")
1236
+ end
1237
+
1238
+ def test_yylex_regexp_escape_backslash_terminator_meta1
1239
+ util_lex_token('%r{blah\\}blah}',
1240
+ :tREGEXP_BEG, "%r{", # FIX ?!?
1241
+ :tSTRING_CONTENT, "blah\\}blah",
1242
+ :tREGEXP_END, "")
1243
+ end
1244
+
1245
+ def test_yylex_regexp_escape_backslash_terminator_meta2
1246
+ util_lex_token('%r/blah\\/blah/',
1247
+ :tREGEXP_BEG, "%r\000", # FIX ?!?
1248
+ :tSTRING_CONTENT, "blah\\/blah",
1249
+ :tREGEXP_END, "")
1250
+ end
1251
+
1252
+ def test_yylex_regexp_escape_backslash_terminator_meta3
1253
+ util_lex_token('%r/blah\\%blah/',
1254
+ :tREGEXP_BEG, "%r\000", # FIX ?!?
1255
+ :tSTRING_CONTENT, "blah\\%blah",
1256
+ :tREGEXP_END, "")
1257
+ end
1258
+
1259
+ def test_yylex_regexp_escape_bad_eos
1260
+ util_bad_token '/regex\\', :tREGEXP_BEG, "/"
1261
+ end
1262
+
1263
+ def test_yylex_regexp_escape_bs
1264
+ util_lex_token('/regex\\\\regex/',
1265
+ :tREGEXP_BEG, "/",
1266
+ :tSTRING_CONTENT, "regex\\\\regex",
1267
+ :tREGEXP_END, "")
1268
+ end
1269
+
1270
+ def test_yylex_regexp_escape_c
1271
+ util_lex_token('/regex\\cxxx/',
1272
+ :tREGEXP_BEG, "/",
1273
+ :tSTRING_CONTENT, "regex\\cxxx",
1274
+ :tREGEXP_END, "")
1275
+ end
1276
+
1277
+ def test_yylex_regexp_escape_c_backslash
1278
+ util_lex_token('/regex\\c\\n/',
1279
+ :tREGEXP_BEG, "/",
1280
+ :tSTRING_CONTENT, "regex\\c\\n",
1281
+ :tREGEXP_END, "")
1282
+ end
1283
+
1284
+ def test_yylex_regexp_escape_chars
1285
+ util_lex_token('/re\\tge\\nxp/',
1286
+ :tREGEXP_BEG, "/",
1287
+ :tSTRING_CONTENT, "re\\tge\\nxp",
1288
+ :tREGEXP_END, "")
1289
+ end
1290
+
1291
+ def test_yylex_regexp_escape_double_backslash
1292
+ regexp = '/[\\/\\\\]$/'
1293
+ util_lex_token(regexp,
1294
+ :tREGEXP_BEG, "/",
1295
+ :tSTRING_CONTENT, regexp[1..-2],
1296
+ :tREGEXP_END, "")
1297
+ end
1298
+
1299
+ def test_yylex_regexp_escape_hex
1300
+ util_lex_token('/regex\\x61xp/',
1301
+ :tREGEXP_BEG, "/",
1302
+ :tSTRING_CONTENT, "regex\\x61xp",
1303
+ :tREGEXP_END, "")
1304
+ end
1305
+
1306
+ def test_yylex_regexp_escape_hex_bad
1307
+ util_bad_token '/regex\\xzxp/', :tREGEXP_BEG, "/"
1308
+ end
1309
+
1310
+ def test_yylex_regexp_escape_hex_one
1311
+ util_lex_token('/^[\\xd\\xa]{2}/on',
1312
+ :tREGEXP_BEG, '/',
1313
+ :tSTRING_CONTENT, '^[\\xd\\xa]{2}',
1314
+ :tREGEXP_END, 'on')
1315
+ end
1316
+
1317
+ def test_yylex_regexp_escape_oct1
1318
+ util_lex_token('/regex\\0xp/',
1319
+ :tREGEXP_BEG, "/",
1320
+ :tSTRING_CONTENT, "regex\\0xp",
1321
+ :tREGEXP_END, "")
1322
+ end
1323
+
1324
+ def test_yylex_regexp_escape_oct2
1325
+ util_lex_token('/regex\\07xp/',
1326
+ :tREGEXP_BEG, "/",
1327
+ :tSTRING_CONTENT, "regex\\07xp",
1328
+ :tREGEXP_END, "")
1329
+ end
1330
+
1331
+ def test_yylex_regexp_escape_oct3
1332
+ util_lex_token('/regex\\10142/',
1333
+ :tREGEXP_BEG, "/",
1334
+ :tSTRING_CONTENT, "regex\\10142",
1335
+ :tREGEXP_END, "")
1336
+ end
1337
+
1338
+ def test_yylex_regexp_escape_return
1339
+ util_lex_token("/regex\\\nregex/",
1340
+ :tREGEXP_BEG, "/",
1341
+ :tSTRING_CONTENT, "regexregex",
1342
+ :tREGEXP_END, "")
1343
+ end
1344
+
1345
+ def test_yylex_regexp_nm
1346
+ util_lex_token("/.*/nm",
1347
+ :tREGEXP_BEG, "/",
1348
+ :tSTRING_CONTENT, ".*",
1349
+ :tREGEXP_END, "nm")
1350
+ end
1351
+
1352
+ def test_yylex_rparen
1353
+ util_lex_token ")", :tRPAREN, ")"
1354
+ end
1355
+
1356
+ def test_yylex_rshft
1357
+ util_lex_token("a >> 2",
1358
+ :tIDENTIFIER, "a",
1359
+ :tRSHFT, ">>",
1360
+ :tINTEGER, 2)
1361
+ end
1362
+
1363
+ def test_yylex_rshft_equals
1364
+ util_lex_token("a >>= 2",
1365
+ :tIDENTIFIER, "a",
1366
+ :tOP_ASGN, ">>",
1367
+ :tINTEGER, 2)
1368
+ end
1369
+
1370
+ def test_yylex_star
1371
+ util_lex_token("a * ",
1372
+ :tIDENTIFIER, "a",
1373
+ :tSTAR2, "*")
1374
+
1375
+ assert_equal :expr_beg, @lex.lex_state
1376
+ end
1377
+
1378
+ def test_yylex_star2
1379
+ util_lex_token("a ** ",
1380
+ :tIDENTIFIER, "a",
1381
+ :tPOW, "**")
1382
+
1383
+ assert_equal :expr_beg, @lex.lex_state
1384
+ end
1385
+
1386
+ def test_yylex_star2_equals
1387
+ util_lex_token("a **= ",
1388
+ :tIDENTIFIER, "a",
1389
+ :tOP_ASGN, "**")
1390
+
1391
+ assert_equal :expr_beg, @lex.lex_state
1392
+ end
1393
+
1394
+ def test_yylex_star_arg
1395
+ @lex.lex_state = :expr_arg
1396
+
1397
+ util_lex_token(" *a",
1398
+ :tSTAR, "*",
1399
+ :tIDENTIFIER, "a")
1400
+
1401
+ assert_equal :expr_arg, @lex.lex_state
1402
+ end
1403
+
1404
+ def test_yylex_star_arg_beg
1405
+ @lex.lex_state = :expr_beg
1406
+
1407
+ util_lex_token("*a",
1408
+ :tSTAR, "*",
1409
+ :tIDENTIFIER, "a")
1410
+
1411
+ assert_equal :expr_arg, @lex.lex_state
1412
+ end
1413
+
1414
+ def test_yylex_star_arg_beg_fname
1415
+ @lex.lex_state = :expr_fname
1416
+
1417
+ util_lex_token("*a",
1418
+ :tSTAR2, "*",
1419
+ :tIDENTIFIER, "a")
1420
+
1421
+ assert_equal :expr_arg, @lex.lex_state
1422
+ end
1423
+
1424
+ def test_yylex_star_equals
1425
+ util_lex_token("a *= ",
1426
+ :tIDENTIFIER, "a",
1427
+ :tOP_ASGN, "*")
1428
+
1429
+ assert_equal :expr_beg, @lex.lex_state
1430
+ end
1431
+
1432
+ def test_yylex_string_bad_eos
1433
+ util_bad_token('%',
1434
+ :tSTRING_BEG, '%')
1435
+ end
1436
+
1437
+ def test_yylex_string_bad_eos_quote
1438
+ util_bad_token('%{nest',
1439
+ :tSTRING_BEG, '%}')
1440
+ end
1441
+
1442
+ def test_yylex_string_double
1443
+ util_lex_token('"string"',
1444
+ :tSTRING, "string")
1445
+ end
1446
+
1447
+ def test_yylex_string_double_escape_C
1448
+ util_lex_token('"\\C-a"',
1449
+ :tSTRING, "\001")
1450
+ end
1451
+
1452
+ def test_yylex_string_double_escape_C_backslash
1453
+ util_lex_token('"\\C-\\\\"',
1454
+ :tSTRING_BEG, "\"",
1455
+ :tSTRING_CONTENT, "\034",
1456
+ :tSTRING_END, "\"")
1457
+ end
1458
+
1459
+ def test_yylex_string_double_escape_C_escape
1460
+ util_lex_token('"\\C-\\M-a"',
1461
+ :tSTRING_BEG, "\"",
1462
+ :tSTRING_CONTENT, "\201",
1463
+ :tSTRING_END, "\"")
1464
+ end
1465
+
1466
+ def test_yylex_string_double_escape_C_question
1467
+ util_lex_token('"\\C-?"',
1468
+ :tSTRING, "\177")
1469
+ end
1470
+
1471
+ def test_yylex_string_double_escape_M
1472
+ util_lex_token('"\\M-a"',
1473
+ :tSTRING, "\341")
1474
+ end
1475
+
1476
+ def test_yylex_string_double_escape_M_backslash
1477
+ util_lex_token('"\\M-\\\\"',
1478
+ :tSTRING_BEG, "\"",
1479
+ :tSTRING_CONTENT, "\334",
1480
+ :tSTRING_END, "\"")
1481
+ end
1482
+
1483
+ def test_yylex_string_double_escape_M_escape
1484
+ util_lex_token('"\\M-\\C-a"',
1485
+ :tSTRING_BEG, "\"",
1486
+ :tSTRING_CONTENT, "\201",
1487
+ :tSTRING_END, "\"")
1488
+ end
1489
+
1490
+ def test_yylex_string_double_escape_bs1
1491
+ util_lex_token('"a\\a\\a"',
1492
+ :tSTRING, "a\a\a")
1493
+ end
1494
+
1495
+ def test_yylex_string_double_escape_bs2
1496
+ util_lex_token('"a\\\\a"',
1497
+ :tSTRING, "a\\a")
1498
+ end
1499
+
1500
+ def test_yylex_string_double_escape_c
1501
+ util_lex_token('"\\ca"',
1502
+ :tSTRING, "\001")
1503
+ end
1504
+
1505
+ def test_yylex_string_double_escape_c_backslash
1506
+ util_lex_token('"\\c\\"',
1507
+ :tSTRING_BEG, "\"",
1508
+ :tSTRING_CONTENT, "\034",
1509
+ :tSTRING_END, "\"")
1510
+ end
1511
+
1512
+ def test_yylex_string_double_escape_c_escape
1513
+ util_lex_token('"\\c\\M-a"',
1514
+ :tSTRING_BEG, "\"",
1515
+ :tSTRING_CONTENT, "\201",
1516
+ :tSTRING_END, "\"")
1517
+ end
1518
+
1519
+ def test_yylex_string_double_escape_c_question
1520
+ util_lex_token('"\\c?"',
1521
+ :tSTRING, "\177")
1522
+ end
1523
+
1524
+ def test_yylex_string_double_escape_chars
1525
+ util_lex_token('"s\\tri\\ng"',
1526
+ :tSTRING, "s\tri\ng")
1527
+ end
1528
+
1529
+ def test_yylex_string_double_escape_hex
1530
+ util_lex_token('"n = \\x61\\x62\\x63"',
1531
+ :tSTRING, "n = abc")
1532
+ end
1533
+
1534
+ def test_yylex_string_double_escape_octal
1535
+ util_lex_token('"n = \\101\\102\\103"',
1536
+ :tSTRING, "n = ABC")
1537
+ end
1538
+
1539
+ def test_yylex_string_double_interp
1540
+ util_lex_token("\"blah #x a \#@a b \#$b c \#{3} # \"",
1541
+ :tSTRING_BEG, "\"",
1542
+ :tSTRING_CONTENT, "blah #x a ",
1543
+ :tSTRING_DVAR, nil,
1544
+ :tSTRING_CONTENT, "@a b ",
1545
+ :tSTRING_DVAR, nil,
1546
+ :tSTRING_CONTENT, "$b c ",
1547
+ :tSTRING_DBEG, nil,
1548
+ :tSTRING_CONTENT, "3} # ",
1549
+ :tSTRING_END, "\"")
1550
+ end
1551
+
1552
+ def test_yylex_string_double_nested_curlies
1553
+ util_lex_token('%{nest{one{two}one}nest}',
1554
+ :tSTRING_BEG, '%}',
1555
+ :tSTRING_CONTENT, "nest{one{two}one}nest",
1556
+ :tSTRING_END, '}')
1557
+ end
1558
+
1559
+ def test_yylex_string_double_no_interp
1560
+ util_lex_token("\"# blah\"", # pound first
1561
+ :tSTRING, "# blah")
1562
+
1563
+ util_lex_token("\"blah # blah\"", # pound not first
1564
+ :tSTRING, "blah # blah")
1565
+ end
1566
+
1567
+ def test_yylex_string_escape_x_single
1568
+ util_lex_token('"\\x0"',
1569
+ :tSTRING, "\000")
1570
+ end
1571
+
1572
+ def test_yylex_string_pct_Q
1573
+ util_lex_token("%Q[s1 s2]",
1574
+ :tSTRING_BEG, "%Q[",
1575
+ :tSTRING_CONTENT, "s1 s2",
1576
+ :tSTRING_END, "]")
1577
+ end
1578
+
1579
+ def test_yylex_string_pct_W
1580
+ util_lex_token("%W[s1 s2\ns3]", # TODO: add interpolation to these
1581
+ :tWORDS_BEG, "%W[",
1582
+ :tSTRING_CONTENT, "s1",
1583
+ :tSPACE, nil,
1584
+ :tSTRING_CONTENT, "s2",
1585
+ :tSPACE, nil,
1586
+ :tSTRING_CONTENT, "s3",
1587
+ :tSPACE, nil,
1588
+ :tSTRING_END, nil)
1589
+ end
1590
+
1591
+ def test_yylex_string_pct_W_bs_nl
1592
+ util_lex_token("%W[s1 \\\ns2]", # TODO: add interpolation to these
1593
+ :tWORDS_BEG, "%W[",
1594
+ :tSTRING_CONTENT, "s1",
1595
+ :tSPACE, nil,
1596
+ :tSTRING_CONTENT, "\ns2",
1597
+ :tSPACE, nil,
1598
+ :tSTRING_END, nil)
1599
+ end
1600
+
1601
+ def test_yylex_string_pct_angle
1602
+ util_lex_token("%<blah>",
1603
+ :tSTRING_BEG, "%>",
1604
+ :tSTRING_CONTENT, "blah",
1605
+ :tSTRING_END, ">")
1606
+ end
1607
+
1608
+ def test_yylex_string_pct_other
1609
+ util_lex_token("%%blah%",
1610
+ :tSTRING_BEG, "%%",
1611
+ :tSTRING_CONTENT, "blah",
1612
+ :tSTRING_END, "%")
1613
+ end
1614
+
1615
+ def test_yylex_string_pct_w
1616
+ util_bad_token("%w[s1 s2 ",
1617
+ :tAWORDS_BEG, "%w[",
1618
+ :tSTRING_CONTENT, "s1",
1619
+ :tSPACE, nil,
1620
+ :tSTRING_CONTENT, "s2",
1621
+ :tSPACE, nil)
1622
+ end
1623
+
1624
+ def test_yylex_string_pct_w_bs_nl
1625
+ util_lex_token("%w[s1 \\\ns2]",
1626
+ :tAWORDS_BEG, "%w[",
1627
+ :tSTRING_CONTENT, "s1",
1628
+ :tSPACE, nil,
1629
+ :tSTRING_CONTENT, "\ns2",
1630
+ :tSPACE, nil,
1631
+ :tSTRING_END, nil)
1632
+ end
1633
+
1634
+ def test_yylex_string_pct_w_bs_sp
1635
+ util_lex_token("%w[s\\ 1 s\\ 2]",
1636
+ :tAWORDS_BEG, "%w[",
1637
+ :tSTRING_CONTENT, "s 1",
1638
+ :tSPACE, nil,
1639
+ :tSTRING_CONTENT, "s 2",
1640
+ :tSPACE, nil,
1641
+ :tSTRING_END, nil)
1642
+ end
1643
+
1644
+ def test_yylex_string_pct_w_tab
1645
+ util_lex_token("%w[abc\tdef]",
1646
+ :tAWORDS_BEG, "%w[",
1647
+ :tSTRING_CONTENT, "abc\tdef",
1648
+ :tSPACE, nil,
1649
+ :tSTRING_END, nil)
1650
+ end
1651
+
1652
+ def test_yylex_string_single
1653
+ util_lex_token("'string'",
1654
+ :tSTRING, "string")
1655
+ end
1656
+
1657
+ def test_yylex_string_single_escape_chars
1658
+ util_lex_token("'s\\tri\\ng'",
1659
+ :tSTRING, "s\\tri\\ng")
1660
+ end
1661
+
1662
+ def test_yylex_string_single_nl
1663
+ util_lex_token("'blah\\\nblah'",
1664
+ :tSTRING, "blah\\\nblah")
1665
+ end
1666
+
1667
+ def test_yylex_symbol
1668
+ util_lex_token(":symbol",
1669
+ :tSYMBOL, "symbol")
1670
+ end
1671
+
1672
+ def test_yylex_symbol_bad_zero
1673
+ util_bad_token(":\"blah\0\"",
1674
+ :tSYMBEG, ":")
1675
+ end
1676
+
1677
+ def test_yylex_symbol_double
1678
+ util_lex_token(":\"symbol\"",
1679
+ :tSYMBEG, ":",
1680
+ :tSTRING_CONTENT, "symbol",
1681
+ :tSTRING_END, '"')
1682
+ end
1683
+
1684
+ def test_yylex_symbol_single
1685
+ util_lex_token(":'symbol'",
1686
+ :tSYMBEG, ":",
1687
+ :tSTRING_CONTENT, "symbol",
1688
+ :tSTRING_END, "'")
1689
+ end
1690
+
1691
+ def test_yylex_ternary
1692
+ util_lex_token("a ? b : c",
1693
+ :tIDENTIFIER, "a",
1694
+ :tEH, "?",
1695
+ :tIDENTIFIER, "b",
1696
+ :tCOLON, ":",
1697
+ :tIDENTIFIER, "c")
1698
+
1699
+ util_lex_token("a ?bb : c", # GAH! MATZ!!!
1700
+ :tIDENTIFIER, "a",
1701
+ :tEH, "?",
1702
+ :tIDENTIFIER, "bb",
1703
+ :tCOLON, ":",
1704
+ :tIDENTIFIER, "c")
1705
+
1706
+ util_lex_token("42 ?", # 42 forces expr_end
1707
+ :tINTEGER, 42,
1708
+ :tEH, "?")
1709
+ end
1710
+
1711
+ def test_yylex_tilde
1712
+ util_lex_token "~", :tTILDE, "~"
1713
+ end
1714
+
1715
+ def test_yylex_tilde_unary
1716
+ @lex.lex_state = :expr_fname
1717
+ util_lex_token "~@", :tTILDE, "~"
1718
+ end
1719
+
1720
+ def test_yylex_uminus
1721
+ util_lex_token("-blah",
1722
+ :tUMINUS, "-",
1723
+ :tIDENTIFIER, "blah")
1724
+ end
1725
+
1726
+ def test_yylex_underscore
1727
+ util_lex_token("_var", :tIDENTIFIER, "_var")
1728
+ end
1729
+
1730
+ def test_yylex_underscore_end
1731
+ @lex.src = "__END__\n"
1732
+ deny @lex.advance
1733
+ end
1734
+
1735
+ def test_yylex_uplus
1736
+ util_lex_token("+blah",
1737
+ :tUPLUS, "+",
1738
+ :tIDENTIFIER, "blah")
1739
+ end
1740
+
1741
+ def test_zbug_float_in_decl
1742
+ util_lex_token("def initialize(u = ",
1743
+ :kDEF, "def",
1744
+ :tIDENTIFIER, "initialize",
1745
+ :tLPAREN2, "(",
1746
+ :tIDENTIFIER, "u",
1747
+ :tEQL, "=")
1748
+
1749
+ assert_equal :expr_beg, @lex.lex_state
1750
+
1751
+ util_lex_token("0.0, s = 0.0",
1752
+ :tFLOAT, 0.0,
1753
+ :tCOMMA, ',',
1754
+ :tIDENTIFIER, "s",
1755
+ :tEQL, "=",
1756
+ :tFLOAT, 0.0)
1757
+ end
1758
+
1759
+ def test_zbug_id_equals
1760
+ util_lex_token("a =",
1761
+ :tIDENTIFIER, "a",
1762
+ :tEQL, "=")
1763
+
1764
+ assert_equal :expr_beg, @lex.lex_state
1765
+
1766
+ util_lex_token("0.0",
1767
+ :tFLOAT, 0.0)
1768
+ end
1769
+
1770
+ def test_zbug_no_spaces_in_decl
1771
+ util_lex_token("def initialize(u=",
1772
+ :kDEF, "def",
1773
+ :tIDENTIFIER, "initialize",
1774
+ :tLPAREN2, "(",
1775
+ :tIDENTIFIER, "u",
1776
+ :tEQL, "=")
1777
+
1778
+ assert_equal :expr_beg, @lex.lex_state
1779
+
1780
+ util_lex_token("0.0,s=0.0",
1781
+ :tFLOAT, 0.0,
1782
+ :tCOMMA, ",",
1783
+ :tIDENTIFIER, "s",
1784
+ :tEQL, "=",
1785
+ :tFLOAT, 0.0)
1786
+ end
1787
+
1788
+ ############################################################
1789
+
1790
+ def util_bad_token s, *args
1791
+ assert_raises SyntaxError do
1792
+ util_lex_token s, *args
1793
+ end
1794
+ end
1795
+
1796
+ def util_escape expected, input
1797
+ @lex.src = input
1798
+ assert_equal expected, @lex.read_escape
1799
+ end
1800
+
1801
+ def util_escape_bad input
1802
+ @lex.src = input
1803
+ assert_raises SyntaxError do
1804
+ @lex.read_escape
1805
+ end
1806
+ end
1807
+
1808
+ def util_lex_fname name, type, end_state = :expr_arg
1809
+ @lex.lex_state = :expr_fname # can only set via parser's defs
1810
+
1811
+ util_lex_token("def #{name} ", :kDEF, "def", type, name)
1812
+
1813
+ assert_equal end_state, @lex.lex_state
1814
+ end
1815
+
1816
+ def util_lex_token input, *args
1817
+ @lex.src = input
1818
+
1819
+ until args.empty? do
1820
+ token = args.shift
1821
+ value = args.shift
1822
+ assert @lex.advance, "no more tokens"
1823
+ assert_equal [token, value], [@lex.token, @lex.yacc_value]
1824
+ end
1825
+
1826
+ deny @lex.advance, "must be empty, but had #{[@lex.token, @lex.yacc_value].inspect}"
1827
+ end
1828
+ end
1829
+