parser 2.0.0.pre2 → 2.0.0.pre3

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.
@@ -1,17 +1,29 @@
1
1
  module Parser
2
2
  module Source
3
3
 
4
+ ##
5
+ # @api public
6
+ #
7
+ # @!attribute [r] text
8
+ # @return String
9
+ #
10
+ # @!attribute [r] location
11
+ # @return Parser::Source::Range
4
12
  class Comment
5
13
  attr_reader :text
6
14
 
7
15
  attr_reader :location
8
16
  alias_method :loc, :location
9
17
 
18
+ ##
19
+ # @see Parser::Source::Comment::Associator
10
20
  def self.associate(ast, comments)
11
21
  associator = Associator.new(comments, ast)
12
22
  associator.associate
13
23
  end
14
24
 
25
+ ##
26
+ # @param [Parser::Source::Range] location
15
27
  def initialize(location)
16
28
  @location = location
17
29
  @text = location.source.freeze
@@ -19,6 +31,18 @@ module Parser
19
31
  freeze
20
32
  end
21
33
 
34
+ ##
35
+ # Returns the type of this comment.
36
+ #
37
+ # * Inline comments correspond to `:inline`:
38
+ #
39
+ # # whatever
40
+ #
41
+ # * Block comments correspond to `:document`:
42
+ #
43
+ # =begin
44
+ # hi i am a document
45
+ # =end
22
46
  def type
23
47
  case text
24
48
  when /^#/
@@ -28,14 +52,25 @@ module Parser
28
52
  end
29
53
  end
30
54
 
55
+ ##
56
+ # @see [#type]
57
+ # @return [TrueClass|FalseClass]
31
58
  def inline?
32
59
  type == :inline
33
60
  end
34
61
 
62
+ ##
63
+ # @see [#type]
64
+ # @return [TrueClass|FalseClass]
35
65
  def document?
36
66
  type == :document
37
67
  end
38
68
 
69
+ ##
70
+ # Compares comments. Two comments are identical if they
71
+ # correspond to the same source range.
72
+ # @param [Object] other
73
+ # @return [TrueClass|FalseClass]
39
74
  def ==(other)
40
75
  other.is_a?(Source::Comment) &&
41
76
  @location == other.location
@@ -1,6 +1,9 @@
1
1
  module Parser
2
2
  module Source
3
3
 
4
+ ##
5
+ # @api public
6
+ #
4
7
  class Comment::Associator
5
8
  def initialize(comments, ast)
6
9
  @comments = comments
@@ -1,10 +1,8 @@
1
1
  module Parser
2
2
  module Source
3
3
 
4
- # General idea for Map subclasses: only store what's
5
- # absolutely necessary; don't duplicate the info contained in
6
- # ASTs; if it can be extracted from source given only the other
7
- # stored information, don't store it.
4
+ ##
5
+ # @api public
8
6
  #
9
7
  class Map
10
8
  attr_reader :expression
@@ -1,6 +1,9 @@
1
1
  module Parser
2
2
  module Source
3
3
 
4
+ ##
5
+ # @api public
6
+ #
4
7
  class Range
5
8
  attr_reader :source_buffer
6
9
  attr_reader :begin_pos, :end_pos
@@ -64,6 +67,10 @@ module Parser
64
67
  [@source_buffer.name, line, column + 1].join(':')
65
68
  end
66
69
 
70
+ def resize(new_size)
71
+ Range.new(@source_buffer, @begin_pos, @begin_pos + new_size)
72
+ end
73
+
67
74
  def join(other)
68
75
  Range.new(@source_buffer,
69
76
  [@begin_pos, other.begin_pos].min,
@@ -1,6 +1,9 @@
1
1
  module Parser
2
2
  module Source
3
3
 
4
+ ##
5
+ # @api public
6
+ #
4
7
  class Rewriter
5
8
  attr_accessor :diagnostics
6
9
 
@@ -1,6 +1,9 @@
1
1
  module Parser
2
2
  module Source
3
3
 
4
+ ##
5
+ # @api private
6
+ #
4
7
  class Rewriter::Action
5
8
  attr_reader :range, :replacement
6
9
 
@@ -1,7 +1,12 @@
1
1
  module Parser
2
2
  ##
3
- # {Parser::SyntaxError} is raised whenever parser detects a syntax error
4
- # (what a surprise!) similar to the standard SyntaxError class.
3
+ # {Parser::SyntaxError} is raised whenever parser detects a syntax error,
4
+ # similar to the standard SyntaxError class.
5
+ #
6
+ # @api public
7
+ #
8
+ # @!attribute [r] diagnostic
9
+ # @return [Parser::Diagnostic]
5
10
  #
6
11
  class SyntaxError < StandardError
7
12
  attr_reader :diagnostic
@@ -1,3 +1,3 @@
1
1
  module Parser
2
- VERSION = '2.0.0.pre2'
2
+ VERSION = '2.0.0.pre3'
3
3
  end
@@ -41,4 +41,6 @@ Gem::Specification.new do |spec|
41
41
 
42
42
  spec.add_development_dependency 'yard'
43
43
  spec.add_development_dependency 'kramdown'
44
+
45
+ spec.add_development_dependency 'gauntlet'
44
46
  end
@@ -74,9 +74,11 @@ module ParseHelper
74
74
  begin
75
75
  parsed_ast = parser.parse(source_file)
76
76
  rescue => exc
77
- new_exc = exc.class.new("(#{version}) #{exc.message}")
78
- new_exc.set_backtrace(exc.backtrace)
79
- raise new_exc
77
+ backtrace = exc.backtrace
78
+ Exception.instance_method(:initialize).bind(exc).
79
+ call("(#{version}) #{exc.message}")
80
+ exc.set_backtrace(backtrace)
81
+ raise
80
82
  end
81
83
 
82
84
  assert_equal ast, parsed_ast,
@@ -3,11 +3,15 @@
3
3
  require 'helper'
4
4
 
5
5
  class TestEncoding < Minitest::Test
6
+ include AST::Sexp
7
+
6
8
  def recognize(string)
7
9
  Parser::Source::Buffer.recognize_encoding(string)
8
10
  end
9
11
 
10
12
  if defined?(Encoding)
13
+ require 'parser/all'
14
+
11
15
  def test_default
12
16
  assert_equal nil, recognize('foobar')
13
17
  end
@@ -45,5 +49,30 @@ class TestEncoding < Minitest::Test
45
49
  assert_equal nil, recognize('# codingkoi8-r')
46
50
  assert_equal nil, recognize('# coding koi8-r')
47
51
  end
52
+
53
+ def test_utf8_mac
54
+ assert_equal Encoding::UTF8_MAC, recognize('# coding: utf8-mac')
55
+ end
56
+
57
+ def test_suffix
58
+ assert_equal Encoding::UTF_8, recognize('# coding: utf-8-dos')
59
+ assert_equal Encoding::UTF_8, recognize('# coding: utf-8-unix')
60
+ assert_equal Encoding::UTF_8, recognize('# coding: utf-8-mac')
61
+
62
+ assert_raises(ArgumentError) do
63
+ assert_equal nil, recognize('# coding: utf-8-dicks')
64
+ end
65
+ end
66
+
67
+ def test_parse_18_invalid_enc
68
+ ast = Parser::Ruby18.parse("# encoding:feynman-diagram\n1")
69
+ assert_equal ast, s(:int, 1)
70
+ end
71
+
72
+ def test_parse_19_invalid_enc
73
+ assert_raises(ArgumentError) do
74
+ Parser::Ruby19.parse("# encoding:feynman-diagram\n1")
75
+ end
76
+ end
48
77
  end
49
78
  end
@@ -16,19 +16,36 @@ class TestLexer < Minitest::Test
16
16
  setup_lexer 18
17
17
  end
18
18
 
19
+ #
20
+ # Tools
21
+ #
22
+
23
+ def utf(str)
24
+ if str.respond_to?(:force_encoding)
25
+ str.force_encoding(Encoding::UTF_8)
26
+ else
27
+ str
28
+ end
29
+ end
30
+
19
31
  #
20
32
  # Additional matchers
21
33
  #
22
34
 
23
- def util_bad_token(s, *args)
35
+ def refute_scanned(s, *args)
24
36
  assert_raises Parser::SyntaxError do
25
- util_lex_token(s, *args)
37
+ assert_scanned(s, *args)
26
38
  end
27
39
  end
28
40
 
29
- def util_escape(expected, input)
30
- source_buffer = Parser::Source::Buffer.new('(util_escape)')
31
- source_buffer.source = "\"\\#{input}\""
41
+ def assert_escape(expected, input)
42
+ source_buffer = Parser::Source::Buffer.new('(assert_escape)')
43
+
44
+ if defined?(Encoding)
45
+ source_buffer.source = "\"\\#{input}\"".encode(input.encoding)
46
+ else
47
+ source_buffer.source = "\"\\#{input}\""
48
+ end
32
49
 
33
50
  @lex.reset
34
51
  @lex.source_buffer = source_buffer
@@ -36,7 +53,7 @@ class TestLexer < Minitest::Test
36
53
  lex_token, (lex_value, *) = @lex.advance
37
54
 
38
55
  if lex_value.respond_to?(:force_encoding)
39
- lex_value.force_encoding('ASCII-8BIT')
56
+ lex_value.force_encoding(Encoding::BINARY)
40
57
  end
41
58
 
42
59
  assert_equal [:tSTRING, expected],
@@ -44,21 +61,21 @@ class TestLexer < Minitest::Test
44
61
  source_buffer.source
45
62
  end
46
63
 
47
- def util_escape_bad(input)
64
+ def refute_escape(input)
48
65
  assert_raises Parser::SyntaxError do
49
66
  @lex.state = :expr_beg
50
- util_lex_token "%Q[\\#{input}]"
67
+ assert_scanned "%Q[\\#{input}]"
51
68
  end
52
69
  end
53
70
 
54
- def util_lex_fname(name, type)
55
- util_lex_token("def #{name} ", :kDEF, 'def', type, name)
71
+ def assert_lex_fname(name, type)
72
+ assert_scanned("def #{name} ", :kDEF, 'def', type, name)
56
73
 
57
74
  assert_equal :expr_endfn, @lex.state
58
75
  end
59
76
 
60
- def util_lex_token(input, *args)
61
- source_buffer = Parser::Source::Buffer.new('(util_lex_token)')
77
+ def assert_scanned(input, *args)
78
+ source_buffer = Parser::Source::Buffer.new('(assert_scanned)')
62
79
  source_buffer.source = input
63
80
 
64
81
  @lex.reset(false)
@@ -81,103 +98,107 @@ class TestLexer < Minitest::Test
81
98
  #
82
99
 
83
100
  def test_read_escape
84
- util_escape "\\", "\\"
85
- util_escape "\n", "n"
86
- util_escape "\t", "t"
87
- util_escape "\r", "r"
88
- util_escape "\f", "f"
89
- util_escape "\13", "v"
90
- util_escape "\0", "0"
91
- util_escape "\07", "a"
92
- util_escape "\007", "a"
93
- util_escape "\033", "e"
94
- util_escape "\377", "377"
95
- util_escape "\377", "xff"
96
- util_escape "\010", "b"
97
- util_escape " ", "s"
98
- util_escape "q", "q" # plain vanilla escape
101
+ assert_escape "\\", "\\"
102
+ assert_escape "\n", "n"
103
+ assert_escape "\t", "t"
104
+ assert_escape "\r", "r"
105
+ assert_escape "\f", "f"
106
+ assert_escape "\13", "v"
107
+ assert_escape "\0", "0"
108
+ assert_escape "\07", "a"
109
+ assert_escape "\007", "a"
110
+ assert_escape "\033", "e"
111
+ assert_escape "\377", "377"
112
+ assert_escape "\377", "xff"
113
+ assert_escape "\010", "b"
114
+ assert_escape " ", "s"
115
+ assert_escape "q", "q" # plain vanilla escape
99
116
  end
100
117
 
101
118
  def test_read_escape_c
102
- util_escape "\030", "C-x"
103
- util_escape "\030", "cx"
104
- util_escape "\230", 'C-\M-x'
105
- util_escape "\230", 'c\M-x'
119
+ assert_escape "\030", "C-x"
120
+ assert_escape "\030", "cx"
121
+ assert_escape "\230", 'C-\M-x'
122
+ assert_escape "\230", 'c\M-x'
106
123
 
107
- util_escape "\177", "C-?"
108
- util_escape "\177", "c?"
124
+ assert_escape "\177", "C-?"
125
+ assert_escape "\177", "c?"
126
+ assert_escape "\r", "cM"
109
127
  end
110
128
 
111
129
  def test_read_escape_m
112
- util_escape "\370", "M-x"
113
- util_escape "\230", 'M-\C-x'
114
- util_escape "\230", 'M-\cx'
130
+ assert_escape "\370", "M-x"
131
+ assert_escape "\230", 'M-\C-x'
132
+ assert_escape "\230", 'M-\cx'
115
133
  end
116
134
 
117
135
  def test_read_escape_errors
118
- util_escape_bad ""
136
+ refute_escape ""
119
137
 
120
- util_escape_bad "M"
121
- util_escape_bad "M-"
122
- util_escape_bad "Mx"
138
+ refute_escape "M"
139
+ refute_escape "M-"
140
+ refute_escape "Mx"
123
141
 
124
- util_escape_bad "Cx"
125
- util_escape_bad "C"
126
- util_escape_bad "C-"
142
+ refute_escape "Cx"
143
+ refute_escape "C"
144
+ refute_escape "C-"
127
145
 
128
- util_escape_bad "c"
146
+ refute_escape "c"
129
147
  end
130
148
 
131
149
  def test_read_escape_unicode__19
132
150
  if RUBY_VERSION >= '1.9'
133
- util_escape "\xc4\xa3", 'u0123'
151
+ assert_escape "\x09", 'u{9}'
152
+ assert_escape "\x31", 'u{31}'
153
+ assert_escape "\x09\x01", 'u{9 1}'
134
154
 
135
- util_escape "\xc4\xa3\xc3\xb0\xeb\x84\xa3", 'u{123 f0 B123}'
155
+ assert_escape "\xc4\xa3", utf('u0123')
156
+ assert_escape "\xc4\xa3\xc3\xb0\xeb\x84\xa3", utf('u{123 f0 B123}')
136
157
  end
137
158
  end
138
159
 
139
160
  def test_read_escape_unicode_bad__19
140
161
  if RUBY_VERSION >= '1.9'
141
- util_escape_bad 'u123'
142
- util_escape_bad 'u{}'
143
- util_escape_bad 'u{123 f0h}'
144
- util_escape_bad 'u{123 f0'
162
+ refute_escape 'u123'
163
+ refute_escape 'u{}'
164
+ refute_escape 'u{123 f0h}'
165
+ refute_escape 'u{123 f0'
145
166
  end
146
167
  end
147
168
 
148
169
  def test_ambiguous_uminus
149
- util_lex_token("m -3",
170
+ assert_scanned("m -3",
150
171
  :tIDENTIFIER, "m",
151
172
  :tUMINUS_NUM, "-",
152
173
  :tINTEGER, 3)
153
174
  end
154
175
 
155
176
  def test_ambiguous_uplus
156
- util_lex_token("m +3",
177
+ assert_scanned("m +3",
157
178
  :tIDENTIFIER, "m",
158
179
  :tINTEGER, 3)
159
180
  end
160
181
 
161
182
  def test_and
162
- util_lex_token "&", :tAMPER, "&"
183
+ assert_scanned "&", :tAMPER, "&"
163
184
  end
164
185
 
165
186
  def test_and2
166
187
  @lex.state = :expr_end
167
188
 
168
- util_lex_token "&&", :tANDOP, "&&"
189
+ assert_scanned "&&", :tANDOP, "&&"
169
190
  end
170
191
 
171
192
  def test_and2_equals
172
193
  @lex.state = :expr_end
173
194
 
174
- util_lex_token "&&=", :tOP_ASGN, "&&"
195
+ assert_scanned "&&=", :tOP_ASGN, "&&"
175
196
  end
176
197
 
177
198
  def test_and_arg
178
199
  @lex.state = :expr_arg
179
200
 
180
- util_lex_token(" &y",
201
+ assert_scanned(" &y",
181
202
  :tAMPER, "&",
182
203
  :tIDENTIFIER, "y")
183
204
  end
@@ -185,35 +206,35 @@ class TestLexer < Minitest::Test
185
206
  def test_and_equals
186
207
  @lex.state = :expr_end
187
208
 
188
- util_lex_token "&=", :tOP_ASGN, "&"
209
+ assert_scanned "&=", :tOP_ASGN, "&"
189
210
  end
190
211
 
191
212
  def test_and_expr
192
213
  @lex.state = :expr_arg
193
214
 
194
- util_lex_token("x & y",
215
+ assert_scanned("x & y",
195
216
  :tIDENTIFIER, "x",
196
217
  :tAMPER2, "&",
197
218
  :tIDENTIFIER, "y")
198
219
  end
199
220
 
200
221
  def test_and_meth
201
- util_lex_fname "&", :tAMPER2
222
+ assert_lex_fname "&", :tAMPER2
202
223
  end
203
224
 
204
225
  def test_assoc
205
- util_lex_token "=>", :tASSOC, "=>"
226
+ assert_scanned "=>", :tASSOC, "=>"
206
227
  end
207
228
 
208
229
  def test_label__18
209
- util_lex_token("{a:b",
230
+ assert_scanned("{a:b",
210
231
  :tLBRACE, "{",
211
232
  :tIDENTIFIER, "a",
212
233
  :tSYMBOL, "b")
213
234
  end
214
235
 
215
236
  def test_label_in_params__18
216
- util_lex_token("foo(a:b",
237
+ assert_scanned("foo(a:b",
217
238
  :tIDENTIFIER, "foo",
218
239
  :tLPAREN2, "(",
219
240
  :tIDENTIFIER, "a",
@@ -223,7 +244,7 @@ class TestLexer < Minitest::Test
223
244
  def test_label__19
224
245
  setup_lexer 19
225
246
 
226
- util_lex_token("{a:b",
247
+ assert_scanned("{a:b",
227
248
  :tLBRACE, "{",
228
249
  :tLABEL, "a",
229
250
  :tIDENTIFIER, "b")
@@ -232,7 +253,7 @@ class TestLexer < Minitest::Test
232
253
  def test_label_in_params__19
233
254
  setup_lexer 19
234
255
 
235
- util_lex_token("foo(a:b",
256
+ assert_scanned("foo(a:b",
236
257
  :tIDENTIFIER, "foo",
237
258
  :tLPAREN2, "(",
238
259
  :tLABEL, "a",
@@ -242,7 +263,7 @@ class TestLexer < Minitest::Test
242
263
  def test_label_fid__19
243
264
  setup_lexer 19
244
265
 
245
- util_lex_token("{a?:true",
266
+ assert_scanned("{a?:true",
246
267
  :tLBRACE, '{',
247
268
  :tLABEL, 'a?',
248
269
  :kTRUE, 'true')
@@ -256,7 +277,7 @@ class TestLexer < Minitest::Test
256
277
  token = "k#{keyword.upcase}".to_sym
257
278
 
258
279
  @lex.reset
259
- util_lex_token("#{keyword} a:b",
280
+ assert_scanned("#{keyword} a:b",
260
281
  token, keyword,
261
282
  :tIDENTIFIER, "a",
262
283
  :tSYMBOL, "b")
@@ -270,7 +291,7 @@ class TestLexer < Minitest::Test
270
291
  token = "k#{keyword.upcase}_MOD".to_sym
271
292
 
272
293
  @lex.state = :expr_end
273
- util_lex_token("#{keyword} a:b",
294
+ assert_scanned("#{keyword} a:b",
274
295
  token, keyword,
275
296
  :tLABEL, "a",
276
297
  :tIDENTIFIER, "b")
@@ -278,7 +299,7 @@ class TestLexer < Minitest::Test
278
299
  end
279
300
 
280
301
  def test_back_ref
281
- util_lex_token("[$&, $`, $', $+]",
302
+ assert_scanned("[$&, $`, $', $+]",
282
303
  :tLBRACK, "[",
283
304
  :tBACK_REF, "$&", :tCOMMA, ",",
284
305
  :tBACK_REF, "$`", :tCOMMA, ",",
@@ -288,19 +309,19 @@ class TestLexer < Minitest::Test
288
309
  end
289
310
 
290
311
  def test_backslash
291
- util_lex_token("1 \\\n+ 2",
312
+ assert_scanned("1 \\\n+ 2",
292
313
  :tINTEGER, 1,
293
314
  :tPLUS, "+",
294
315
  :tINTEGER, 2)
295
316
  end
296
317
 
297
318
  def test_backslash_bad
298
- util_bad_token("1 \\ + 2",
319
+ refute_scanned("1 \\ + 2",
299
320
  :tINTEGER, 1)
300
321
  end
301
322
 
302
323
  def test_backtick
303
- util_lex_token("`ls`",
324
+ assert_scanned("`ls`",
304
325
  :tXSTRING_BEG, "`",
305
326
  :tSTRING_CONTENT, "ls",
306
327
  :tSTRING_END, "`")
@@ -308,14 +329,14 @@ class TestLexer < Minitest::Test
308
329
 
309
330
  def test_backtick_cmdarg
310
331
  @lex.state = :expr_dot
311
- util_lex_token("\n`", :tBACK_REF2, "`") # \n ensures expr_cmd
332
+ assert_scanned("\n`", :tBACK_REF2, "`") # \n ensures expr_cmd
312
333
 
313
334
  assert_equal :expr_arg, @lex.state
314
335
  end
315
336
 
316
337
  def test_backtick_dot
317
338
  @lex.state = :expr_dot
318
- util_lex_token("a.`(3)",
339
+ assert_scanned("a.`(3)",
319
340
  :tIDENTIFIER, "a",
320
341
  :tDOT, ".",
321
342
  :tBACK_REF2, "`",
@@ -326,70 +347,70 @@ class TestLexer < Minitest::Test
326
347
 
327
348
  def test_backtick_method
328
349
  @lex.state = :expr_fname
329
- util_lex_token("`", :tBACK_REF2, "`")
350
+ assert_scanned("`", :tBACK_REF2, "`")
330
351
  assert_equal :expr_endfn, @lex.state
331
352
  end
332
353
 
333
354
  def test_bad_char
334
- util_bad_token(" \010 ")
355
+ refute_scanned(" \010 ")
335
356
  end
336
357
 
337
358
  def test_bang
338
- util_lex_token "!", :tBANG, "!"
359
+ assert_scanned "!", :tBANG, "!"
339
360
  end
340
361
 
341
362
  def test_bang_equals
342
- util_lex_token "!=", :tNEQ, "!="
363
+ assert_scanned "!=", :tNEQ, "!="
343
364
  end
344
365
 
345
366
  def test_bang_tilde
346
- util_lex_token "!~", :tNMATCH, "!~"
367
+ assert_scanned "!~", :tNMATCH, "!~"
347
368
  end
348
369
 
349
370
  def test_def_ubang
350
371
  setup_lexer(20)
351
372
 
352
373
  @lex.state = :expr_fname
353
- util_lex_token '!@', :tBANG, '!@'
374
+ assert_scanned '!@', :tBANG, '!@'
354
375
  end
355
376
 
356
377
  def test_carat
357
- util_lex_token "^", :tCARET, "^"
378
+ assert_scanned "^", :tCARET, "^"
358
379
  end
359
380
 
360
381
  def test_carat_equals
361
- util_lex_token "^=", :tOP_ASGN, "^"
382
+ assert_scanned "^=", :tOP_ASGN, "^"
362
383
  end
363
384
 
364
385
  def test_colon2
365
- util_lex_token("A::B",
386
+ assert_scanned("A::B",
366
387
  :tCONSTANT, "A",
367
388
  :tCOLON2, "::",
368
389
  :tCONSTANT, "B")
369
390
 
370
391
  @lex.state = :expr_arg
371
- util_lex_token("::Array",
392
+ assert_scanned("::Array",
372
393
  :tCOLON2, "::",
373
394
  :tCONSTANT, "Array")
374
395
  end
375
396
 
376
397
  def test_colon3
377
- util_lex_token("::Array",
398
+ assert_scanned("::Array",
378
399
  :tCOLON3, "::",
379
400
  :tCONSTANT, "Array")
380
401
 
381
402
  @lex.state = :expr_arg
382
- util_lex_token(" ::Array",
403
+ assert_scanned(" ::Array",
383
404
  :tCOLON3, "::",
384
405
  :tCONSTANT, "Array")
385
406
  end
386
407
 
387
408
  def test_comma
388
- util_lex_token ",", :tCOMMA, ","
409
+ assert_scanned ",", :tCOMMA, ","
389
410
  end
390
411
 
391
412
  def test_comment
392
- util_lex_token("1 # one\n# two\n2",
413
+ assert_scanned("1 # one\n# two\n2",
393
414
  :tINTEGER, 1,
394
415
  :tNL, nil,
395
416
  :tINTEGER, 2)
@@ -400,24 +421,24 @@ class TestLexer < Minitest::Test
400
421
  end
401
422
 
402
423
  def test_comment_expr_beg
403
- util_lex_token("{#1\n}",
424
+ assert_scanned("{#1\n}",
404
425
  :tLBRACE, "{",
405
426
  :tRCURLY, "}")
406
427
  end
407
428
 
408
429
  def test_comment_begin
409
- util_lex_token("=begin\nblah\nblah\n=end\n42",
430
+ assert_scanned("=begin\nblah\nblah\n=end\n42",
410
431
  :tINTEGER, 42)
411
432
  assert_equal 1, @lex.comments.length
412
433
  assert_equal "=begin\nblah\nblah\n=end\n", @lex.comments[0].text
413
434
  end
414
435
 
415
436
  def test_comment_begin_bad
416
- util_bad_token("=begin\nblah\nblah\n")
437
+ refute_scanned("=begin\nblah\nblah\n")
417
438
  end
418
439
 
419
440
  def test_comment_begin_not_comment
420
- util_lex_token("beginfoo = 5\np x \\\n=beginfoo",
441
+ assert_scanned("beginfoo = 5\np x \\\n=beginfoo",
421
442
  :tIDENTIFIER, "beginfoo",
422
443
  :tEQL, "=",
423
444
  :tINTEGER, 5,
@@ -429,58 +450,58 @@ class TestLexer < Minitest::Test
429
450
  end
430
451
 
431
452
  def test_comment_begin_space
432
- util_lex_token("=begin blah\nblah\n=end\n")
453
+ assert_scanned("=begin blah\nblah\n=end\n")
433
454
 
434
455
  assert_equal 1, @lex.comments.length
435
456
  assert_equal "=begin blah\nblah\n=end\n", @lex.comments[0].text
436
457
  end
437
458
 
438
459
  def test_comment_end_space_and_text
439
- util_lex_token("=begin blah\nblah\n=end blab\n")
460
+ assert_scanned("=begin blah\nblah\n=end blab\n")
440
461
 
441
462
  assert_equal 1, @lex.comments.length
442
463
  assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments[0].text
443
464
  end
444
465
 
445
466
  def test_comment_eos
446
- util_lex_token("# comment")
467
+ assert_scanned("# comment")
447
468
  end
448
469
 
449
470
  def test_constant
450
- util_lex_token("ArgumentError",
471
+ assert_scanned("ArgumentError",
451
472
  :tCONSTANT, "ArgumentError")
452
473
  end
453
474
 
454
475
  def test_constant_semi
455
- util_lex_token("ArgumentError;",
476
+ assert_scanned("ArgumentError;",
456
477
  :tCONSTANT, "ArgumentError",
457
478
  :tSEMI, ";")
458
479
  end
459
480
 
460
481
  def test_cvar
461
- util_lex_token "@@blah", :tCVAR, "@@blah"
482
+ assert_scanned "@@blah", :tCVAR, "@@blah"
462
483
  end
463
484
 
464
485
  def test_cvar_bad
465
- util_bad_token "@@1"
486
+ refute_scanned "@@1"
466
487
  end
467
488
 
468
489
  def test_div
469
- util_lex_token("a / 2",
490
+ assert_scanned("a / 2",
470
491
  :tIDENTIFIER, "a",
471
492
  :tDIVIDE, "/",
472
493
  :tINTEGER, 2)
473
494
  end
474
495
 
475
496
  def test_div_equals
476
- util_lex_token("a /= 2",
497
+ assert_scanned("a /= 2",
477
498
  :tIDENTIFIER, "a",
478
499
  :tOP_ASGN, "/",
479
500
  :tINTEGER, 2)
480
501
  end
481
502
 
482
503
  def test_do
483
- util_lex_token("x do 42 end",
504
+ assert_scanned("x do 42 end",
484
505
  :tIDENTIFIER, "x",
485
506
  :kDO, "do",
486
507
  :tINTEGER, 42,
@@ -490,7 +511,7 @@ class TestLexer < Minitest::Test
490
511
  def test_do_cond
491
512
  @lex.cond.push(true)
492
513
 
493
- util_lex_token("x do 42 end",
514
+ assert_scanned("x do 42 end",
494
515
  :tIDENTIFIER, "x",
495
516
  :kDO_COND, "do",
496
517
  :tINTEGER, 42,
@@ -500,7 +521,7 @@ class TestLexer < Minitest::Test
500
521
  def test_do_block
501
522
  @lex.state = :expr_endarg
502
523
 
503
- util_lex_token("do 42 end",
524
+ assert_scanned("do 42 end",
504
525
  :kDO_BLOCK, "do",
505
526
  :tINTEGER, 42,
506
527
  :kEND, "end")
@@ -509,7 +530,7 @@ class TestLexer < Minitest::Test
509
530
  def test_do_cond
510
531
  @lex.cond.push true
511
532
 
512
- util_lex_token("x do 42 end",
533
+ assert_scanned("x do 42 end",
513
534
  :tIDENTIFIER, "x",
514
535
  :kDO_COND, "do",
515
536
  :tINTEGER, 42,
@@ -517,150 +538,150 @@ class TestLexer < Minitest::Test
517
538
  end
518
539
 
519
540
  def test_dot
520
- util_lex_token ".", :tDOT, "."
541
+ assert_scanned ".", :tDOT, "."
521
542
  end
522
543
 
523
544
  def test_dot2
524
- util_lex_token "..", :tDOT2, ".."
545
+ assert_scanned "..", :tDOT2, ".."
525
546
  end
526
547
 
527
548
  def test_dot3
528
- util_lex_token "...", :tDOT3, "..."
549
+ assert_scanned "...", :tDOT3, "..."
529
550
  end
530
551
 
531
552
  def test_equals
532
- util_lex_token "=", :tEQL, "="
553
+ assert_scanned "=", :tEQL, "="
533
554
  end
534
555
 
535
556
  def test_equals2
536
- util_lex_token "==", :tEQ, "=="
557
+ assert_scanned "==", :tEQ, "=="
537
558
  end
538
559
 
539
560
  def test_equals3
540
- util_lex_token "===", :tEQQ, "==="
561
+ assert_scanned "===", :tEQQ, "==="
541
562
  end
542
563
 
543
564
  def test_equals_tilde
544
- util_lex_token "=~", :tMATCH, "=~"
565
+ assert_scanned "=~", :tMATCH, "=~"
545
566
  end
546
567
 
547
568
  def test_float
548
- util_lex_token "1.0", :tFLOAT, 1.0
569
+ assert_scanned "1.0", :tFLOAT, 1.0
549
570
  end
550
571
 
551
572
  def test_float_bad_no_underscores
552
- util_bad_token "1__0.0"
573
+ refute_scanned "1__0.0"
553
574
  end
554
575
 
555
576
  def test_float_bad_no_zero_leading
556
- util_bad_token ".0"
577
+ refute_scanned ".0"
557
578
  end
558
579
 
559
580
  def test_float_bad_trailing_underscore
560
- util_bad_token "123_.0"
581
+ refute_scanned "123_.0"
561
582
  end
562
583
 
563
584
  def test_float_call
564
- util_lex_token("1.0.to_s",
585
+ assert_scanned("1.0.to_s",
565
586
  :tFLOAT, 1.0,
566
587
  :tDOT, ".",
567
588
  :tIDENTIFIER, "to_s")
568
589
  end
569
590
 
570
591
  def test_float_dot_E
571
- util_lex_token "1.0E10", :tFLOAT, 1.0e10
592
+ assert_scanned "1.0E10", :tFLOAT, 1.0e10
572
593
  end
573
594
 
574
595
  def test_float_dot_E_neg
575
- util_lex_token("-1.0E10",
596
+ assert_scanned("-1.0E10",
576
597
  :tUMINUS_NUM, "-",
577
598
  :tFLOAT, 1.0e10)
578
599
  end
579
600
 
580
601
  def test_float_dot_e
581
- util_lex_token "1.0e10", :tFLOAT, 1.0e10
602
+ assert_scanned "1.0e10", :tFLOAT, 1.0e10
582
603
  end
583
604
 
584
605
  def test_float_dot_e_neg
585
- util_lex_token("-1.0e10",
606
+ assert_scanned("-1.0e10",
586
607
  :tUMINUS_NUM, "-",
587
608
  :tFLOAT, 1.0e10)
588
609
  end
589
610
 
590
611
  def test_float_e
591
- util_lex_token "1e10", :tFLOAT, 1e10
612
+ assert_scanned "1e10", :tFLOAT, 1e10
592
613
  end
593
614
 
594
615
  def test_float_e_bad_trailing_underscore
595
- util_bad_token "123_e10"
616
+ refute_scanned "123_e10"
596
617
  end
597
618
 
598
619
  def test_float_e_minus
599
- util_lex_token "1e-10", :tFLOAT, 1e-10
620
+ assert_scanned "1e-10", :tFLOAT, 1e-10
600
621
  end
601
622
 
602
623
  def test_float_e_neg
603
- util_lex_token("-1e10",
624
+ assert_scanned("-1e10",
604
625
  :tUMINUS_NUM, "-",
605
626
  :tFLOAT, 1e10)
606
627
  end
607
628
 
608
629
  def test_float_e_neg_minus
609
- util_lex_token("-1e-10",
630
+ assert_scanned("-1e-10",
610
631
  :tUMINUS_NUM, "-",
611
632
  :tFLOAT, 1e-10)
612
633
  end
613
634
 
614
635
  def test_float_e_neg_plus
615
- util_lex_token("-1e+10",
636
+ assert_scanned("-1e+10",
616
637
  :tUMINUS_NUM, "-",
617
638
  :tFLOAT, 1e10)
618
639
  end
619
640
 
620
641
  def test_float_e_plus
621
- util_lex_token "1e+10", :tFLOAT, 1e10
642
+ assert_scanned "1e+10", :tFLOAT, 1e10
622
643
  end
623
644
 
624
645
  def test_float_e_zero
625
- util_lex_token "0e0", :tFLOAT, 0e0
646
+ assert_scanned "0e0", :tFLOAT, 0e0
626
647
  end
627
648
 
628
649
  def test_float_neg
629
- util_lex_token("-1.0",
650
+ assert_scanned("-1.0",
630
651
  :tUMINUS_NUM, "-",
631
652
  :tFLOAT, 1.0)
632
653
  end
633
654
 
634
655
  def test_ge
635
- util_lex_token("a >= 2",
656
+ assert_scanned("a >= 2",
636
657
  :tIDENTIFIER, "a",
637
658
  :tGEQ, ">=",
638
659
  :tINTEGER, 2)
639
660
  end
640
661
 
641
662
  def test_global
642
- util_lex_token("$blah", :tGVAR, "$blah")
663
+ assert_scanned("$blah", :tGVAR, "$blah")
643
664
  end
644
665
 
645
666
  def test_global_backref
646
- util_lex_token("$`", :tBACK_REF, "$`")
667
+ assert_scanned("$`", :tBACK_REF, "$`")
647
668
  end
648
669
 
649
670
  # This was removed in 2.1.
650
671
  # def test_global_dash_nothing
651
- # util_lex_token("$- ", :tGVAR, "$-")
672
+ # assert_scanned("$- ", :tGVAR, "$-")
652
673
  # end
653
674
 
654
675
  def test_global_dash_something
655
- util_lex_token("$-x", :tGVAR, "$-x")
676
+ assert_scanned("$-x", :tGVAR, "$-x")
656
677
  end
657
678
 
658
679
  def test_global_number
659
- util_lex_token("$10", :tNTH_REF, 10)
680
+ assert_scanned("$10", :tNTH_REF, 10)
660
681
  end
661
682
 
662
683
  def test_global_other
663
- util_lex_token("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
684
+ assert_scanned("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
664
685
  :tLBRACK, "[",
665
686
  :tGVAR, "$~", :tCOMMA, ",",
666
687
  :tGVAR, "$*", :tCOMMA, ",",
@@ -682,28 +703,28 @@ class TestLexer < Minitest::Test
682
703
  end
683
704
 
684
705
  def test_global_underscore
685
- util_lex_token("$_",
706
+ assert_scanned("$_",
686
707
  :tGVAR, "$_")
687
708
  end
688
709
 
689
710
  def test_global_wierd
690
- util_lex_token("$__blah",
711
+ assert_scanned("$__blah",
691
712
  :tGVAR, "$__blah")
692
713
  end
693
714
 
694
715
  def test_global_zero
695
- util_lex_token("$0", :tGVAR, "$0")
716
+ assert_scanned("$0", :tGVAR, "$0")
696
717
  end
697
718
 
698
719
  def test_gt
699
- util_lex_token("a > 2",
720
+ assert_scanned("a > 2",
700
721
  :tIDENTIFIER, "a",
701
722
  :tGT, ">",
702
723
  :tINTEGER, 2)
703
724
  end
704
725
 
705
726
  def test_heredoc_backtick
706
- util_lex_token("a = <<`EOF`\n blah blah\nEOF\n",
727
+ assert_scanned("a = <<`EOF`\n blah blah\nEOF\n",
707
728
  :tIDENTIFIER, "a",
708
729
  :tEQL, "=",
709
730
  :tXSTRING_BEG, "`",
@@ -713,7 +734,7 @@ class TestLexer < Minitest::Test
713
734
  end
714
735
 
715
736
  def test_heredoc_double
716
- util_lex_token("a = <<\"EOF\"\n blah blah\nEOF\n",
737
+ assert_scanned("a = <<\"EOF\"\n blah blah\nEOF\n",
717
738
  :tIDENTIFIER, "a",
718
739
  :tEQL, "=",
719
740
  :tSTRING_BEG, "\"",
@@ -723,7 +744,7 @@ class TestLexer < Minitest::Test
723
744
  end
724
745
 
725
746
  def test_heredoc_double_dash
726
- util_lex_token("a = <<-\"EOF\"\n blah blah\n EOF\n",
747
+ assert_scanned("a = <<-\"EOF\"\n blah blah\n EOF\n",
727
748
  :tIDENTIFIER, "a",
728
749
  :tEQL, "=",
729
750
  :tSTRING_BEG, "\"",
@@ -733,21 +754,21 @@ class TestLexer < Minitest::Test
733
754
  end
734
755
 
735
756
  def test_heredoc_double_eos
736
- util_bad_token("a = <<\"EOF\"\nblah",
757
+ refute_scanned("a = <<\"EOF\"\nblah",
737
758
  :tIDENTIFIER, "a",
738
759
  :tEQL, "=",
739
760
  :tSTRING_BEG, "\"")
740
761
  end
741
762
 
742
763
  def test_heredoc_double_eos_nl
743
- util_bad_token("a = <<\"EOF\"\nblah\n",
764
+ refute_scanned("a = <<\"EOF\"\nblah\n",
744
765
  :tIDENTIFIER, "a",
745
766
  :tEQL, "=",
746
767
  :tSTRING_BEG, "\"")
747
768
  end
748
769
 
749
770
  def test_heredoc_double_interp
750
- util_lex_token("a = <<\"EOF\"\n#x a \#@a b \#$b c \#{3} \nEOF\n",
771
+ assert_scanned("a = <<\"EOF\"\n#x a \#@a b \#$b c \#{3} \nEOF\n",
751
772
  :tIDENTIFIER, "a",
752
773
  :tEQL, "=",
753
774
  :tSTRING_BEG, "\"",
@@ -767,7 +788,7 @@ class TestLexer < Minitest::Test
767
788
  end
768
789
 
769
790
  def test_heredoc_empty
770
- util_lex_token("<<\"\"\n\#{x}\nblah2\n\n",
791
+ assert_scanned("<<\"\"\n\#{x}\nblah2\n\n",
771
792
  :tSTRING_BEG, "\"",
772
793
  :tSTRING_DBEG, "\#{",
773
794
  :tIDENTIFIER, "x",
@@ -779,7 +800,7 @@ class TestLexer < Minitest::Test
779
800
  end
780
801
 
781
802
  def test_heredoc_none
782
- util_lex_token("a = <<EOF\nblah\nblah\nEOF",
803
+ assert_scanned("a = <<EOF\nblah\nblah\nEOF",
783
804
  :tIDENTIFIER, "a",
784
805
  :tEQL, "=",
785
806
  :tSTRING_BEG, "\"",
@@ -790,7 +811,7 @@ class TestLexer < Minitest::Test
790
811
  end
791
812
 
792
813
  def test_heredoc_none_dash
793
- util_lex_token("a = <<-EOF\nblah\nblah\n EOF",
814
+ assert_scanned("a = <<-EOF\nblah\nblah\n EOF",
794
815
  :tIDENTIFIER, "a",
795
816
  :tEQL, "=",
796
817
  :tSTRING_BEG, "\"",
@@ -801,7 +822,7 @@ class TestLexer < Minitest::Test
801
822
  end
802
823
 
803
824
  def test_heredoc_single
804
- util_lex_token("a = <<'EOF'\n blah blah\nEOF\n",
825
+ assert_scanned("a = <<'EOF'\n blah blah\nEOF\n",
805
826
  :tIDENTIFIER, "a",
806
827
  :tEQL, "=",
807
828
  :tSTRING_BEG, "'",
@@ -811,14 +832,14 @@ class TestLexer < Minitest::Test
811
832
  end
812
833
 
813
834
  def test_heredoc_single_bad_eos_body
814
- util_bad_token("a = <<'EOF'\nblah",
835
+ refute_scanned("a = <<'EOF'\nblah",
815
836
  :tIDENTIFIER, "a",
816
837
  :tEQL, "=",
817
838
  :tSTRING_BEG, "'")
818
839
  end
819
840
 
820
841
  def test_heredoc_single_dash
821
- util_lex_token("a = <<-'EOF'\n blah blah\n EOF\n",
842
+ assert_scanned("a = <<-'EOF'\n blah blah\n EOF\n",
822
843
  :tIDENTIFIER, "a",
823
844
  :tEQL, "=",
824
845
  :tSTRING_BEG, "'",
@@ -828,7 +849,7 @@ class TestLexer < Minitest::Test
828
849
  end
829
850
 
830
851
  def test_heredoc_one_character
831
- util_lex_token("a = <<E\nABCDEF\nE\n",
852
+ assert_scanned("a = <<E\nABCDEF\nE\n",
832
853
  :tIDENTIFIER, "a",
833
854
  :tEQL, "=",
834
855
  :tSTRING_BEG, "\"",
@@ -837,66 +858,76 @@ class TestLexer < Minitest::Test
837
858
  :tNL, nil)
838
859
  end
839
860
 
861
+ def test_heredoc_cr
862
+ assert_scanned("a = <<E\r\r\nABCDEF\r\r\nE\r\r\r\n",
863
+ :tIDENTIFIER, "a",
864
+ :tEQL, "=",
865
+ :tSTRING_BEG, "\"",
866
+ :tSTRING_CONTENT, "ABCDEF\r\n",
867
+ :tSTRING_END, "E",
868
+ :tNL, nil)
869
+ end
870
+
840
871
  def test_identifier
841
- util_lex_token("identifier", :tIDENTIFIER, "identifier")
872
+ assert_scanned("identifier", :tIDENTIFIER, "identifier")
842
873
  end
843
874
 
844
875
  def test_identifier_bang
845
- util_lex_token("identifier!",
876
+ assert_scanned("identifier!",
846
877
  :tFID, "identifier!")
847
878
 
848
- util_lex_token("identifier!=",
879
+ assert_scanned("identifier!=",
849
880
  :tFID, "identifier",
850
881
  :tNEQ, "!=")
851
882
  end
852
883
 
853
884
  def test_identifier_cmp
854
- util_lex_fname "<=>", :tCMP
885
+ assert_lex_fname "<=>", :tCMP
855
886
  end
856
887
 
857
888
  def test_identifier_def
858
- util_lex_fname "identifier", :tIDENTIFIER
889
+ assert_lex_fname "identifier", :tIDENTIFIER
859
890
  end
860
891
 
861
892
  def test_identifier_eh
862
- util_lex_token("identifier?", :tFID, "identifier?")
893
+ assert_scanned("identifier?", :tFID, "identifier?")
863
894
  end
864
895
 
865
896
  def test_identifier_equals_arrow
866
- util_lex_token(":blah==>",
897
+ assert_scanned(":blah==>",
867
898
  :tSYMBOL, "blah=",
868
899
  :tASSOC, "=>")
869
900
  end
870
901
 
871
902
  def test_identifier_equals3
872
- util_lex_token(":a===b",
903
+ assert_scanned(":a===b",
873
904
  :tSYMBOL, "a",
874
905
  :tEQQ, "===",
875
906
  :tIDENTIFIER, "b")
876
907
  end
877
908
 
878
909
  def test_identifier_equals_equals_arrow
879
- util_lex_token(":a==>b",
910
+ assert_scanned(":a==>b",
880
911
  :tSYMBOL, "a=",
881
912
  :tASSOC, "=>",
882
913
  :tIDENTIFIER, "b")
883
914
  end
884
915
 
885
916
  def test_identifier_equals_caret
886
- util_lex_fname "^", :tCARET
917
+ assert_lex_fname "^", :tCARET
887
918
  end
888
919
 
889
920
  def test_identifier_equals_def
890
- util_lex_fname "identifier=", :tIDENTIFIER
921
+ assert_lex_fname "identifier=", :tIDENTIFIER
891
922
  end
892
923
 
893
924
  def test_identifier_equals_def2
894
- util_lex_fname "==", :tEQ
925
+ assert_lex_fname "==", :tEQ
895
926
  end
896
927
 
897
928
  def test_identifier_equals_expr
898
929
  @lex.state = :expr_dot
899
- util_lex_token("y = arg",
930
+ assert_scanned("y = arg",
900
931
  :tIDENTIFIER, "y",
901
932
  :tEQL, "=",
902
933
  :tIDENTIFIER, "arg")
@@ -905,205 +936,209 @@ class TestLexer < Minitest::Test
905
936
  end
906
937
 
907
938
  def test_identifier_equals_or
908
- util_lex_fname "|", :tPIPE
939
+ assert_lex_fname "|", :tPIPE
909
940
  end
910
941
 
911
942
  def test_identifier_equals_slash
912
- util_lex_fname "/", :tDIVIDE
943
+ assert_lex_fname "/", :tDIVIDE
913
944
  end
914
945
 
915
946
  def test_identifier_equals_tilde
916
947
  @lex.state = :expr_fname
917
- util_lex_token("identifier=~",
948
+ assert_scanned("identifier=~",
918
949
  :tIDENTIFIER, "identifier=",
919
950
  :tTILDE, "~")
920
951
  end
921
952
 
922
953
  def test_identifier_gt
923
- util_lex_fname ">", :tGT
954
+ assert_lex_fname ">", :tGT
924
955
  end
925
956
 
926
957
  def test_identifier_le
927
- util_lex_fname "<=", :tLEQ
958
+ assert_lex_fname "<=", :tLEQ
928
959
  end
929
960
 
930
961
  def test_identifier_lt
931
- util_lex_fname "<", :tLT
962
+ assert_lex_fname "<", :tLT
932
963
  end
933
964
 
934
965
  def test_identifier_tilde
935
- util_lex_fname "~", :tTILDE
966
+ assert_lex_fname "~", :tTILDE
967
+ end
968
+
969
+ def test_identifier_defined?
970
+ assert_lex_fname "defined?", :kDEFINED
936
971
  end
937
972
 
938
973
  def test_index
939
- util_lex_fname "[]", :tAREF
974
+ assert_lex_fname "[]", :tAREF
940
975
  end
941
976
 
942
977
  def test_index_equals
943
- util_lex_fname "[]=", :tASET
978
+ assert_lex_fname "[]=", :tASET
944
979
  end
945
980
 
946
981
  def test_integer
947
- util_lex_token "42", :tINTEGER, 42
982
+ assert_scanned "42", :tINTEGER, 42
948
983
  end
949
984
 
950
985
  def test_integer_bin
951
- util_lex_token "0b101010", :tINTEGER, 42
986
+ assert_scanned "0b101010", :tINTEGER, 42
952
987
  end
953
988
 
954
989
  def test_integer_bin_bad_none
955
- util_bad_token "0b "
990
+ refute_scanned "0b "
956
991
  end
957
992
 
958
993
  def test_integer_bin_bad_underscores
959
- util_bad_token "0b10__01"
994
+ refute_scanned "0b10__01"
960
995
  end
961
996
 
962
997
  def test_integer_dec
963
- util_lex_token "42", :tINTEGER, 42
998
+ assert_scanned "42", :tINTEGER, 42
964
999
  end
965
1000
 
966
1001
  def test_integer_dec_bad_underscores
967
- util_bad_token "42__24"
1002
+ refute_scanned "42__24"
968
1003
  end
969
1004
 
970
1005
  def test_integer_dec_d
971
- util_lex_token "0d42", :tINTEGER, 42
1006
+ assert_scanned "0d42", :tINTEGER, 42
972
1007
  end
973
1008
 
974
1009
  def test_integer_dec_d_bad_none
975
- util_bad_token "0d"
1010
+ refute_scanned "0d"
976
1011
  end
977
1012
 
978
1013
  def test_integer_dec_d_bad_underscores
979
- util_bad_token "0d42__24"
1014
+ refute_scanned "0d42__24"
980
1015
  end
981
1016
 
982
1017
  def test_question_eh_a__18
983
1018
  setup_lexer 18
984
1019
 
985
- util_lex_token "?a", :tINTEGER, 97
1020
+ assert_scanned "?a", :tINTEGER, 97
986
1021
  end
987
1022
 
988
1023
  def test_question_eh_a__19
989
1024
  setup_lexer 19
990
1025
 
991
- util_lex_token '?a', :tSTRING, "a"
1026
+ assert_scanned '?a', :tSTRING, "a"
992
1027
  end
993
1028
 
994
1029
  def test_question_eh_escape_M_escape_C__18
995
1030
  setup_lexer 18
996
1031
 
997
- util_lex_token '?\M-\C-a', :tINTEGER, 129
1032
+ assert_scanned '?\M-\C-a', :tINTEGER, 129
998
1033
  end
999
1034
 
1000
1035
  def test_question_eh_escape_M_escape_C__19
1001
1036
  setup_lexer 19
1002
1037
 
1003
- util_lex_token '?\M-\C-a', :tSTRING, "\M-\C-a"
1038
+ assert_scanned '?\M-\C-a', :tSTRING, "\M-\C-a"
1004
1039
  end
1005
1040
 
1006
1041
  def test_integer_hex
1007
- util_lex_token "0x2a", :tINTEGER, 42
1042
+ assert_scanned "0x2a", :tINTEGER, 42
1008
1043
  end
1009
1044
 
1010
1045
  def test_integer_hex_bad_none
1011
- util_bad_token "0x "
1046
+ refute_scanned "0x "
1012
1047
  end
1013
1048
 
1014
1049
  def test_integer_hex_bad_underscores
1015
- util_bad_token "0xab__cd"
1050
+ refute_scanned "0xab__cd"
1016
1051
  end
1017
1052
 
1018
1053
  def test_integer_oct
1019
- util_lex_token "052", :tINTEGER, 42
1054
+ assert_scanned "052", :tINTEGER, 42
1020
1055
  end
1021
1056
 
1022
1057
  def test_integer_oct_bad_range
1023
- util_bad_token "08"
1058
+ refute_scanned "08"
1024
1059
  end
1025
1060
 
1026
1061
  def test_integer_oct_bad_underscores
1027
- util_bad_token "01__23"
1062
+ refute_scanned "01__23"
1028
1063
  end
1029
1064
 
1030
1065
  def test_integer_oct_O
1031
- util_lex_token "0O52", :tINTEGER, 42
1066
+ assert_scanned "0O52", :tINTEGER, 42
1032
1067
  end
1033
1068
 
1034
1069
  def test_integer_oct_O_bad_range
1035
- util_bad_token "0O1238"
1070
+ refute_scanned "0O1238"
1036
1071
  end
1037
1072
 
1038
1073
  def test_integer_oct_O_bad_underscores
1039
- util_bad_token "0O1__23"
1074
+ refute_scanned "0O1__23"
1040
1075
  end
1041
1076
 
1042
1077
  def test_integer_oct_O_not_bad_none
1043
- util_lex_token "0O ", :tINTEGER, 0
1078
+ assert_scanned "0O ", :tINTEGER, 0
1044
1079
  end
1045
1080
 
1046
1081
  def test_integer_oct_o
1047
- util_lex_token "0o52", :tINTEGER, 42
1082
+ assert_scanned "0o52", :tINTEGER, 42
1048
1083
  end
1049
1084
 
1050
1085
  def test_integer_oct_o_bad_range
1051
- util_bad_token "0o1283"
1086
+ refute_scanned "0o1283"
1052
1087
  end
1053
1088
 
1054
1089
  def test_integer_oct_o_bad_underscores
1055
- util_bad_token "0o1__23"
1090
+ refute_scanned "0o1__23"
1056
1091
  end
1057
1092
 
1058
1093
  def test_integer_oct_o_not_bad_none
1059
- util_lex_token "0o ", :tINTEGER, 0
1094
+ assert_scanned "0o ", :tINTEGER, 0
1060
1095
  end
1061
1096
 
1062
1097
  def test_integer_trailing
1063
- util_lex_token("1.to_s",
1098
+ assert_scanned("1.to_s",
1064
1099
  :tINTEGER, 1,
1065
1100
  :tDOT, '.',
1066
1101
  :tIDENTIFIER, 'to_s')
1067
1102
  end
1068
1103
 
1069
1104
  def test_integer_underscore
1070
- util_lex_token "4_2", :tINTEGER, 42
1105
+ assert_scanned "4_2", :tINTEGER, 42
1071
1106
  end
1072
1107
 
1073
1108
  def test_integer_underscore_bad
1074
- util_bad_token "4__2"
1109
+ refute_scanned "4__2"
1075
1110
  end
1076
1111
 
1077
1112
  def test_integer_zero
1078
- util_lex_token "0", :tINTEGER, 0
1113
+ assert_scanned "0", :tINTEGER, 0
1079
1114
  end
1080
1115
 
1081
1116
  def test_ivar
1082
- util_lex_token "@blah", :tIVAR, "@blah"
1117
+ assert_scanned "@blah", :tIVAR, "@blah"
1083
1118
  end
1084
1119
 
1085
1120
  def test_ivar_bad
1086
- util_bad_token "@1"
1121
+ refute_scanned "@1"
1087
1122
  end
1088
1123
 
1089
1124
  def test_ivar_bad_0_length
1090
- util_bad_token "1+@\n", :tINTEGER, 1, :tPLUS, "+"
1125
+ refute_scanned "1+@\n", :tINTEGER, 1, :tPLUS, "+"
1091
1126
  end
1092
1127
 
1093
1128
  def test_keyword_expr
1094
1129
  @lex.state = :expr_endarg
1095
1130
 
1096
- util_lex_token("if", :kIF_MOD, "if")
1131
+ assert_scanned("if", :kIF_MOD, "if")
1097
1132
 
1098
1133
  assert_equal :expr_beg, @lex.state
1099
1134
  end
1100
1135
 
1101
1136
  def test_lt
1102
- util_lex_token "<", :tLT, "<"
1137
+ assert_scanned "<", :tLT, "<"
1103
1138
  end
1104
1139
 
1105
1140
  def test_lt2
1106
- util_lex_token("a <\< b",
1141
+ assert_scanned("a <\< b",
1107
1142
  :tIDENTIFIER, "a",
1108
1143
  :tLSHFT, "<\<",
1109
1144
  :tIDENTIFIER, "b")
@@ -1111,18 +1146,18 @@ class TestLexer < Minitest::Test
1111
1146
  end
1112
1147
 
1113
1148
  def test_lt2_equals
1114
- util_lex_token("a <\<= b",
1149
+ assert_scanned("a <\<= b",
1115
1150
  :tIDENTIFIER, "a",
1116
1151
  :tOP_ASGN, "<\<",
1117
1152
  :tIDENTIFIER, "b")
1118
1153
  end
1119
1154
 
1120
1155
  def test_lt_equals
1121
- util_lex_token "<=", :tLEQ, "<="
1156
+ assert_scanned "<=", :tLEQ, "<="
1122
1157
  end
1123
1158
 
1124
1159
  def test_minus
1125
- util_lex_token("1 - 2",
1160
+ assert_scanned("1 - 2",
1126
1161
  :tINTEGER, 1,
1127
1162
  :tMINUS, "-",
1128
1163
  :tINTEGER, 2)
@@ -1131,27 +1166,27 @@ class TestLexer < Minitest::Test
1131
1166
  def test_minus_equals
1132
1167
  @lex.state = :expr_end
1133
1168
 
1134
- util_lex_token "-=", :tOP_ASGN, "-"
1169
+ assert_scanned "-=", :tOP_ASGN, "-"
1135
1170
  end
1136
1171
 
1137
1172
  def test_minus_method
1138
1173
  @lex.state = :expr_fname
1139
- util_lex_token "-", :tMINUS, "-"
1174
+ assert_scanned "-", :tMINUS, "-"
1140
1175
  end
1141
1176
 
1142
1177
  def test_minus_unary_method
1143
1178
  @lex.state = :expr_fname
1144
- util_lex_token "-@", :tUMINUS, "-@"
1179
+ assert_scanned "-@", :tUMINUS, "-@"
1145
1180
  end
1146
1181
 
1147
1182
  def test_minus_unary_number
1148
- util_lex_token("-42",
1183
+ assert_scanned("-42",
1149
1184
  :tUMINUS_NUM, "-",
1150
1185
  :tINTEGER, 42)
1151
1186
  end
1152
1187
 
1153
1188
  def test_nth_ref
1154
- util_lex_token('[$1, $2, $3]',
1189
+ assert_scanned('[$1, $2, $3]',
1155
1190
  :tLBRACK, "[",
1156
1191
  :tNTH_REF, 1, :tCOMMA, ",",
1157
1192
  :tNTH_REF, 2, :tCOMMA, ",",
@@ -1160,26 +1195,26 @@ class TestLexer < Minitest::Test
1160
1195
  end
1161
1196
 
1162
1197
  def test_open_bracket
1163
- util_lex_token("(", :tLPAREN, "(")
1198
+ assert_scanned("(", :tLPAREN, "(")
1164
1199
  end
1165
1200
 
1166
1201
  def test_open_bracket_cmdarg
1167
- util_lex_token("m (", :tIDENTIFIER, "m",
1202
+ assert_scanned("m (", :tIDENTIFIER, "m",
1168
1203
  :tLPAREN_ARG, "(")
1169
1204
  end
1170
1205
 
1171
1206
  def test_open_bracket_exprarg
1172
- util_lex_token("m(", :tIDENTIFIER, "m",
1207
+ assert_scanned("m(", :tIDENTIFIER, "m",
1173
1208
  :tLPAREN2, "(")
1174
1209
  end
1175
1210
 
1176
1211
  def test_open_curly_bracket
1177
- util_lex_token("{",
1212
+ assert_scanned("{",
1178
1213
  :tLBRACE, "{")
1179
1214
  end
1180
1215
 
1181
1216
  def test_open_curly_bracket_arg
1182
- util_lex_token("m { 3 }",
1217
+ assert_scanned("m { 3 }",
1183
1218
  :tIDENTIFIER, "m",
1184
1219
  :tLCURLY, "{",
1185
1220
  :tINTEGER, 3,
@@ -1189,14 +1224,14 @@ class TestLexer < Minitest::Test
1189
1224
  def test_open_curly_bracket_block
1190
1225
  @lex.state = :expr_endarg # seen m(3)
1191
1226
 
1192
- util_lex_token("{ 4 }",
1227
+ assert_scanned("{ 4 }",
1193
1228
  :tLBRACE_ARG, "{",
1194
1229
  :tINTEGER, 4,
1195
1230
  :tRCURLY, "}")
1196
1231
  end
1197
1232
 
1198
1233
  def test_open_square_bracket_arg
1199
- util_lex_token("m [ 3 ]",
1234
+ assert_scanned("m [ 3 ]",
1200
1235
  :tIDENTIFIER, "m",
1201
1236
  :tLBRACK, "[",
1202
1237
  :tINTEGER, 3,
@@ -1204,7 +1239,7 @@ class TestLexer < Minitest::Test
1204
1239
  end
1205
1240
 
1206
1241
  def test_open_square_bracket_ary
1207
- util_lex_token("[1, 2, 3]",
1242
+ assert_scanned("[1, 2, 3]",
1208
1243
  :tLBRACK, "[",
1209
1244
  :tINTEGER, 1,
1210
1245
  :tCOMMA, ",",
@@ -1215,7 +1250,7 @@ class TestLexer < Minitest::Test
1215
1250
  end
1216
1251
 
1217
1252
  def test_open_square_bracket_meth
1218
- util_lex_token("m[3]",
1253
+ assert_scanned("m[3]",
1219
1254
  :tIDENTIFIER, "m",
1220
1255
  :tLBRACK2, "[",
1221
1256
  :tINTEGER, 3,
@@ -1223,37 +1258,37 @@ class TestLexer < Minitest::Test
1223
1258
  end
1224
1259
 
1225
1260
  def test_or
1226
- util_lex_token "|", :tPIPE, "|"
1261
+ assert_scanned "|", :tPIPE, "|"
1227
1262
  end
1228
1263
 
1229
1264
  def test_or2
1230
- util_lex_token "||", :tOROP, "||"
1265
+ assert_scanned "||", :tOROP, "||"
1231
1266
  end
1232
1267
 
1233
1268
  def test_or2_equals
1234
- util_lex_token "||=", :tOP_ASGN, "||"
1269
+ assert_scanned "||=", :tOP_ASGN, "||"
1235
1270
  end
1236
1271
 
1237
1272
  def test_or_equals
1238
- util_lex_token "|=", :tOP_ASGN, "|"
1273
+ assert_scanned "|=", :tOP_ASGN, "|"
1239
1274
  end
1240
1275
 
1241
1276
  def test_percent
1242
- util_lex_token("a % 2",
1277
+ assert_scanned("a % 2",
1243
1278
  :tIDENTIFIER, "a",
1244
1279
  :tPERCENT, "%",
1245
1280
  :tINTEGER, 2)
1246
1281
  end
1247
1282
 
1248
1283
  def test_percent_equals
1249
- util_lex_token("a %= 2",
1284
+ assert_scanned("a %= 2",
1250
1285
  :tIDENTIFIER, "a",
1251
1286
  :tOP_ASGN, "%",
1252
1287
  :tINTEGER, 2)
1253
1288
  end
1254
1289
 
1255
1290
  def test_plus
1256
- util_lex_token("1 + 1",
1291
+ assert_scanned("1 + 1",
1257
1292
  :tINTEGER, 1,
1258
1293
  :tPLUS, "+",
1259
1294
  :tINTEGER, 1)
@@ -1262,135 +1297,137 @@ class TestLexer < Minitest::Test
1262
1297
  def test_plus_equals
1263
1298
  @lex.state = :expr_end
1264
1299
 
1265
- util_lex_token "+=", :tOP_ASGN, "+"
1300
+ assert_scanned "+=", :tOP_ASGN, "+"
1266
1301
  end
1267
1302
 
1268
1303
  def test_plus_method
1269
1304
  @lex.state = :expr_fname
1270
- util_lex_token "+", :tPLUS, "+"
1305
+ assert_scanned "+", :tPLUS, "+"
1271
1306
  end
1272
1307
 
1273
1308
  def test_plus_unary_method
1274
1309
  @lex.state = :expr_fname
1275
- util_lex_token "+@", :tUPLUS, "+@"
1310
+ assert_scanned "+@", :tUPLUS, "+@"
1276
1311
  end
1277
1312
 
1278
1313
  def test_numbers
1279
- util_lex_token "0b10", :tINTEGER, 2
1280
- util_lex_token "0B10", :tINTEGER, 2
1314
+ assert_scanned "0b10", :tINTEGER, 2
1315
+ assert_scanned "0B10", :tINTEGER, 2
1316
+
1317
+ assert_scanned "0d10", :tINTEGER, 10
1318
+ assert_scanned "0D10", :tINTEGER, 10
1281
1319
 
1282
- util_lex_token "0d10", :tINTEGER, 10
1283
- util_lex_token "0D10", :tINTEGER, 10
1320
+ assert_scanned "0x10", :tINTEGER, 16
1321
+ assert_scanned "0X10", :tINTEGER, 16
1284
1322
 
1285
- util_lex_token "0x10", :tINTEGER, 16
1286
- util_lex_token "0X10", :tINTEGER, 16
1323
+ assert_scanned "0o10", :tINTEGER, 8
1324
+ assert_scanned "0O10", :tINTEGER, 8
1325
+ assert_scanned "0o", :tINTEGER, 0
1326
+ assert_scanned "0O", :tINTEGER, 0
1287
1327
 
1288
- util_lex_token "0o10", :tINTEGER, 8
1289
- util_lex_token "0O10", :tINTEGER, 8
1290
- util_lex_token "0o", :tINTEGER, 0
1291
- util_lex_token "0O", :tINTEGER, 0
1328
+ assert_scanned "0o", :tINTEGER, 0
1329
+ assert_scanned "0O", :tINTEGER, 0
1292
1330
 
1293
- util_lex_token "0o", :tINTEGER, 0
1294
- util_lex_token "0O", :tINTEGER, 0
1331
+ assert_scanned "0777_333", :tINTEGER, 261851
1295
1332
 
1296
- util_lex_token "0", :tINTEGER, 0
1333
+ assert_scanned "0", :tINTEGER, 0
1297
1334
 
1298
- util_bad_token "0x"
1299
- util_bad_token "0X"
1300
- util_bad_token "0b"
1301
- util_bad_token "0B"
1302
- util_bad_token "0d"
1303
- util_bad_token "0D"
1335
+ refute_scanned "0x"
1336
+ refute_scanned "0X"
1337
+ refute_scanned "0b"
1338
+ refute_scanned "0B"
1339
+ refute_scanned "0d"
1340
+ refute_scanned "0D"
1304
1341
 
1305
- util_bad_token "08"
1306
- util_bad_token "09"
1307
- util_bad_token "0o8"
1308
- util_bad_token "0o9"
1309
- util_bad_token "0O8"
1310
- util_bad_token "0O9"
1342
+ refute_scanned "08"
1343
+ refute_scanned "09"
1344
+ refute_scanned "0o8"
1345
+ refute_scanned "0o9"
1346
+ refute_scanned "0O8"
1347
+ refute_scanned "0O9"
1311
1348
 
1312
- util_bad_token "1_e1"
1313
- util_bad_token "1_.1"
1314
- util_bad_token "1__1"
1349
+ refute_scanned "1_e1"
1350
+ refute_scanned "1_.1"
1351
+ refute_scanned "1__1"
1315
1352
 
1316
- util_bad_token "1end"
1317
- util_bad_token "1.1end"
1353
+ refute_scanned "1end"
1354
+ refute_scanned "1.1end"
1318
1355
  end
1319
1356
 
1320
1357
  def test_plus_unary_number
1321
- util_lex_token("+42",
1358
+ assert_scanned("+42",
1322
1359
  :tINTEGER, 42)
1323
1360
  end
1324
1361
 
1325
1362
  def test_question__18
1326
1363
  setup_lexer 18
1327
1364
 
1328
- util_lex_token "?*", :tINTEGER, 42
1365
+ assert_scanned "?*", :tINTEGER, 42
1329
1366
  end
1330
1367
 
1331
1368
  def test_question__19
1332
1369
  setup_lexer 19
1333
1370
 
1334
- util_lex_token "?*", :tSTRING, "*"
1371
+ assert_scanned "?*", :tSTRING, "*"
1335
1372
  end
1336
1373
 
1337
1374
  def test_question_bad_eos
1338
- util_bad_token "?"
1375
+ refute_scanned "?"
1339
1376
  end
1340
1377
 
1341
1378
  def test_question_bad_ws
1342
- util_lex_token "? ", :tEH, "?"
1343
- util_lex_token "?\n", :tEH, "?"
1344
- util_lex_token "?\t", :tEH, "?"
1345
- util_lex_token "?\v", :tEH, "?"
1346
- util_lex_token "?\r", :tEH, "?"
1347
- util_lex_token "?\f", :tEH, "?"
1379
+ assert_scanned "? ", :tEH, "?"
1380
+ assert_scanned "?\n", :tEH, "?"
1381
+ assert_scanned "?\t", :tEH, "?"
1382
+ assert_scanned "?\v", :tEH, "?"
1383
+ assert_scanned "?\r", :tEH, "?"
1384
+ assert_scanned "?\f", :tEH, "?"
1348
1385
  end
1349
1386
 
1350
1387
  def test_question_ws_backslashed__18
1351
1388
  setup_lexer 18
1352
1389
 
1353
1390
  @lex.state = :expr_beg
1354
- util_lex_token "?\\ ", :tINTEGER, 32
1391
+ assert_scanned "?\\ ", :tINTEGER, 32
1355
1392
  @lex.state = :expr_beg
1356
- util_lex_token "?\\n", :tINTEGER, 10
1393
+ assert_scanned "?\\n", :tINTEGER, 10
1357
1394
  @lex.state = :expr_beg
1358
- util_lex_token "?\\t", :tINTEGER, 9
1395
+ assert_scanned "?\\t", :tINTEGER, 9
1359
1396
  @lex.state = :expr_beg
1360
- util_lex_token "?\\v", :tINTEGER, 11
1397
+ assert_scanned "?\\v", :tINTEGER, 11
1361
1398
  @lex.state = :expr_beg
1362
- util_lex_token "?\\r", :tINTEGER, 13
1399
+ assert_scanned "?\\r", :tINTEGER, 13
1363
1400
  @lex.state = :expr_beg
1364
- util_lex_token "?\\f", :tINTEGER, 12
1401
+ assert_scanned "?\\f", :tINTEGER, 12
1365
1402
  end
1366
1403
 
1367
1404
  def test_question_ws_backslashed__19
1368
1405
  setup_lexer 19
1369
1406
 
1370
1407
  @lex.state = :expr_beg
1371
- util_lex_token "?\\ ", :tSTRING, " "
1408
+ assert_scanned "?\\ ", :tSTRING, " "
1372
1409
  @lex.state = :expr_beg
1373
- util_lex_token "?\\n", :tSTRING, "\n"
1410
+ assert_scanned "?\\n", :tSTRING, "\n"
1374
1411
  @lex.state = :expr_beg
1375
- util_lex_token "?\\t", :tSTRING, "\t"
1412
+ assert_scanned "?\\t", :tSTRING, "\t"
1376
1413
  @lex.state = :expr_beg
1377
- util_lex_token "?\\v", :tSTRING, "\v"
1414
+ assert_scanned "?\\v", :tSTRING, "\v"
1378
1415
  @lex.state = :expr_beg
1379
- util_lex_token "?\\r", :tSTRING, "\r"
1416
+ assert_scanned "?\\r", :tSTRING, "\r"
1380
1417
  @lex.state = :expr_beg
1381
- util_lex_token "?\\f", :tSTRING, "\f"
1418
+ assert_scanned "?\\f", :tSTRING, "\f"
1382
1419
  end
1383
1420
 
1384
1421
  def test_rbracket
1385
- util_lex_token "]", :tRBRACK, "]"
1422
+ assert_scanned "]", :tRBRACK, "]"
1386
1423
  end
1387
1424
 
1388
1425
  def test_rcurly
1389
- util_lex_token "}", :tRCURLY, "}"
1426
+ assert_scanned "}", :tRCURLY, "}"
1390
1427
  end
1391
1428
 
1392
1429
  def test_regexp
1393
- util_lex_token("/regexp/",
1430
+ assert_scanned("/regexp/",
1394
1431
  :tREGEXP_BEG, "/",
1395
1432
  :tSTRING_CONTENT, "regexp",
1396
1433
  :tSTRING_END, "/",
@@ -1398,7 +1435,7 @@ class TestLexer < Minitest::Test
1398
1435
  end
1399
1436
 
1400
1437
  def test_regexp_ambiguous
1401
- util_lex_token("method /regexp/",
1438
+ assert_scanned("method /regexp/",
1402
1439
  :tIDENTIFIER, "method",
1403
1440
  :tREGEXP_BEG, "/",
1404
1441
  :tSTRING_CONTENT, "regexp",
@@ -1407,14 +1444,14 @@ class TestLexer < Minitest::Test
1407
1444
  end
1408
1445
 
1409
1446
  def test_regexp_bad
1410
- util_bad_token("/.*/xyz",
1447
+ refute_scanned("/.*/xyz",
1411
1448
  :tREGEXP_BEG, "/",
1412
1449
  :tSTRING_CONTENT, ".*",
1413
1450
  :tSTRING_END, "/")
1414
1451
  end
1415
1452
 
1416
1453
  def test_regexp_escape_C
1417
- util_lex_token('/regex\\C-x/',
1454
+ assert_scanned('/regex\\C-x/',
1418
1455
  :tREGEXP_BEG, "/",
1419
1456
  :tSTRING_CONTENT, "regex\\C-x",
1420
1457
  :tSTRING_END, "/",
@@ -1422,7 +1459,7 @@ class TestLexer < Minitest::Test
1422
1459
  end
1423
1460
 
1424
1461
  def test_regexp_escape_C_M
1425
- util_lex_token('/regex\\C-\\M-x/',
1462
+ assert_scanned('/regex\\C-\\M-x/',
1426
1463
  :tREGEXP_BEG, "/",
1427
1464
  :tSTRING_CONTENT, "regex\\C-\\M-x",
1428
1465
  :tSTRING_END, "/",
@@ -1430,7 +1467,7 @@ class TestLexer < Minitest::Test
1430
1467
  end
1431
1468
 
1432
1469
  def test_regexp_escape_C_M_craaaazy
1433
- util_lex_token("/regex\\C-\\\n\\M-x/",
1470
+ assert_scanned("/regex\\C-\\\n\\M-x/",
1434
1471
  :tREGEXP_BEG, "/",
1435
1472
  :tSTRING_CONTENT, "regex\\C-\\M-x",
1436
1473
  :tSTRING_END, "/",
@@ -1438,27 +1475,27 @@ class TestLexer < Minitest::Test
1438
1475
  end
1439
1476
 
1440
1477
  def test_regexp_escape_C_bad_dash
1441
- util_bad_token '/regex\\Cx/', :tREGEXP_BEG, "/"
1478
+ refute_scanned '/regex\\Cx/', :tREGEXP_BEG, "/"
1442
1479
  end
1443
1480
 
1444
1481
  def test_regexp_escape_C_bad_dash_eos
1445
- util_bad_token '/regex\\C-/', :tREGEXP_BEG, "/"
1482
+ refute_scanned '/regex\\C-/', :tREGEXP_BEG, "/"
1446
1483
  end
1447
1484
 
1448
1485
  def test_regexp_escape_C_bad_dash_eos2
1449
- util_bad_token '/regex\\C-', :tREGEXP_BEG, "/"
1486
+ refute_scanned '/regex\\C-', :tREGEXP_BEG, "/"
1450
1487
  end
1451
1488
 
1452
1489
  def test_regexp_escape_C_bad_eos
1453
- util_bad_token '/regex\\C/', :tREGEXP_BEG, "/"
1490
+ refute_scanned '/regex\\C/', :tREGEXP_BEG, "/"
1454
1491
  end
1455
1492
 
1456
1493
  def test_regexp_escape_C_bad_eos2
1457
- util_bad_token '/regex\\c', :tREGEXP_BEG, "/"
1494
+ refute_scanned '/regex\\c', :tREGEXP_BEG, "/"
1458
1495
  end
1459
1496
 
1460
1497
  def test_regexp_escape_M
1461
- util_lex_token('/regex\\M-x/',
1498
+ assert_scanned('/regex\\M-x/',
1462
1499
  :tREGEXP_BEG, "/",
1463
1500
  :tSTRING_CONTENT, "regex\\M-x",
1464
1501
  :tSTRING_END, "/",
@@ -1466,7 +1503,7 @@ class TestLexer < Minitest::Test
1466
1503
  end
1467
1504
 
1468
1505
  def test_regexp_escape_M_C
1469
- util_lex_token('/regex\\M-\\C-x/',
1506
+ assert_scanned('/regex\\M-\\C-x/',
1470
1507
  :tREGEXP_BEG, "/",
1471
1508
  :tSTRING_CONTENT, "regex\\M-\\C-x",
1472
1509
  :tSTRING_END, "/",
@@ -1474,23 +1511,23 @@ class TestLexer < Minitest::Test
1474
1511
  end
1475
1512
 
1476
1513
  def test_regexp_escape_M_bad_dash
1477
- util_bad_token '/regex\\Mx/', :tREGEXP_BEG, "/"
1514
+ refute_scanned '/regex\\Mx/', :tREGEXP_BEG, "/"
1478
1515
  end
1479
1516
 
1480
1517
  def test_regexp_escape_M_bad_dash_eos
1481
- util_bad_token '/regex\\M-/', :tREGEXP_BEG, "/"
1518
+ refute_scanned '/regex\\M-/', :tREGEXP_BEG, "/"
1482
1519
  end
1483
1520
 
1484
1521
  def test_regexp_escape_M_bad_dash_eos2
1485
- util_bad_token '/regex\\M-', :tREGEXP_BEG, "/"
1522
+ refute_scanned '/regex\\M-', :tREGEXP_BEG, "/"
1486
1523
  end
1487
1524
 
1488
1525
  def test_regexp_escape_M_bad_eos
1489
- util_bad_token '/regex\\M/', :tREGEXP_BEG, "/"
1526
+ refute_scanned '/regex\\M/', :tREGEXP_BEG, "/"
1490
1527
  end
1491
1528
 
1492
1529
  def test_regexp_escape_backslash_slash
1493
- util_lex_token('/\\//',
1530
+ assert_scanned('/\\//',
1494
1531
  :tREGEXP_BEG, "/",
1495
1532
  :tSTRING_CONTENT, '\\/',
1496
1533
  :tSTRING_END, "/",
@@ -1498,7 +1535,7 @@ class TestLexer < Minitest::Test
1498
1535
  end
1499
1536
 
1500
1537
  def test_regexp_escape_backslash_terminator
1501
- util_lex_token('%r%blah\\%blah%',
1538
+ assert_scanned('%r%blah\\%blah%',
1502
1539
  :tREGEXP_BEG, "%r%",
1503
1540
  :tSTRING_CONTENT, "blah\\%blah",
1504
1541
  :tSTRING_END, "%",
@@ -1506,7 +1543,7 @@ class TestLexer < Minitest::Test
1506
1543
  end
1507
1544
 
1508
1545
  def test_regexp_escape_backslash_terminator_meta1
1509
- util_lex_token('%r{blah\\}blah}',
1546
+ assert_scanned('%r{blah\\}blah}',
1510
1547
  :tREGEXP_BEG, "%r{",
1511
1548
  :tSTRING_CONTENT, "blah\\}blah",
1512
1549
  :tSTRING_END, "}",
@@ -1514,7 +1551,7 @@ class TestLexer < Minitest::Test
1514
1551
  end
1515
1552
 
1516
1553
  def test_regexp_escape_backslash_terminator_meta2
1517
- util_lex_token('%r/blah\\/blah/',
1554
+ assert_scanned('%r/blah\\/blah/',
1518
1555
  :tREGEXP_BEG, "%r/",
1519
1556
  :tSTRING_CONTENT, "blah\\/blah",
1520
1557
  :tSTRING_END, "/",
@@ -1522,7 +1559,7 @@ class TestLexer < Minitest::Test
1522
1559
  end
1523
1560
 
1524
1561
  def test_regexp_escape_backslash_terminator_meta3
1525
- util_lex_token('%r/blah\\%blah/',
1562
+ assert_scanned('%r/blah\\%blah/',
1526
1563
  :tREGEXP_BEG, "%r/",
1527
1564
  :tSTRING_CONTENT, "blah\\%blah",
1528
1565
  :tSTRING_END, "/",
@@ -1530,11 +1567,11 @@ class TestLexer < Minitest::Test
1530
1567
  end
1531
1568
 
1532
1569
  def test_regexp_escape_bad_eos
1533
- util_bad_token '/regex\\', :tREGEXP_BEG, "/"
1570
+ refute_scanned '/regex\\', :tREGEXP_BEG, "/"
1534
1571
  end
1535
1572
 
1536
1573
  def test_regexp_escape_bs
1537
- util_lex_token('/regex\\\\regex/',
1574
+ assert_scanned('/regex\\\\regex/',
1538
1575
  :tREGEXP_BEG, "/",
1539
1576
  :tSTRING_CONTENT, "regex\\\\regex",
1540
1577
  :tSTRING_END, "/",
@@ -1542,7 +1579,7 @@ class TestLexer < Minitest::Test
1542
1579
  end
1543
1580
 
1544
1581
  def test_regexp_escape_c
1545
- util_lex_token('/regex\\cxxx/',
1582
+ assert_scanned('/regex\\cxxx/',
1546
1583
  :tREGEXP_BEG, "/",
1547
1584
  :tSTRING_CONTENT, "regex\\cxxx",
1548
1585
  :tSTRING_END, "/",
@@ -1550,7 +1587,7 @@ class TestLexer < Minitest::Test
1550
1587
  end
1551
1588
 
1552
1589
  def test_regexp_escape_c_backslash
1553
- util_lex_token('/regex\\c\\n/',
1590
+ assert_scanned('/regex\\c\\n/',
1554
1591
  :tREGEXP_BEG, "/",
1555
1592
  :tSTRING_CONTENT, "regex\\c\\n",
1556
1593
  :tSTRING_END, "/",
@@ -1558,7 +1595,7 @@ class TestLexer < Minitest::Test
1558
1595
  end
1559
1596
 
1560
1597
  def test_regexp_escape_chars
1561
- util_lex_token('/re\\tge\\nxp/',
1598
+ assert_scanned('/re\\tge\\nxp/',
1562
1599
  :tREGEXP_BEG, "/",
1563
1600
  :tSTRING_CONTENT, "re\\tge\\nxp",
1564
1601
  :tSTRING_END, "/",
@@ -1567,7 +1604,7 @@ class TestLexer < Minitest::Test
1567
1604
 
1568
1605
  def test_regexp_escape_double_backslash
1569
1606
  regexp = '/[\\/\\\\]$/'
1570
- util_lex_token(regexp,
1607
+ assert_scanned(regexp,
1571
1608
  :tREGEXP_BEG, "/",
1572
1609
  :tSTRING_CONTENT, regexp[1..-2],
1573
1610
  :tSTRING_END, "/",
@@ -1575,7 +1612,7 @@ class TestLexer < Minitest::Test
1575
1612
  end
1576
1613
 
1577
1614
  def test_regexp_escape_hex
1578
- util_lex_token('/regex\\x61xp/',
1615
+ assert_scanned('/regex\\x61xp/',
1579
1616
  :tREGEXP_BEG, "/",
1580
1617
  :tSTRING_CONTENT, "regex\\x61xp",
1581
1618
  :tSTRING_END, "/",
@@ -1583,11 +1620,11 @@ class TestLexer < Minitest::Test
1583
1620
  end
1584
1621
 
1585
1622
  def test_regexp_escape_hex_bad
1586
- util_bad_token '/regex\\xzxp/', :tREGEXP_BEG, "/"
1623
+ refute_scanned '/regex\\xzxp/', :tREGEXP_BEG, "/"
1587
1624
  end
1588
1625
 
1589
1626
  def test_regexp_escape_hex_one
1590
- util_lex_token('/^[\\xd\\xa]{2}/on',
1627
+ assert_scanned('/^[\\xd\\xa]{2}/on',
1591
1628
  :tREGEXP_BEG, '/',
1592
1629
  :tSTRING_CONTENT, '^[\\xd\\xa]{2}',
1593
1630
  :tSTRING_END, "/",
@@ -1595,7 +1632,7 @@ class TestLexer < Minitest::Test
1595
1632
  end
1596
1633
 
1597
1634
  def test_regexp_escape_oct1
1598
- util_lex_token('/regex\\0xp/',
1635
+ assert_scanned('/regex\\0xp/',
1599
1636
  :tREGEXP_BEG, "/",
1600
1637
  :tSTRING_CONTENT, "regex\\0xp",
1601
1638
  :tSTRING_END, "/",
@@ -1603,7 +1640,7 @@ class TestLexer < Minitest::Test
1603
1640
  end
1604
1641
 
1605
1642
  def test_regexp_escape_oct2
1606
- util_lex_token('/regex\\07xp/',
1643
+ assert_scanned('/regex\\07xp/',
1607
1644
  :tREGEXP_BEG, "/",
1608
1645
  :tSTRING_CONTENT, "regex\\07xp",
1609
1646
  :tSTRING_END, "/",
@@ -1611,7 +1648,7 @@ class TestLexer < Minitest::Test
1611
1648
  end
1612
1649
 
1613
1650
  def test_regexp_escape_oct3
1614
- util_lex_token('/regex\\10142/',
1651
+ assert_scanned('/regex\\10142/',
1615
1652
  :tREGEXP_BEG, "/",
1616
1653
  :tSTRING_CONTENT, "regex\\10142",
1617
1654
  :tSTRING_END, "/",
@@ -1619,7 +1656,7 @@ class TestLexer < Minitest::Test
1619
1656
  end
1620
1657
 
1621
1658
  def test_regexp_escape_return
1622
- util_lex_token("/regex\\\nregex/",
1659
+ assert_scanned("/regex\\\nregex/",
1623
1660
  :tREGEXP_BEG, "/",
1624
1661
  :tSTRING_CONTENT, "regexregex",
1625
1662
  :tSTRING_END, "/",
@@ -1627,7 +1664,7 @@ class TestLexer < Minitest::Test
1627
1664
  end
1628
1665
 
1629
1666
  def test_regexp_nm
1630
- util_lex_token("/.*/nm",
1667
+ assert_scanned("/.*/nm",
1631
1668
  :tREGEXP_BEG, "/",
1632
1669
  :tSTRING_CONTENT, ".*",
1633
1670
  :tSTRING_END, "/",
@@ -1635,25 +1672,25 @@ class TestLexer < Minitest::Test
1635
1672
  end
1636
1673
 
1637
1674
  def test_rparen
1638
- util_lex_token ")", :tRPAREN, ")"
1675
+ assert_scanned ")", :tRPAREN, ")"
1639
1676
  end
1640
1677
 
1641
1678
  def test_rshft
1642
- util_lex_token("a >> 2",
1679
+ assert_scanned("a >> 2",
1643
1680
  :tIDENTIFIER, "a",
1644
1681
  :tRSHFT, ">>",
1645
1682
  :tINTEGER, 2)
1646
1683
  end
1647
1684
 
1648
1685
  def test_rshft_equals
1649
- util_lex_token("a >>= 2",
1686
+ assert_scanned("a >>= 2",
1650
1687
  :tIDENTIFIER, "a",
1651
1688
  :tOP_ASGN, ">>",
1652
1689
  :tINTEGER, 2)
1653
1690
  end
1654
1691
 
1655
1692
  def test_star
1656
- util_lex_token("a * ",
1693
+ assert_scanned("a * ",
1657
1694
  :tIDENTIFIER, "a",
1658
1695
  :tSTAR2, "*")
1659
1696
 
@@ -1661,7 +1698,7 @@ class TestLexer < Minitest::Test
1661
1698
  end
1662
1699
 
1663
1700
  def test_star2
1664
- util_lex_token("a ** ",
1701
+ assert_scanned("a ** ",
1665
1702
  :tIDENTIFIER, "a",
1666
1703
  :tPOW, "**")
1667
1704
 
@@ -1669,7 +1706,7 @@ class TestLexer < Minitest::Test
1669
1706
  end
1670
1707
 
1671
1708
  def test_star2_equals
1672
- util_lex_token("a **= ",
1709
+ assert_scanned("a **= ",
1673
1710
  :tIDENTIFIER, "a",
1674
1711
  :tOP_ASGN, "**")
1675
1712
 
@@ -1677,7 +1714,7 @@ class TestLexer < Minitest::Test
1677
1714
  end
1678
1715
 
1679
1716
  def test_star2_beg
1680
- util_lex_token("** ",
1717
+ assert_scanned("** ",
1681
1718
  :tDSTAR, "**")
1682
1719
 
1683
1720
  assert_equal :expr_beg, @lex.state
@@ -1686,7 +1723,7 @@ class TestLexer < Minitest::Test
1686
1723
  def test_star_arg
1687
1724
  @lex.state = :expr_arg
1688
1725
 
1689
- util_lex_token(" *a",
1726
+ assert_scanned(" *a",
1690
1727
  :tSTAR, "*",
1691
1728
  :tIDENTIFIER, "a")
1692
1729
 
@@ -1696,7 +1733,7 @@ class TestLexer < Minitest::Test
1696
1733
  def test_star_arg_beg
1697
1734
  @lex.state = :expr_beg
1698
1735
 
1699
- util_lex_token("*a",
1736
+ assert_scanned("*a",
1700
1737
  :tSTAR, "*",
1701
1738
  :tIDENTIFIER, "a")
1702
1739
 
@@ -1706,7 +1743,7 @@ class TestLexer < Minitest::Test
1706
1743
  def test_star_arg_beg_fname
1707
1744
  @lex.state = :expr_fname
1708
1745
 
1709
- util_lex_token("*a",
1746
+ assert_scanned("*a",
1710
1747
  :tSTAR2, "*",
1711
1748
  :tIDENTIFIER, "a")
1712
1749
 
@@ -1714,7 +1751,7 @@ class TestLexer < Minitest::Test
1714
1751
  end
1715
1752
 
1716
1753
  def test_star_equals
1717
- util_lex_token("a *= ",
1754
+ assert_scanned("a *= ",
1718
1755
  :tIDENTIFIER, "a",
1719
1756
  :tOP_ASGN, "*")
1720
1757
 
@@ -1722,97 +1759,102 @@ class TestLexer < Minitest::Test
1722
1759
  end
1723
1760
 
1724
1761
  def test_string_bad_eos
1725
- util_bad_token('%',
1762
+ refute_scanned('%',
1726
1763
  :tSTRING_BEG, '%')
1727
1764
  end
1728
1765
 
1729
1766
  def test_string_bad_eos_quote
1730
- util_bad_token('%{nest',
1767
+ refute_scanned('%{nest',
1731
1768
  :tSTRING_BEG, '%}')
1732
1769
  end
1733
1770
 
1734
1771
  def test_string_double
1735
- util_lex_token('"string"',
1772
+ assert_scanned('"string"',
1736
1773
  :tSTRING, "string")
1737
1774
  end
1738
1775
 
1739
1776
  def test_string_double_escape_C
1740
- util_lex_token('"\\C-a"',
1777
+ assert_scanned('"\\C-a"',
1741
1778
  :tSTRING, "\001")
1742
1779
  end
1743
1780
 
1744
1781
  def test_string_double_escape_C_backslash
1745
- util_lex_token('"\\C-\\\\"',
1782
+ assert_scanned('"\\C-\\\\"',
1746
1783
  :tSTRING, "\034")
1747
1784
  end
1748
1785
 
1749
1786
  def test_string_double_escape_C_escape
1750
- util_lex_token('"\\C-\\M-a"',
1787
+ assert_scanned('"\\C-\\M-a"',
1751
1788
  :tSTRING, "\201")
1752
1789
  end
1753
1790
 
1754
1791
  def test_string_double_escape_C_question
1755
- util_lex_token('"\\C-?"',
1792
+ assert_scanned('"\\C-?"',
1756
1793
  :tSTRING, "\177")
1757
1794
  end
1758
1795
 
1759
1796
  def test_string_double_escape_M
1760
- util_lex_token('"\\M-a"',
1797
+ assert_scanned('"\\M-a"',
1761
1798
  :tSTRING, "\341")
1762
1799
  end
1763
1800
 
1764
1801
  def test_string_double_escape_M_backslash
1765
- util_lex_token('"\\M-\\\\"',
1802
+ assert_scanned('"\\M-\\\\"',
1766
1803
  :tSTRING, "\334")
1767
1804
  end
1768
1805
 
1769
1806
  def test_string_double_escape_M_escape
1770
- util_lex_token('"\\M-\\C-a"',
1807
+ assert_scanned('"\\M-\\C-a"',
1771
1808
  :tSTRING, "\201")
1772
1809
  end
1773
1810
 
1774
1811
  def test_string_double_escape_bs1
1775
- util_lex_token('"a\\a\\a"',
1812
+ assert_scanned('"a\\a\\a"',
1776
1813
  :tSTRING, "a\a\a")
1777
1814
  end
1778
1815
 
1779
1816
  def test_string_double_escape_bs2
1780
- util_lex_token('"a\\\\a"',
1817
+ assert_scanned('"a\\\\a"',
1781
1818
  :tSTRING, "a\\a")
1782
1819
  end
1783
1820
 
1784
1821
  def test_string_double_escape_c
1785
- util_lex_token('"\\ca"',
1822
+ assert_scanned('"\\ca"',
1786
1823
  :tSTRING, "\001")
1787
1824
  end
1788
1825
 
1789
1826
  def test_string_double_escape_c_escape
1790
- util_lex_token('"\\c\\M-a"',
1827
+ assert_scanned('"\\c\\M-a"',
1791
1828
  :tSTRING, "\201")
1792
1829
  end
1793
1830
 
1794
1831
  def test_string_double_escape_c_question
1795
- util_lex_token('"\\c?"',
1832
+ assert_scanned('"\\c?"',
1796
1833
  :tSTRING, "\177")
1797
1834
  end
1798
1835
 
1799
1836
  def test_string_double_escape_chars
1800
- util_lex_token('"s\\tri\\ng"',
1837
+ assert_scanned('"s\\tri\\ng"',
1801
1838
  :tSTRING, "s\tri\ng")
1802
1839
  end
1803
1840
 
1804
1841
  def test_string_double_escape_hex
1805
- util_lex_token('"n = \\x61\\x62\\x63"',
1842
+ assert_scanned('"n = \\x61\\x62\\x63"',
1806
1843
  :tSTRING, "n = abc")
1807
1844
  end
1808
1845
 
1809
1846
  def test_string_double_escape_octal
1810
- util_lex_token('"n = \\101\\102\\103"',
1847
+ assert_scanned('"n = \\101\\102\\103"',
1811
1848
  :tSTRING, "n = ABC")
1812
1849
  end
1813
1850
 
1851
+ def test_string_double_escape_octal_wrap
1852
+ assert_scanned('"\\753"',
1853
+ :tSTRING, "\xEB")
1854
+ end
1855
+
1814
1856
  def test_string_double_interp
1815
- util_lex_token("\"blah #x a \#@a b \#$b c \#{3} # \"",
1857
+ assert_scanned("\"blah #x a \#@a b \#$b c \#{3} # \"",
1816
1858
  :tSTRING_BEG, "\"",
1817
1859
  :tSTRING_CONTENT, "blah #x a ",
1818
1860
  :tSTRING_DVAR, nil,
@@ -1829,7 +1871,7 @@ class TestLexer < Minitest::Test
1829
1871
  end
1830
1872
 
1831
1873
  def test_string_double_interp_label
1832
- util_lex_token('"#{foo:bar}"',
1874
+ assert_scanned('"#{foo:bar}"',
1833
1875
  :tSTRING_BEG, '"',
1834
1876
  :tSTRING_DBEG, '#{',
1835
1877
  :tIDENTIFIER, 'foo',
@@ -1839,34 +1881,34 @@ class TestLexer < Minitest::Test
1839
1881
  end
1840
1882
 
1841
1883
  def test_string_double_nested_curlies
1842
- util_lex_token('%{nest{one{two}one}nest}',
1884
+ assert_scanned('%{nest{one{two}one}nest}',
1843
1885
  :tSTRING_BEG, '%{',
1844
1886
  :tSTRING_CONTENT, "nest{one{two}one}nest",
1845
1887
  :tSTRING_END, '}')
1846
1888
  end
1847
1889
 
1848
1890
  def test_string_double_no_interp
1849
- util_lex_token("\"# blah\"", # pound first
1891
+ assert_scanned("\"# blah\"", # pound first
1850
1892
  :tSTRING, "# blah")
1851
1893
 
1852
- util_lex_token("\"blah # blah\"", # pound not first
1894
+ assert_scanned("\"blah # blah\"", # pound not first
1853
1895
  :tSTRING, "blah # blah")
1854
1896
  end
1855
1897
 
1856
1898
  def test_string_escape_x_single
1857
- util_lex_token('"\\x0"',
1899
+ assert_scanned('"\\x0"',
1858
1900
  :tSTRING, "\000")
1859
1901
  end
1860
1902
 
1861
1903
  def test_string_pct_Q
1862
- util_lex_token("%Q[s1 s2]",
1904
+ assert_scanned("%Q[s1 s2]",
1863
1905
  :tSTRING_BEG, '%Q[',
1864
1906
  :tSTRING_CONTENT, "s1 s2",
1865
1907
  :tSTRING_END, ']')
1866
1908
  end
1867
1909
 
1868
1910
  def test_string_pct_W
1869
- util_lex_token("%W[s1 s2\ns3]",
1911
+ assert_scanned("%W[s1 s2\ns3]",
1870
1912
  :tWORDS_BEG, "%W[",
1871
1913
  :tSTRING_CONTENT, "s1",
1872
1914
  :tSPACE, nil,
@@ -1878,7 +1920,7 @@ class TestLexer < Minitest::Test
1878
1920
  end
1879
1921
 
1880
1922
  def test_string_pct_W_bs_nl
1881
- util_lex_token("%W[s1 \\\ns2]",
1923
+ assert_scanned("%W[s1 \\\ns2]",
1882
1924
  :tWORDS_BEG, "%W[",
1883
1925
  :tSTRING_CONTENT, "s1",
1884
1926
  :tSPACE, nil,
@@ -1888,7 +1930,7 @@ class TestLexer < Minitest::Test
1888
1930
  end
1889
1931
 
1890
1932
  def test_string_pct_W_interp
1891
- util_lex_token('%W[#{1}#{2} #@a]',
1933
+ assert_scanned('%W[#{1}#{2} #@a]',
1892
1934
  :tWORDS_BEG, '%W[',
1893
1935
  :tSTRING_DBEG, '#{',
1894
1936
  :tINTEGER, 1,
@@ -1904,7 +1946,7 @@ class TestLexer < Minitest::Test
1904
1946
  end
1905
1947
 
1906
1948
  def test_string_pct_I
1907
- util_lex_token("%I(s1 s2)",
1949
+ assert_scanned("%I(s1 s2)",
1908
1950
  :tSYMBOLS_BEG, "%I(",
1909
1951
  :tSTRING_CONTENT, "s1",
1910
1952
  :tSPACE, nil,
@@ -1914,21 +1956,21 @@ class TestLexer < Minitest::Test
1914
1956
  end
1915
1957
 
1916
1958
  def test_string_pct_angle
1917
- util_lex_token("%<blah>",
1959
+ assert_scanned("%<blah>",
1918
1960
  :tSTRING_BEG, '%<',
1919
1961
  :tSTRING_CONTENT, "blah",
1920
1962
  :tSTRING_END, '>')
1921
1963
  end
1922
1964
 
1923
1965
  def test_string_pct_pct
1924
- util_lex_token("%%blah%",
1966
+ assert_scanned("%%blah%",
1925
1967
  :tSTRING_BEG, '%',
1926
1968
  :tSTRING_CONTENT, "blah",
1927
1969
  :tSTRING_END, '%')
1928
1970
  end
1929
1971
 
1930
1972
  def test_string_pct_w
1931
- util_lex_token("%w[s1 s2 ]",
1973
+ assert_scanned("%w[s1 s2 ]",
1932
1974
  :tQWORDS_BEG, "%w[",
1933
1975
  :tSTRING_CONTENT, "s1",
1934
1976
  :tSPACE, nil,
@@ -1938,14 +1980,14 @@ class TestLexer < Minitest::Test
1938
1980
  end
1939
1981
 
1940
1982
  def test_string_pct_w_incomplete
1941
- util_bad_token("%w[s1 ",
1983
+ refute_scanned("%w[s1 ",
1942
1984
  :tQWORDS_BEG, "%w[",
1943
1985
  :tSTRING_CONTENT, "s1",
1944
1986
  :tSPACE, nil)
1945
1987
  end
1946
1988
 
1947
1989
  def test_string_pct_w_bs_nl
1948
- util_lex_token("%w[s1 \\\ns2]",
1990
+ assert_scanned("%w[s1 \\\ns2]",
1949
1991
  :tQWORDS_BEG, "%w[",
1950
1992
  :tSTRING_CONTENT, "s1",
1951
1993
  :tSPACE, nil,
@@ -1955,7 +1997,7 @@ class TestLexer < Minitest::Test
1955
1997
  end
1956
1998
 
1957
1999
  def test_string_pct_w_bs_sp
1958
- util_lex_token("%w[s\\ 1 s\\ 2]",
2000
+ assert_scanned("%w[s\\ 1 s\\ 2]",
1959
2001
  :tQWORDS_BEG, "%w[",
1960
2002
  :tSTRING_CONTENT, "s 1",
1961
2003
  :tSPACE, nil,
@@ -1965,7 +2007,7 @@ class TestLexer < Minitest::Test
1965
2007
  end
1966
2008
 
1967
2009
  def test_string_pct_w_tab
1968
- util_lex_token("%w[abc\tdef]",
2010
+ assert_scanned("%w[abc\tdef]",
1969
2011
  :tQWORDS_BEG, "%w[",
1970
2012
  :tSTRING_CONTENT, "abc",
1971
2013
  :tSPACE, nil,
@@ -1975,7 +2017,7 @@ class TestLexer < Minitest::Test
1975
2017
  end
1976
2018
 
1977
2019
  def test_string_pct_i
1978
- util_lex_token("%i(s1 s2)",
2020
+ assert_scanned("%i(s1 s2)",
1979
2021
  :tQSYMBOLS_BEG, "%i(",
1980
2022
  :tSTRING_CONTENT, "s1",
1981
2023
  :tSPACE, nil,
@@ -1985,17 +2027,17 @@ class TestLexer < Minitest::Test
1985
2027
  end
1986
2028
 
1987
2029
  def test_string_single
1988
- util_lex_token("'string'",
2030
+ assert_scanned("'string'",
1989
2031
  :tSTRING, "string")
1990
2032
  end
1991
2033
 
1992
2034
  def test_string_single_escape_chars
1993
- util_lex_token("'s\\tri\\ng'",
2035
+ assert_scanned("'s\\tri\\ng'",
1994
2036
  :tSTRING, "s\\tri\\ng")
1995
2037
  end
1996
2038
 
1997
2039
  def test_string_single_nl
1998
- util_lex_token("'blah\\\nblah'",
2040
+ assert_scanned("'blah\\\nblah'",
1999
2041
  :tSTRING_BEG, "'",
2000
2042
  :tSTRING_CONTENT, "blah\\\n",
2001
2043
  :tSTRING_CONTENT, "blah",
@@ -2003,72 +2045,67 @@ class TestLexer < Minitest::Test
2003
2045
  end
2004
2046
 
2005
2047
  def test_symbol
2006
- util_lex_token(":symbol",
2048
+ assert_scanned(":symbol",
2007
2049
  :tSYMBOL, "symbol")
2008
2050
  end
2009
2051
 
2010
- def test_symbol_bad_zero
2011
- util_bad_token(":\"blah\0\"",
2012
- :tSYMBEG, ":")
2013
- end
2014
-
2015
2052
  def test_symbol_double
2016
- util_lex_token(":\"symbol\"",
2053
+ assert_scanned(":\"symbol\"",
2017
2054
  :tSYMBEG, ":\"",
2018
2055
  :tSTRING_CONTENT, "symbol",
2019
2056
  :tSTRING_END, "\"")
2020
2057
  end
2021
2058
 
2022
2059
  def test_symbol_single
2023
- util_lex_token(":'symbol'",
2060
+ assert_scanned(":'symbol'",
2024
2061
  :tSYMBEG, ":'",
2025
2062
  :tSTRING_CONTENT, "symbol",
2026
2063
  :tSTRING_END, "'")
2027
2064
  end
2028
2065
 
2029
2066
  def test_ternary
2030
- util_lex_token("a ? b : c",
2067
+ assert_scanned("a ? b : c",
2031
2068
  :tIDENTIFIER, "a",
2032
2069
  :tEH, "?",
2033
2070
  :tIDENTIFIER, "b",
2034
2071
  :tCOLON, ":",
2035
2072
  :tIDENTIFIER, "c")
2036
2073
 
2037
- util_lex_token("a ?b : c",
2074
+ assert_scanned("a ?b : c",
2038
2075
  :tIDENTIFIER, "a",
2039
2076
  :tINTEGER, 98,
2040
2077
  :tCOLON, ":",
2041
2078
  :tIDENTIFIER, "c")
2042
2079
 
2043
- util_lex_token("a ?bb : c", # GAH! MATZ!!!
2080
+ assert_scanned("a ?bb : c", # GAH! MATZ!!!
2044
2081
  :tIDENTIFIER, "a",
2045
2082
  :tEH, "?",
2046
2083
  :tIDENTIFIER, "bb",
2047
2084
  :tCOLON, ":",
2048
2085
  :tIDENTIFIER, "c")
2049
2086
 
2050
- util_lex_token("42 ?", # 42 forces expr_end
2087
+ assert_scanned("42 ?", # 42 forces expr_end
2051
2088
  :tINTEGER, 42,
2052
2089
  :tEH, "?")
2053
2090
  end
2054
2091
 
2055
2092
  def test_tilde
2056
- util_lex_token "~", :tTILDE, "~"
2093
+ assert_scanned "~", :tTILDE, "~"
2057
2094
  end
2058
2095
 
2059
2096
  def test_tilde_unary
2060
2097
  @lex.state = :expr_fname
2061
- util_lex_token "~@", :tTILDE, "~@"
2098
+ assert_scanned "~@", :tTILDE, "~@"
2062
2099
  end
2063
2100
 
2064
2101
  def test_uminus
2065
- util_lex_token("-blah",
2102
+ assert_scanned("-blah",
2066
2103
  :tUMINUS, "-",
2067
2104
  :tIDENTIFIER, "blah")
2068
2105
  end
2069
2106
 
2070
2107
  def test_underscore
2071
- util_lex_token("_var", :tIDENTIFIER, "_var")
2108
+ assert_scanned("_var", :tIDENTIFIER, "_var")
2072
2109
  end
2073
2110
 
2074
2111
  def test_underscore_end
@@ -2082,13 +2119,13 @@ class TestLexer < Minitest::Test
2082
2119
  end
2083
2120
 
2084
2121
  def test_uplus
2085
- util_lex_token("+blah",
2122
+ assert_scanned("+blah",
2086
2123
  :tUPLUS, "+",
2087
2124
  :tIDENTIFIER, "blah")
2088
2125
  end
2089
2126
 
2090
2127
  def test_if_unless_mod
2091
- util_lex_token("return if true unless false",
2128
+ assert_scanned("return if true unless false",
2092
2129
  :kRETURN, "return",
2093
2130
  :kIF_MOD, "if",
2094
2131
  :kTRUE, "true",
@@ -2097,7 +2134,7 @@ class TestLexer < Minitest::Test
2097
2134
  end
2098
2135
 
2099
2136
  def test_if_stmt
2100
- util_lex_token("if true\n return end",
2137
+ assert_scanned("if true\n return end",
2101
2138
  :kIF, "if",
2102
2139
  :kTRUE, "true",
2103
2140
  :tNL, nil,
@@ -2107,7 +2144,7 @@ class TestLexer < Minitest::Test
2107
2144
 
2108
2145
  def test_sclass_label
2109
2146
  setup_lexer 20
2110
- util_lex_token("class << a:b",
2147
+ assert_scanned("class << a:b",
2111
2148
  :kCLASS, 'class',
2112
2149
  :tLSHFT, '<<',
2113
2150
  :tIDENTIFIER, 'a',
@@ -2118,19 +2155,8 @@ class TestLexer < Minitest::Test
2118
2155
  env = Parser::StaticEnvironment.new
2119
2156
  env.declare "a"
2120
2157
 
2121
- setup_lexer(18)
2122
- @lex.static_env = env
2123
-
2124
- util_lex_token("a [42]",
2125
- :tIDENTIFIER, "a",
2126
- :tLBRACK, "[",
2127
- :tINTEGER, 42,
2128
- :tRBRACK, "]")
2129
-
2130
- setup_lexer(19)
2131
2158
  @lex.static_env = env
2132
-
2133
- util_lex_token("a [42]",
2159
+ assert_scanned("a [42]",
2134
2160
  :tIDENTIFIER, "a",
2135
2161
  :tLBRACK2, "[",
2136
2162
  :tINTEGER, 42,
@@ -2143,23 +2169,23 @@ class TestLexer < Minitest::Test
2143
2169
 
2144
2170
  def test_whitespace_fname
2145
2171
  @lex.state = :expr_fname
2146
- util_lex_token('class',
2172
+ assert_scanned('class',
2147
2173
  :kCLASS, 'class')
2148
2174
 
2149
2175
  @lex.state = :expr_fname
2150
- util_lex_token(' class',
2176
+ assert_scanned(' class',
2151
2177
  :kCLASS, 'class')
2152
2178
 
2153
2179
  @lex.state = :expr_fname
2154
- util_lex_token("\nclass",
2180
+ assert_scanned("\nclass",
2155
2181
  :kCLASS, 'class')
2156
2182
 
2157
2183
  @lex.state = :expr_fname
2158
- util_lex_token("\\\nclass",
2184
+ assert_scanned("\\\nclass",
2159
2185
  :kCLASS, 'class')
2160
2186
 
2161
2187
  @lex.state = :expr_fname
2162
- util_lex_token("#foo\nclass",
2188
+ assert_scanned("#foo\nclass",
2163
2189
  :kCLASS, 'class')
2164
2190
  end
2165
2191
 
@@ -2167,37 +2193,37 @@ class TestLexer < Minitest::Test
2167
2193
  setup_lexer(21)
2168
2194
 
2169
2195
  @lex.state = :expr_endfn
2170
- util_lex_token('foo:',
2196
+ assert_scanned('foo:',
2171
2197
  :tLABEL, 'foo')
2172
2198
 
2173
2199
  @lex.state = :expr_endfn
2174
- util_lex_token(' foo:',
2200
+ assert_scanned(' foo:',
2175
2201
  :tLABEL, 'foo')
2176
2202
 
2177
2203
  @lex.state = :expr_endfn
2178
- util_lex_token("\nfoo:",
2204
+ assert_scanned("\nfoo:",
2179
2205
  :tNL, nil,
2180
2206
  :tIDENTIFIER, 'foo',
2181
2207
  :tCOLON, ':')
2182
2208
 
2183
2209
  @lex.state = :expr_endfn
2184
- util_lex_token("\nfoo: ",
2210
+ assert_scanned("\nfoo: ",
2185
2211
  :tNL, nil,
2186
2212
  :tIDENTIFIER, 'foo',
2187
2213
  :tCOLON, ':')
2188
2214
 
2189
2215
  @lex.state = :expr_endfn
2190
- util_lex_token("\\\nfoo:",
2216
+ assert_scanned("\\\nfoo:",
2191
2217
  :tLABEL, 'foo')
2192
2218
 
2193
2219
  @lex.state = :expr_endfn
2194
- util_lex_token("#foo\nfoo:",
2220
+ assert_scanned("#foo\nfoo:",
2195
2221
  :tNL, nil,
2196
2222
  :tIDENTIFIER, 'foo',
2197
2223
  :tCOLON, ':')
2198
2224
 
2199
2225
  @lex.state = :expr_endfn
2200
- util_lex_token("#foo\nfoo: ",
2226
+ assert_scanned("#foo\nfoo: ",
2201
2227
  :tNL, nil,
2202
2228
  :tIDENTIFIER, 'foo',
2203
2229
  :tCOLON, ':')
@@ -2205,121 +2231,121 @@ class TestLexer < Minitest::Test
2205
2231
 
2206
2232
  def test_whitespace_dot
2207
2233
  @lex.state = :expr_dot
2208
- util_lex_token('class',
2234
+ assert_scanned('class',
2209
2235
  :tIDENTIFIER, 'class')
2210
2236
 
2211
2237
  @lex.state = :expr_dot
2212
- util_lex_token(' class',
2238
+ assert_scanned(' class',
2213
2239
  :tIDENTIFIER, 'class')
2214
2240
 
2215
2241
  @lex.state = :expr_dot
2216
- util_lex_token("\nclass",
2242
+ assert_scanned("\nclass",
2217
2243
  :tIDENTIFIER, 'class')
2218
2244
 
2219
2245
  @lex.state = :expr_dot
2220
- util_lex_token("\\\nclass",
2246
+ assert_scanned("\\\nclass",
2221
2247
  :tIDENTIFIER, 'class')
2222
2248
 
2223
2249
  @lex.state = :expr_dot
2224
- util_lex_token("#foo\nclass",
2250
+ assert_scanned("#foo\nclass",
2225
2251
  :tIDENTIFIER, 'class')
2226
2252
  end
2227
2253
 
2228
2254
  def test_whitespace_arg
2229
2255
  @lex.state = :expr_arg
2230
- util_lex_token('+',
2256
+ assert_scanned('+',
2231
2257
  :tPLUS, '+')
2232
2258
 
2233
2259
  @lex.state = :expr_arg
2234
- util_lex_token(' +',
2260
+ assert_scanned(' +',
2235
2261
  :tUPLUS, '+')
2236
2262
 
2237
2263
  @lex.state = :expr_arg
2238
- util_lex_token("\n+",
2264
+ assert_scanned("\n+",
2239
2265
  :tNL, nil,
2240
2266
  :tUPLUS, '+')
2241
2267
 
2242
2268
  @lex.state = :expr_arg
2243
- util_lex_token("\\\n+",
2269
+ assert_scanned("\\\n+",
2244
2270
  :tUPLUS, '+')
2245
2271
 
2246
2272
  @lex.state = :expr_arg
2247
- util_lex_token("\\\n +",
2273
+ assert_scanned("\\\n +",
2248
2274
  :tUPLUS, '+')
2249
2275
 
2250
2276
  @lex.state = :expr_arg
2251
- util_lex_token("#foo\n+",
2277
+ assert_scanned("#foo\n+",
2252
2278
  :tNL, nil,
2253
2279
  :tUPLUS, '+')
2254
2280
  end
2255
2281
 
2256
2282
  def test_whitespace_endarg
2257
2283
  @lex.state = :expr_endarg
2258
- util_lex_token('{',
2284
+ assert_scanned('{',
2259
2285
  :tLBRACE_ARG, '{')
2260
2286
 
2261
2287
  @lex.state = :expr_endarg
2262
- util_lex_token(' {',
2288
+ assert_scanned(' {',
2263
2289
  :tLBRACE_ARG, '{')
2264
2290
 
2265
2291
  @lex.state = :expr_endarg
2266
- util_lex_token("\n{",
2292
+ assert_scanned("\n{",
2267
2293
  :tNL, nil,
2268
2294
  :tLBRACE, '{')
2269
2295
 
2270
2296
  @lex.state = :expr_endarg
2271
- util_lex_token("\\\n{",
2297
+ assert_scanned("\\\n{",
2272
2298
  :tLBRACE_ARG, '{')
2273
2299
 
2274
2300
  @lex.state = :expr_endarg
2275
- util_lex_token("#foo\n{",
2301
+ assert_scanned("#foo\n{",
2276
2302
  :tNL, nil,
2277
2303
  :tLBRACE, '{')
2278
2304
  end
2279
2305
 
2280
2306
  def test_whitespace_mid
2281
2307
  @lex.state = :expr_mid
2282
- util_lex_token('+',
2308
+ assert_scanned('+',
2283
2309
  :tUPLUS, '+')
2284
2310
 
2285
2311
  @lex.state = :expr_mid
2286
- util_lex_token(' +',
2312
+ assert_scanned(' +',
2287
2313
  :tUPLUS, '+')
2288
2314
 
2289
2315
  @lex.state = :expr_mid
2290
- util_lex_token("\n+",
2316
+ assert_scanned("\n+",
2291
2317
  :tNL, nil,
2292
2318
  :tUPLUS, '+')
2293
2319
 
2294
2320
  @lex.state = :expr_mid
2295
- util_lex_token("\\\n+",
2321
+ assert_scanned("\\\n+",
2296
2322
  :tUPLUS, '+')
2297
2323
 
2298
2324
  @lex.state = :expr_mid
2299
- util_lex_token("#foo\n+",
2325
+ assert_scanned("#foo\n+",
2300
2326
  :tNL, nil,
2301
2327
  :tUPLUS, '+')
2302
2328
  end
2303
2329
 
2304
2330
  def test_whitespace_beg
2305
2331
  @lex.state = :expr_beg
2306
- util_lex_token('+',
2332
+ assert_scanned('+',
2307
2333
  :tUPLUS, '+')
2308
2334
 
2309
2335
  @lex.state = :expr_beg
2310
- util_lex_token(' +',
2336
+ assert_scanned(' +',
2311
2337
  :tUPLUS, '+')
2312
2338
 
2313
2339
  @lex.state = :expr_beg
2314
- util_lex_token("\n+",
2340
+ assert_scanned("\n+",
2315
2341
  :tUPLUS, '+')
2316
2342
 
2317
2343
  @lex.state = :expr_beg
2318
- util_lex_token("\\\n+",
2344
+ assert_scanned("\\\n+",
2319
2345
  :tUPLUS, '+')
2320
2346
 
2321
2347
  @lex.state = :expr_beg
2322
- util_lex_token("#foo\n+",
2348
+ assert_scanned("#foo\n+",
2323
2349
  :tUPLUS, '+')
2324
2350
  end
2325
2351
 
@@ -2327,55 +2353,55 @@ class TestLexer < Minitest::Test
2327
2353
  setup_lexer(20)
2328
2354
 
2329
2355
  @lex.state = :expr_value
2330
- util_lex_token('a:b',
2356
+ assert_scanned('a:b',
2331
2357
  :tIDENTIFIER, 'a',
2332
2358
  :tSYMBOL, 'b')
2333
2359
 
2334
2360
  @lex.state = :expr_value
2335
- util_lex_token(' a:b',
2361
+ assert_scanned(' a:b',
2336
2362
  :tIDENTIFIER, 'a',
2337
2363
  :tSYMBOL, 'b')
2338
2364
 
2339
2365
  @lex.state = :expr_value
2340
- util_lex_token("\na:b",
2341
- :tLABEL, 'a',
2342
- :tIDENTIFIER, 'b')
2366
+ assert_scanned("\na:b",
2367
+ :tIDENTIFIER, 'a',
2368
+ :tSYMBOL, 'b')
2343
2369
 
2344
2370
  @lex.state = :expr_value
2345
- util_lex_token("\\\na:b",
2371
+ assert_scanned("\\\na:b",
2346
2372
  :tIDENTIFIER, 'a',
2347
2373
  :tSYMBOL, 'b')
2348
2374
 
2349
2375
  @lex.state = :expr_value
2350
- util_lex_token("#foo\na:b",
2351
- :tLABEL, 'a',
2352
- :tIDENTIFIER, 'b')
2376
+ assert_scanned("#foo\na:b",
2377
+ :tIDENTIFIER, 'a',
2378
+ :tSYMBOL, 'b')
2353
2379
  end
2354
2380
 
2355
2381
  def test_whitespace_end
2356
2382
  @lex.state = :expr_end
2357
- util_lex_token('+ 1',
2383
+ assert_scanned('+ 1',
2358
2384
  :tPLUS, '+',
2359
2385
  :tINTEGER, 1)
2360
2386
 
2361
2387
  @lex.state = :expr_end
2362
- util_lex_token(' + 1',
2388
+ assert_scanned(' + 1',
2363
2389
  :tPLUS, '+',
2364
2390
  :tINTEGER, 1)
2365
2391
 
2366
2392
  @lex.state = :expr_end
2367
- util_lex_token("\n+ 1",
2393
+ assert_scanned("\n+ 1",
2368
2394
  :tNL, nil,
2369
2395
  :tUPLUS, '+',
2370
2396
  :tINTEGER, 1)
2371
2397
 
2372
2398
  @lex.state = :expr_end
2373
- util_lex_token("\\\n+ 1",
2399
+ assert_scanned("\\\n+ 1",
2374
2400
  :tPLUS, '+',
2375
2401
  :tINTEGER, 1)
2376
2402
 
2377
2403
  @lex.state = :expr_end
2378
- util_lex_token("#foo\n+ 1",
2404
+ assert_scanned("#foo\n+ 1",
2379
2405
  :tNL, nil,
2380
2406
  :tUPLUS, '+',
2381
2407
  :tINTEGER, 1)
@@ -2390,29 +2416,29 @@ class TestLexer < Minitest::Test
2390
2416
  #
2391
2417
 
2392
2418
  def test_bug_sclass_joined
2393
- util_lex_token("class<<self",
2419
+ assert_scanned("class<<self",
2394
2420
  :kCLASS, "class",
2395
2421
  :tLSHFT, "<<",
2396
2422
  :kSELF, "self")
2397
2423
  end
2398
2424
 
2399
2425
  def test_bug_const_expr_end
2400
- util_lex_token("Option",
2426
+ assert_scanned("Option",
2401
2427
  :tCONSTANT, 'Option')
2402
2428
 
2403
- assert_equal :expr_arg, @lex.state
2429
+ assert_equal :expr_cmdarg, @lex.state
2404
2430
  end
2405
2431
 
2406
2432
  def test_bug_expr_beg_div
2407
2433
  @lex.state = :expr_beg
2408
- util_lex_token("/=/",
2434
+ assert_scanned("/=/",
2409
2435
  :tREGEXP_BEG, "/",
2410
2436
  :tSTRING_CONTENT, "=",
2411
2437
  :tSTRING_END, "/",
2412
2438
  :tREGEXP_OPT, "")
2413
2439
 
2414
2440
  @lex.state = :expr_beg
2415
- util_lex_token("/ = /",
2441
+ assert_scanned("/ = /",
2416
2442
  :tREGEXP_BEG, "/",
2417
2443
  :tSTRING_CONTENT, " = ",
2418
2444
  :tSTRING_END, "/",
@@ -2421,13 +2447,13 @@ class TestLexer < Minitest::Test
2421
2447
 
2422
2448
  def test_bug_expr_beg_percent
2423
2449
  @lex.state = :expr_beg
2424
- util_lex_token("%=foo=",
2450
+ assert_scanned("%=foo=",
2425
2451
  :tSTRING_BEG, "%=",
2426
2452
  :tSTRING_CONTENT, 'foo',
2427
2453
  :tSTRING_END, "=")
2428
2454
 
2429
2455
  @lex.state = :expr_beg
2430
- util_lex_token("% = ",
2456
+ assert_scanned("% = ",
2431
2457
  :tSTRING_BEG, "% ",
2432
2458
  :tSTRING_CONTENT, '=',
2433
2459
  :tSTRING_END, ' ')
@@ -2435,20 +2461,20 @@ class TestLexer < Minitest::Test
2435
2461
 
2436
2462
  def test_bug_expr_beg_document
2437
2463
  @lex.state = :expr_beg
2438
- util_lex_token(" \n=begin\n=end\nend",
2464
+ assert_scanned(" \n=begin\n=end\nend",
2439
2465
  :kEND, "end")
2440
2466
 
2441
2467
  end
2442
2468
 
2443
2469
  def test_bug_expr_beg_number
2444
2470
  @lex.state = :expr_beg
2445
- util_lex_token("86400_000_000",
2471
+ assert_scanned("86400_000_000",
2446
2472
  :tINTEGER, 86400_000_000)
2447
2473
  end
2448
2474
 
2449
2475
  def test_bug_expr_beg_backspace_nl
2450
2476
  @lex.state = :expr_beg
2451
- util_lex_token("\n/foo/",
2477
+ assert_scanned("\n/foo/",
2452
2478
  :tREGEXP_BEG, "/",
2453
2479
  :tSTRING_CONTENT, "foo",
2454
2480
  :tSTRING_END, "/",
@@ -2456,7 +2482,7 @@ class TestLexer < Minitest::Test
2456
2482
  end
2457
2483
 
2458
2484
  def test_bug_expr_beg_heredoc
2459
- util_lex_token("<<EOL % [\nfoo\nEOL\n]",
2485
+ assert_scanned("<<EOL % [\nfoo\nEOL\n]",
2460
2486
  :tSTRING_BEG, '"',
2461
2487
  :tSTRING_CONTENT, "foo\n",
2462
2488
  :tSTRING_END, 'EOL',
@@ -2465,40 +2491,55 @@ class TestLexer < Minitest::Test
2465
2491
  :tRBRACK, ']')
2466
2492
  end
2467
2493
 
2494
+ def test_bug_expr_beg_fid
2495
+ assert_scanned("Rainbows!",
2496
+ :tFID, 'Rainbows!')
2497
+ end
2498
+
2499
+ def test_bug_expr_beg_rescue_assoc
2500
+ assert_scanned("rescue=>",
2501
+ :kRESCUE, 'rescue',
2502
+ :tASSOC, '=>')
2503
+ end
2504
+
2468
2505
  def test_bug_expr_arg_percent
2469
2506
  @lex.state = :expr_arg
2470
- util_lex_token("%[",
2507
+ assert_scanned("%[",
2471
2508
  :tPERCENT, "%",
2472
2509
  :tLBRACK, "[")
2473
2510
 
2474
2511
  @lex.state = :expr_arg
2475
- util_lex_token("%=1",
2512
+ assert_scanned("%=1",
2476
2513
  :tOP_ASGN, "%",
2477
2514
  :tINTEGER, 1)
2478
2515
 
2479
2516
  @lex.state = :expr_arg
2480
- util_lex_token(" %[1]",
2517
+ assert_scanned(" %[1]",
2481
2518
  :tSTRING_BEG, "%[",
2482
2519
  :tSTRING_CONTENT, '1',
2483
2520
  :tSTRING_END, ']')
2484
2521
 
2485
2522
  @lex.state = :expr_arg
2486
- util_lex_token(" %=1=",
2523
+ assert_scanned(" %=1=",
2487
2524
  :tOP_ASGN, "%",
2488
2525
  :tINTEGER, 1,
2489
2526
  :tEQL, "=")
2527
+
2528
+ @lex.state = :expr_arg
2529
+ assert_scanned(" %\n",
2530
+ :tPERCENT, '%')
2490
2531
  end
2491
2532
 
2492
2533
  def test_bug_expr_arg_lt_lt
2493
2534
  @lex.state = :expr_arg
2494
- util_lex_token("<<EOS\nEOS",
2535
+ assert_scanned("<<EOS\nEOS",
2495
2536
  :tLSHFT, "<<",
2496
2537
  :tCONSTANT, "EOS",
2497
2538
  :tNL, nil,
2498
2539
  :tCONSTANT, "EOS")
2499
2540
 
2500
2541
  @lex.state = :expr_arg
2501
- util_lex_token(" <<EOS\nEOS",
2542
+ assert_scanned(" <<EOS\nEOS",
2502
2543
  :tSTRING_BEG, "\"",
2503
2544
  :tSTRING_END, "EOS",
2504
2545
  :tNL, nil)
@@ -2506,24 +2547,24 @@ class TestLexer < Minitest::Test
2506
2547
 
2507
2548
  def test_bug_expr_arg_slash
2508
2549
  @lex.state = :expr_arg
2509
- util_lex_token("/1",
2550
+ assert_scanned("/1",
2510
2551
  :tDIVIDE, "/",
2511
2552
  :tINTEGER, 1)
2512
2553
 
2513
2554
  @lex.state = :expr_arg
2514
- util_lex_token("/ 1",
2555
+ assert_scanned("/ 1",
2515
2556
  :tDIVIDE, "/",
2516
2557
  :tINTEGER, 1)
2517
2558
 
2518
2559
  @lex.state = :expr_arg
2519
- util_lex_token(" /1/",
2560
+ assert_scanned(" /1/",
2520
2561
  :tREGEXP_BEG, "/",
2521
2562
  :tSTRING_CONTENT, "1",
2522
2563
  :tSTRING_END, "/",
2523
2564
  :tREGEXP_OPT, "")
2524
2565
 
2525
2566
  @lex.state = :expr_arg
2526
- util_lex_token(" / 1",
2567
+ assert_scanned(" / 1",
2527
2568
  :tDIVIDE, "/",
2528
2569
  :tINTEGER, 1)
2529
2570
  end
@@ -2532,17 +2573,17 @@ class TestLexer < Minitest::Test
2532
2573
  setup_lexer 19
2533
2574
 
2534
2575
  @lex.state = :expr_arg
2535
- util_lex_token(" unless:",
2576
+ assert_scanned(" unless:",
2536
2577
  :tLABEL, 'unless')
2537
2578
 
2538
2579
  @lex.state = :expr_arg
2539
- util_lex_token(" unless: ",
2580
+ assert_scanned(" unless: ",
2540
2581
  :tLABEL, 'unless')
2541
2582
  end
2542
2583
 
2543
2584
  def test_bug_heredoc_continuation
2544
2585
  @lex.state = :expr_arg
2545
- util_lex_token(" <<EOS\nEOS\nend",
2586
+ assert_scanned(" <<EOS\nEOS\nend",
2546
2587
  :tSTRING_BEG, "\"",
2547
2588
  :tSTRING_END, "EOS",
2548
2589
  :tNL, nil,
@@ -2550,15 +2591,15 @@ class TestLexer < Minitest::Test
2550
2591
  end
2551
2592
 
2552
2593
  def test_bug_heredoc_cr_lf
2553
- util_lex_token("<<FIN\r\nfoo\r\nFIN\r\n",
2594
+ assert_scanned("<<FIN\r\nfoo\r\nFIN\r\n",
2554
2595
  :tSTRING_BEG, "\"",
2555
- :tSTRING_CONTENT, "foo\r\n",
2596
+ :tSTRING_CONTENT, "foo\n",
2556
2597
  :tSTRING_END, "FIN",
2557
2598
  :tNL, nil)
2558
2599
  end
2559
2600
 
2560
2601
  def test_bug_eh_symbol_no_newline
2561
- util_lex_token("?\"\nfoo",
2602
+ assert_scanned("?\"\nfoo",
2562
2603
  :tINTEGER, 34,
2563
2604
  :tNL, nil,
2564
2605
  :tIDENTIFIER, "foo")
@@ -2566,30 +2607,36 @@ class TestLexer < Minitest::Test
2566
2607
 
2567
2608
  def test_bug_expr_arg_newline
2568
2609
  @lex.state = :expr_arg
2569
- util_lex_token("\nfoo",
2610
+ assert_scanned("\nfoo",
2570
2611
  :tNL, nil,
2571
2612
  :tIDENTIFIER, "foo")
2572
2613
 
2573
2614
  @lex.state = :expr_arg
2574
- util_lex_token(" \nfoo",
2615
+ assert_scanned(" \nfoo",
2575
2616
  :tNL, nil,
2576
2617
  :tIDENTIFIER, "foo")
2577
2618
 
2578
2619
  @lex.state = :expr_arg
2579
- util_lex_token("#foo\nfoo",
2620
+ assert_scanned("#foo\nfoo",
2580
2621
  :tNL, nil,
2581
2622
  :tIDENTIFIER, "foo")
2582
2623
  end
2583
2624
 
2584
2625
  def test_bug_expr_arg_comment_newline
2585
2626
  @lex.state = :expr_arg
2586
- util_lex_token(" #\nfoo",
2627
+ assert_scanned(" #\nfoo",
2587
2628
  :tNL, nil,
2588
2629
  :tIDENTIFIER, 'foo')
2589
2630
  end
2590
2631
 
2632
+ def test_bug_expr_arg_eh_crlf
2633
+ @lex.state = :expr_arg
2634
+ assert_scanned(" ?\r\n",
2635
+ :tEH, '?')
2636
+ end
2637
+
2591
2638
  def test_bug_heredoc_backspace_nl
2592
- util_lex_token(" <<'XXX'\nf \\\nXXX\n",
2639
+ assert_scanned(" <<'XXX'\nf \\\nXXX\n",
2593
2640
  :tSTRING_BEG, "'",
2594
2641
  :tSTRING_CONTENT, "f \\\n",
2595
2642
  :tSTRING_END, "XXX",
@@ -2597,7 +2644,7 @@ class TestLexer < Minitest::Test
2597
2644
  end
2598
2645
 
2599
2646
  def test_bug_heredoc_lshft
2600
- util_lex_token("<<RULES << CLEANINGS\nRULES",
2647
+ assert_scanned("<<RULES << CLEANINGS\nRULES",
2601
2648
  :tSTRING_BEG, '"',
2602
2649
  :tSTRING_END, 'RULES',
2603
2650
  :tLSHFT, '<<',
@@ -2605,7 +2652,7 @@ class TestLexer < Minitest::Test
2605
2652
  end
2606
2653
 
2607
2654
  def test_bug_sclass_comment_lshft_label
2608
- util_lex_token("class # foo\n<< a:b;end",
2655
+ assert_scanned("class # foo\n<< a:b;end",
2609
2656
  :kCLASS, 'class',
2610
2657
  :tLSHFT, '<<',
2611
2658
  :tIDENTIFIER, 'a',
@@ -2615,59 +2662,278 @@ class TestLexer < Minitest::Test
2615
2662
  end
2616
2663
 
2617
2664
  def test_bug_expr_dot_comment
2618
- util_lex_token("foo. #bar\nbaz",
2665
+ assert_scanned("foo. #bar\nbaz",
2619
2666
  :tIDENTIFIER, 'foo',
2620
2667
  :tDOT, '.',
2621
2668
  :tIDENTIFIER, 'baz')
2622
2669
  end
2623
2670
 
2671
+ def test_bug_expr_dot_fid
2672
+ assert_scanned("foo.S?",
2673
+ :tIDENTIFIER, 'foo',
2674
+ :tDOT, '.',
2675
+ :tFID, 'S?')
2676
+ end
2677
+
2678
+ def test_bug_expr_dot_id_eq
2679
+ assert_scanned("foo.x= 1",
2680
+ :tIDENTIFIER, 'foo',
2681
+ :tDOT, '.',
2682
+ :tIDENTIFIER, 'x',
2683
+ :tEQL, '=',
2684
+ :tINTEGER, 1)
2685
+ end
2686
+
2687
+ def test_bug_expr_dot_fid_mod
2688
+ assert_scanned("foo.x!if 1",
2689
+ :tIDENTIFIER, 'foo',
2690
+ :tDOT, '.',
2691
+ :tFID, 'x!',
2692
+ :kIF_MOD, 'if',
2693
+ :tINTEGER, 1)
2694
+ end
2695
+
2624
2696
  def test_bug_expr_mid_comment
2625
- util_lex_token("rescue #bar\nprint",
2697
+ assert_scanned("rescue #bar\nprint",
2626
2698
  :kRESCUE, 'rescue',
2627
2699
  :tNL, nil,
2628
2700
  :tIDENTIFIER, 'print')
2629
2701
  end
2630
2702
 
2703
+ def test_bug_expr_mid_bareword
2704
+ assert_scanned("begin; rescue rescue1",
2705
+ :kBEGIN, 'begin',
2706
+ :tSEMI, ';',
2707
+ :kRESCUE, 'rescue',
2708
+ :tIDENTIFIER, 'rescue1')
2709
+ end
2710
+
2631
2711
  def test_bug_expr_value_document
2632
- util_lex_token("1;\n=begin\n=end",
2712
+ assert_scanned("1;\n=begin\n=end",
2633
2713
  :tINTEGER, 1,
2634
2714
  :tSEMI, ';')
2635
2715
  end
2636
2716
 
2637
2717
  def test_bug_expr_end_colon
2638
- util_lex_token("'foo':'bar'",
2718
+ assert_scanned("'foo':'bar'",
2639
2719
  :tSTRING, 'foo',
2640
2720
  :tCOLON, ':',
2641
2721
  :tSTRING, 'bar')
2642
2722
  end
2643
2723
 
2724
+ def test_bug_expr_value_rescue_colon2
2725
+ @lex.state = :expr_value
2726
+ assert_scanned("rescue::Exception",
2727
+ :kRESCUE, 'rescue',
2728
+ :tCOLON3, '::',
2729
+ :tCONSTANT, 'Exception')
2730
+ end
2731
+
2732
+ def test_bug_expr_endarg_braces
2733
+ assert_scanned("let [] {",
2734
+ :tIDENTIFIER, 'let',
2735
+ :tLBRACK, '[',
2736
+ :tRBRACK, ']',
2737
+ :tLBRACE_ARG, '{')
2738
+ end
2739
+
2740
+ def test_bug_line_begin_label
2741
+ setup_lexer(19)
2742
+ assert_scanned("foo:bar",
2743
+ :tIDENTIFIER, 'foo',
2744
+ :tSYMBOL, 'bar')
2745
+ end
2746
+
2747
+ def test_bug_interp_expr_value
2748
+ assert_scanned('"#{f:a}"',
2749
+ :tSTRING_BEG, '"',
2750
+ :tSTRING_DBEG, '#{',
2751
+ :tIDENTIFIER, 'f',
2752
+ :tSYMBOL, 'a',
2753
+ :tRCURLY, '}',
2754
+ :tSTRING_END, '"')
2755
+ end
2756
+
2757
+ def test_bug_const_e
2758
+ assert_scanned('E10',
2759
+ :tCONSTANT, 'E10')
2760
+ assert_scanned('E4U',
2761
+ :tCONSTANT, 'E4U')
2762
+ end
2763
+
2644
2764
  def test_bug_symbol_newline
2645
- util_lex_token(":foo\n",
2765
+ assert_scanned(":foo\n",
2646
2766
  :tSYMBOL, 'foo',
2647
2767
  :tNL, nil)
2648
2768
 
2649
- util_lex_token(":foo=\n",
2769
+ assert_scanned(":foo=\n",
2650
2770
  :tSYMBOL, 'foo=',
2651
2771
  :tNL, nil)
2652
2772
  end
2653
2773
 
2654
- def test_bug_expr_value_rescue_colon2
2655
- @lex.state = :expr_value
2656
- util_lex_token("rescue::Exception",
2657
- :kRESCUE, 'rescue',
2658
- :tCOLON3, '::',
2659
- :tCONSTANT, 'Exception')
2774
+ def test_bug_interleaved_heredoc
2775
+ assert_scanned(%Q{<<w; "\nfoo\nw\n"},
2776
+ :tSTRING_BEG, '"',
2777
+ :tSTRING_CONTENT, "foo\n",
2778
+ :tSTRING_END, 'w',
2779
+ :tSEMI, ';',
2780
+ :tSTRING_BEG, '"',
2781
+ :tSTRING_CONTENT, "\n",
2782
+ :tSTRING_END, '"')
2783
+
2784
+ @lex.state = :expr_beg
2785
+ assert_scanned(%Q{<<w; %w[\nfoo\nw\n1]},
2786
+ :tSTRING_BEG, '"',
2787
+ :tSTRING_CONTENT, "foo\n",
2788
+ :tSTRING_END, 'w',
2789
+ :tSEMI, ';',
2790
+ :tQWORDS_BEG, '%w[',
2791
+ :tSTRING_CONTENT, "1",
2792
+ :tSPACE, nil,
2793
+ :tSTRING_END, ']')
2794
+
2795
+ @lex.state = :expr_beg
2796
+ assert_scanned(%Q{<<w; "\#{\nfoo\nw\n}"},
2797
+ :tSTRING_BEG, '"',
2798
+ :tSTRING_CONTENT, "foo\n",
2799
+ :tSTRING_END, 'w',
2800
+ :tSEMI, ';',
2801
+ :tSTRING_BEG, '"',
2802
+ :tSTRING_DBEG, '#{',
2803
+ :tRCURLY, '}',
2804
+ :tSTRING_END, '"')
2660
2805
  end
2661
2806
 
2662
- def test_bug_line_begin_label
2807
+ def test_bug_fid_char
2663
2808
  setup_lexer(19)
2664
- util_lex_token("foo:bar",
2809
+ assert_scanned(%Q{eof??a},
2810
+ :tFID, 'eof?',
2811
+ :tSTRING, 'a')
2812
+ end
2813
+
2814
+ def test_bug_nonlabel_context__18
2815
+ env = Parser::StaticEnvironment.new
2816
+ env.declare "a"
2817
+
2818
+ @lex.static_env = env
2819
+ assert_scanned("1+a:a",
2820
+ :tINTEGER, 1,
2821
+ :tPLUS, '+',
2822
+ :tIDENTIFIER, 'a',
2823
+ :tCOLON, ':',
2824
+ :tIDENTIFIER, 'a')
2825
+ end
2826
+
2827
+ def test_bug_string_percent_newline
2828
+ assert_scanned(%Q{%\nfoo\n},
2829
+ :tSTRING_BEG, "%\n",
2830
+ :tSTRING_CONTENT, 'foo',
2831
+ :tSTRING_END, "\n")
2832
+ end
2833
+
2834
+ def test_bug_string_percent_zero
2835
+ assert_scanned(%Q{%\0foo\0},
2836
+ :tSTRING_BEG, "%\0",
2837
+ :tSTRING_CONTENT, 'foo',
2838
+ :tSTRING_END, "\0")
2839
+ end
2840
+
2841
+ def test_bug_string_utf_escape_composition
2842
+ assert_scanned(%q{"\xE2\x80\x99"},
2843
+ :tSTRING, "\xE2\x80\x99")
2844
+
2845
+ if defined?(Encoding)
2846
+ assert_scanned(%q{"\xE2\x80\x99"}.force_encoding(Encoding::UTF_8),
2847
+ :tSTRING, '’'.force_encoding(Encoding::UTF_8))
2848
+ assert_scanned(%q{"\342\200\231"}.force_encoding(Encoding::UTF_8),
2849
+ :tSTRING, '’'.force_encoding(Encoding::UTF_8))
2850
+ assert_scanned(%q{"\M-b\C-\M-@\C-\M-Y"}.force_encoding(Encoding::UTF_8),
2851
+ :tSTRING, '’'.force_encoding(Encoding::UTF_8))
2852
+ end
2853
+ end
2854
+
2855
+ def test_bug_string_non_utf
2856
+ assert_scanned(%Q{"caf\xE9"},
2857
+ :tSTRING, "caf\xE9")
2858
+ assert_scanned(%Q{"caf\xC3\xA9"},
2859
+ :tSTRING, "caf\xC3\xA9")
2860
+
2861
+ if defined?(Encoding)
2862
+ assert_scanned(%q{"café"}.force_encoding(Encoding::UTF_8),
2863
+ :tSTRING, "café".force_encoding(Encoding::UTF_8))
2864
+ end
2865
+ end
2866
+
2867
+ def test_bug_semi__END__
2868
+ assert_scanned(%Q{foo;\n__END__},
2665
2869
  :tIDENTIFIER, 'foo',
2666
- :tSYMBOL, 'bar')
2870
+ :tSEMI, ';')
2871
+ end
2872
+
2873
+ def test_bug_eql_end
2874
+ assert_scanned(%Q{=begin\n#=end\n=end})
2875
+ end
2876
+
2877
+ def test_bug_hidden_eof
2878
+ @lex.state = :expr_beg
2879
+ assert_scanned(%Q{"foo\0\x1a\x04bar"},
2880
+ :tSTRING_BEG, '"',
2881
+ :tSTRING_CONTENT, "foo\0",
2882
+ :tSTRING_CONTENT, "\x1a",
2883
+ :tSTRING_CONTENT, "\x04",
2884
+ :tSTRING_CONTENT, "bar",
2885
+ :tSTRING_END, '"')
2886
+
2887
+ @lex.state = :expr_beg
2888
+ assert_scanned(%Q{'foo\0\x1a\x04bar'},
2889
+ :tSTRING_BEG, "'",
2890
+ :tSTRING_CONTENT, "foo\0",
2891
+ :tSTRING_CONTENT, "\x1a",
2892
+ :tSTRING_CONTENT, "\x04",
2893
+ :tSTRING_CONTENT, "bar",
2894
+ :tSTRING_END, "'")
2895
+
2896
+ @lex.state = :expr_beg
2897
+ assert_scanned(%Q{%w[foo\0\x1a\x04bar]},
2898
+ :tQWORDS_BEG, '%w[',
2899
+ :tSTRING_CONTENT, "foo\0",
2900
+ :tSTRING_CONTENT, "\x1a",
2901
+ :tSTRING_CONTENT, "\x04",
2902
+ :tSTRING_CONTENT, "bar",
2903
+ :tSPACE, nil,
2904
+ :tSTRING_END, ']')
2905
+
2906
+ @lex.state = :expr_beg
2907
+ assert_scanned(%Q{%W[foo\0\x1a\x04bar]},
2908
+ :tWORDS_BEG, '%W[',
2909
+ :tSTRING_CONTENT, "foo\0",
2910
+ :tSTRING_CONTENT, "\x1a",
2911
+ :tSTRING_CONTENT, "\x04",
2912
+ :tSTRING_CONTENT, "bar",
2913
+ :tSPACE, nil,
2914
+ :tSTRING_END, ']')
2915
+
2916
+ @lex.state = :expr_beg
2917
+ assert_scanned(%Q{# foo\0\nbar},
2918
+ :tIDENTIFIER, 'bar')
2919
+
2920
+ @lex.state = :line_begin
2921
+ assert_scanned(%Q{=begin\n\0\n=end\nbar},
2922
+ :tIDENTIFIER, 'bar')
2923
+ end
2924
+
2925
+ def test_bug_num_adj_kw
2926
+ assert_scanned(%q{1if},
2927
+ :tINTEGER, 1,
2928
+ :kIF_MOD, 'if')
2929
+
2930
+ assert_scanned(%q{1.0if},
2931
+ :tFLOAT, 1.0,
2932
+ :kIF_MOD, 'if')
2667
2933
  end
2668
2934
 
2669
2935
  def test_bug_ragel_stack
2670
- util_lex_token("\"\#{$2 ? $2 : 1}\"",
2936
+ assert_scanned("\"\#{$2 ? $2 : 1}\"",
2671
2937
  :tSTRING_BEG, "\"",
2672
2938
  :tSTRING_DBEG, "\#{",
2673
2939
  :tNTH_REF, 2,