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