parser 0.9.alpha1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/AST_FORMAT.md +1338 -0
- data/README.md +58 -3
- data/Rakefile +32 -12
- data/bin/benchmark +47 -0
- data/bin/explain-parse +14 -0
- data/bin/parse +6 -0
- data/lib/parser.rb +84 -0
- data/lib/parser/all.rb +2 -0
- data/lib/parser/ast/node.rb +11 -0
- data/lib/parser/ast/processor.rb +8 -0
- data/lib/parser/base.rb +116 -0
- data/lib/parser/builders/default.rb +654 -0
- data/lib/parser/compatibility/ruby1_8.rb +13 -0
- data/lib/parser/diagnostic.rb +44 -0
- data/lib/parser/diagnostic/engine.rb +44 -0
- data/lib/parser/lexer.rl +335 -245
- data/lib/parser/lexer/explanation.rb +37 -0
- data/lib/parser/{lexer_literal.rb → lexer/literal.rb} +22 -12
- data/lib/parser/lexer/stack_state.rb +38 -0
- data/lib/parser/ruby18.y +1957 -0
- data/lib/parser/ruby19.y +2154 -0
- data/lib/parser/source/buffer.rb +78 -0
- data/lib/parser/source/map.rb +20 -0
- data/lib/parser/source/map/operator.rb +15 -0
- data/lib/parser/source/map/variable_assignment.rb +15 -0
- data/lib/parser/source/range.rb +66 -0
- data/lib/parser/static_environment.rb +12 -6
- data/parser.gemspec +23 -13
- data/test/helper.rb +45 -0
- data/test/parse_helper.rb +204 -0
- data/test/racc_coverage_helper.rb +130 -0
- data/test/test_diagnostic.rb +47 -0
- data/test/test_diagnostic_engine.rb +58 -0
- data/test/test_lexer.rb +601 -357
- data/test/test_lexer_stack_state.rb +69 -0
- data/test/test_parse_helper.rb +74 -0
- data/test/test_parser.rb +3654 -0
- data/test/test_source_buffer.rb +80 -0
- data/test/test_source_range.rb +51 -0
- data/test/test_static_environment.rb +1 -4
- metadata +137 -12
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'racc/grammarfileparser'
|
2
|
+
|
3
|
+
# Unfortunately, Ruby's Coverage module ignores module_eval statements,
|
4
|
+
# which Racc uses to map `parser.y` locations in the generated
|
5
|
+
# `parser.rb`.
|
6
|
+
module RaccCoverage
|
7
|
+
@coverage = {}
|
8
|
+
@base_path = nil
|
9
|
+
@trace = nil
|
10
|
+
|
11
|
+
def self.start(parsers, base_path)
|
12
|
+
@base_path = base_path
|
13
|
+
|
14
|
+
parsers.each do |parser|
|
15
|
+
@coverage[parser] = extract_interesting_lines(parser, base_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
@trace = TracePoint.trace(:line) do |trace|
|
19
|
+
lineno = trace.lineno - 1
|
20
|
+
|
21
|
+
if (line_coverage = @coverage[trace.path])
|
22
|
+
if line_coverage[lineno]
|
23
|
+
line_coverage[lineno] += 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.stop
|
30
|
+
@trace.disable
|
31
|
+
end
|
32
|
+
|
33
|
+
# Ruby's TracePoint#lineno will point only on "interesting" lines,
|
34
|
+
# i.e.: only code (no comments or empty lines), no `end` keywords,
|
35
|
+
# and for multi-line statements, only the first line of the statement.
|
36
|
+
#
|
37
|
+
# This method implements a very dumb Ruby parser, which skips empty lines
|
38
|
+
# or lines with just comments, `end` keywords, and correctly handles
|
39
|
+
# multi-line statements of the following form:
|
40
|
+
#
|
41
|
+
# * All lines of the statement except the last must end with `,`, `.` or `(`.
|
42
|
+
#
|
43
|
+
# Coverage can be disabled for code regions with annotations :nocov: and :cov:.
|
44
|
+
#
|
45
|
+
# Also, for best results, all actions should be delimited by at least
|
46
|
+
# one non-action line.
|
47
|
+
#
|
48
|
+
def self.extract_interesting_lines(parser, base_path)
|
49
|
+
grammar_source = File.join(@base_path, parser)
|
50
|
+
grammar_file = Racc::GrammarFileParser.parse_file(grammar_source)
|
51
|
+
|
52
|
+
ruby_sources = [
|
53
|
+
# Header and footer aren't passed through module_eval
|
54
|
+
# in Racc-generated file, so the location info is lost.
|
55
|
+
*grammar_file.params.inner,
|
56
|
+
].compact
|
57
|
+
|
58
|
+
grammar_file.grammar.each_rule do |rule|
|
59
|
+
source = rule.action.source
|
60
|
+
next if source.nil?
|
61
|
+
|
62
|
+
ruby_sources << source
|
63
|
+
end
|
64
|
+
|
65
|
+
lines = []
|
66
|
+
|
67
|
+
ruby_sources.each do |source|
|
68
|
+
first_line = source.lineno
|
69
|
+
|
70
|
+
state = :first_line
|
71
|
+
|
72
|
+
source.text.each_line.with_index do |line, index|
|
73
|
+
line = line.strip
|
74
|
+
|
75
|
+
continues = line.end_with?(',') ||
|
76
|
+
line.end_with?('(') ||
|
77
|
+
line.end_with?('.')
|
78
|
+
|
79
|
+
case state
|
80
|
+
when :first_line
|
81
|
+
if line =~ /:nocov/
|
82
|
+
state = :nocov
|
83
|
+
next
|
84
|
+
elsif line.empty? ||
|
85
|
+
line == 'end' ||
|
86
|
+
line.start_with?('#')
|
87
|
+
next
|
88
|
+
elsif continues
|
89
|
+
state = :mid_line
|
90
|
+
end
|
91
|
+
|
92
|
+
lines[first_line + index - 1] = 0
|
93
|
+
|
94
|
+
when :mid_line
|
95
|
+
unless continues
|
96
|
+
state = :first_line
|
97
|
+
end
|
98
|
+
|
99
|
+
when :nocov
|
100
|
+
if line =~ /:cov:/
|
101
|
+
state = :first_line
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
lines
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.result
|
111
|
+
result =
|
112
|
+
@coverage.map do |parser, coverage|
|
113
|
+
[File.join(@base_path, parser), coverage]
|
114
|
+
end
|
115
|
+
|
116
|
+
Hash[result]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
class << SimpleCov
|
121
|
+
def result_with_racc_coverage
|
122
|
+
@result ||= SimpleCov::Result.new(
|
123
|
+
Coverage.result.merge(RaccCoverage.result))
|
124
|
+
|
125
|
+
result_without_racc_coverage
|
126
|
+
end
|
127
|
+
|
128
|
+
alias result_without_racc_coverage result
|
129
|
+
alias result result_with_racc_coverage
|
130
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDiagnostic < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@buffer = Parser::Source::Buffer.new('(string)')
|
6
|
+
@buffer.source = "if (this is some bad code + bugs)"
|
7
|
+
|
8
|
+
@range1 = Parser::Source::Range.new(@buffer, 0, 1) # if
|
9
|
+
@range2 = Parser::Source::Range.new(@buffer, 4, 7) # this
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_verifies_levels
|
13
|
+
assert_raises ArgumentError, /level/ do
|
14
|
+
Parser::Diagnostic.new(:foobar, "foo", @range1)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_freezes
|
19
|
+
string = "foo"
|
20
|
+
highlights = [@range2]
|
21
|
+
|
22
|
+
diag = Parser::Diagnostic.new(:error, string, @range1, highlights)
|
23
|
+
assert diag.frozen?
|
24
|
+
assert diag.message.frozen?
|
25
|
+
assert diag.highlights.frozen?
|
26
|
+
|
27
|
+
refute string.frozen?
|
28
|
+
refute highlights.frozen?
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_render
|
32
|
+
location = Parser::Source::Range.new(@buffer, 26, 26)
|
33
|
+
|
34
|
+
highlights = [
|
35
|
+
Parser::Source::Range.new(@buffer, 21, 24),
|
36
|
+
Parser::Source::Range.new(@buffer, 28, 31)
|
37
|
+
]
|
38
|
+
|
39
|
+
diag = Parser::Diagnostic.new(:error, "code far too bad",
|
40
|
+
location, highlights)
|
41
|
+
assert_equal([
|
42
|
+
"(string):1:27: error: code far too bad",
|
43
|
+
"if (this is some bad code + bugs)",
|
44
|
+
" ~~~~ ^ ~~~~ "
|
45
|
+
], diag.render)
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestDiagnosticEngine < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@buffer = Parser::Source::Buffer.new('(source)')
|
6
|
+
@buffer.source = 'foobar'
|
7
|
+
|
8
|
+
@engine = Parser::Diagnostic::Engine.new
|
9
|
+
|
10
|
+
@queue = []
|
11
|
+
@engine.consumer = lambda { |diag| @queue << diag }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_process_warnings
|
15
|
+
warn = Parser::Diagnostic.new(:warning, "foo", @buffer, 1..2)
|
16
|
+
@engine.process(warn)
|
17
|
+
|
18
|
+
assert_equal [warn], @queue
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_ignore_warnings
|
22
|
+
@engine.ignore_warnings = true
|
23
|
+
|
24
|
+
warn = Parser::Diagnostic.new(:warning, "foo", @buffer, 1..2)
|
25
|
+
@engine.process(warn)
|
26
|
+
|
27
|
+
assert_equal [], @queue
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_all_errors_are_fatal
|
31
|
+
@engine.all_errors_are_fatal = true
|
32
|
+
|
33
|
+
error = Parser::Diagnostic.new(:error, "foo", @buffer, 1..2)
|
34
|
+
|
35
|
+
assert_raises Parser::SyntaxError do
|
36
|
+
@engine.process(error)
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal [error], @queue
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_all_errors_are_collected
|
43
|
+
error = Parser::Diagnostic.new(:error, "foo", @buffer, 1..2)
|
44
|
+
@engine.process(error)
|
45
|
+
|
46
|
+
assert_equal [error], @queue
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_fatal_error
|
50
|
+
fatal = Parser::Diagnostic.new(:fatal, "foo", @buffer, 1..2)
|
51
|
+
|
52
|
+
assert_raises Parser::SyntaxError do
|
53
|
+
@engine.process(fatal)
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_equal [fatal], @queue
|
57
|
+
end
|
58
|
+
end
|
data/test/test_lexer.rb
CHANGED
@@ -1,28 +1,38 @@
|
|
1
1
|
# encoding: ascii-8bit
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'parser/lexer'
|
3
|
+
require 'helper'
|
5
4
|
|
6
5
|
class TestLexer < MiniTest::Unit::TestCase
|
7
|
-
def setup_lexer
|
6
|
+
def setup_lexer(version)
|
8
7
|
@lex = Parser::Lexer.new(version)
|
8
|
+
|
9
|
+
@lex.diagnostics = Parser::Diagnostic::Engine.new
|
10
|
+
@lex.diagnostics.all_errors_are_fatal = true
|
11
|
+
# @lex.diagnostics.consumer = lambda { |diag| $stderr.puts "", diag.render }
|
9
12
|
end
|
10
13
|
|
11
14
|
def setup
|
12
15
|
setup_lexer 18
|
13
16
|
end
|
14
17
|
|
15
|
-
|
18
|
+
#
|
19
|
+
# Additional matchers
|
20
|
+
#
|
21
|
+
|
22
|
+
def util_bad_token(s, *args)
|
16
23
|
assert_raises Parser::SyntaxError do
|
17
|
-
util_lex_token
|
24
|
+
util_lex_token(s, *args)
|
18
25
|
end
|
19
26
|
end
|
20
27
|
|
21
|
-
def util_escape
|
28
|
+
def util_escape(expected, input)
|
29
|
+
source_buffer = Parser::Source::Buffer.new('(util_escape)')
|
30
|
+
source_buffer.source = "%Q[\\#{input}]"
|
31
|
+
|
22
32
|
@lex.reset
|
23
|
-
@lex.
|
33
|
+
@lex.source_buffer = source_buffer
|
24
34
|
|
25
|
-
lex_token, lex_value = @lex.advance
|
35
|
+
lex_token, (lex_value, *) = @lex.advance
|
26
36
|
|
27
37
|
if lex_value.respond_to?(:force_encoding)
|
28
38
|
lex_value.force_encoding('ASCII-8BIT')
|
@@ -30,47 +40,44 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
30
40
|
|
31
41
|
assert_equal [:tSTRING, expected],
|
32
42
|
[lex_token, lex_value],
|
33
|
-
|
43
|
+
source_buffer.source
|
34
44
|
end
|
35
45
|
|
36
|
-
def util_escape_bad
|
46
|
+
def util_escape_bad(input)
|
37
47
|
assert_raises Parser::SyntaxError do
|
38
48
|
@lex.state = :expr_beg
|
39
49
|
util_lex_token "%Q[\\#{input}]"
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
43
|
-
def util_lex_fname
|
44
|
-
util_lex_token("def #{name} ", :kDEF,
|
53
|
+
def util_lex_fname(name, type, end_state = :expr_end)
|
54
|
+
util_lex_token("def #{name} ", :kDEF, 'def', type, name)
|
45
55
|
|
46
56
|
assert_equal end_state, @lex.state
|
47
57
|
end
|
48
58
|
|
49
|
-
def util_lex_token
|
59
|
+
def util_lex_token(input, *args)
|
60
|
+
source_buffer = Parser::Source::Buffer.new('(util_lex_token)')
|
61
|
+
source_buffer.source = input
|
62
|
+
|
50
63
|
@lex.reset(false)
|
51
|
-
@lex.
|
64
|
+
@lex.source_buffer = source_buffer
|
52
65
|
|
53
66
|
until args.empty? do
|
54
67
|
token, value = args.shift(2)
|
55
68
|
|
56
|
-
lex_token, lex_value = @lex.advance
|
57
|
-
assert lex_token,
|
69
|
+
lex_token, (lex_value, *) = @lex.advance
|
70
|
+
assert lex_token, 'no more tokens'
|
58
71
|
assert_equal [token, value], [lex_token, lex_value], input
|
59
72
|
end
|
60
73
|
|
61
|
-
lex_token, lex_value = @lex.advance
|
74
|
+
lex_token, (lex_value, *) = @lex.advance
|
62
75
|
refute lex_token, "must be empty, but had #{[lex_token, lex_value].inspect}"
|
63
76
|
end
|
64
77
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
token, = @lex.advance
|
69
|
-
assert token # blah
|
70
|
-
|
71
|
-
token, = @lex.advance
|
72
|
-
refute token # nada
|
73
|
-
end
|
78
|
+
#
|
79
|
+
# Tests
|
80
|
+
#
|
74
81
|
|
75
82
|
def test_read_escape
|
76
83
|
util_escape "\\", "\\"
|
@@ -121,19 +128,23 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
121
128
|
end
|
122
129
|
|
123
130
|
def test_read_escape_unicode__19
|
124
|
-
|
131
|
+
if RUBY_VERSION >= '1.9'
|
132
|
+
util_escape "\xc4\xa3", 'u0123'
|
125
133
|
|
126
|
-
|
134
|
+
util_escape "\xc4\xa3\xc3\xb0\xeb\x84\xa3", 'u{123 f0 B123}'
|
135
|
+
end
|
127
136
|
end
|
128
137
|
|
129
138
|
def test_read_escape_unicode_bad__19
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
139
|
+
if RUBY_VERSION >= '1.9'
|
140
|
+
util_escape_bad 'u123'
|
141
|
+
util_escape_bad 'u{}'
|
142
|
+
util_escape_bad 'u{123 f0h}'
|
143
|
+
util_escape_bad 'u{123 f0'
|
144
|
+
end
|
134
145
|
end
|
135
146
|
|
136
|
-
def
|
147
|
+
def test_ambiguous_uminus
|
137
148
|
util_lex_token("m -3",
|
138
149
|
:tIDENTIFIER, "m",
|
139
150
|
:tUMINUS_NUM, "-",
|
@@ -141,30 +152,30 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
141
152
|
# TODO: verify warning
|
142
153
|
end
|
143
154
|
|
144
|
-
def
|
155
|
+
def test_ambiguous_uplus
|
145
156
|
util_lex_token("m +3",
|
146
157
|
:tIDENTIFIER, "m",
|
147
158
|
:tINTEGER, 3)
|
148
159
|
# TODO: verify warning
|
149
160
|
end
|
150
161
|
|
151
|
-
def
|
162
|
+
def test_and
|
152
163
|
util_lex_token "&", :tAMPER, "&"
|
153
164
|
end
|
154
165
|
|
155
|
-
def
|
166
|
+
def test_and2
|
156
167
|
@lex.state = :expr_end
|
157
168
|
|
158
169
|
util_lex_token "&&", :tANDOP, "&&"
|
159
170
|
end
|
160
171
|
|
161
|
-
def
|
172
|
+
def test_and2_equals
|
162
173
|
@lex.state = :expr_end
|
163
174
|
|
164
175
|
util_lex_token "&&=", :tOP_ASGN, "&&"
|
165
176
|
end
|
166
177
|
|
167
|
-
def
|
178
|
+
def test_and_arg
|
168
179
|
@lex.state = :expr_arg
|
169
180
|
|
170
181
|
util_lex_token(" &y",
|
@@ -172,13 +183,13 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
172
183
|
:tIDENTIFIER, "y")
|
173
184
|
end
|
174
185
|
|
175
|
-
def
|
186
|
+
def test_and_equals
|
176
187
|
@lex.state = :expr_end
|
177
188
|
|
178
189
|
util_lex_token "&=", :tOP_ASGN, "&"
|
179
190
|
end
|
180
191
|
|
181
|
-
def
|
192
|
+
def test_and_expr
|
182
193
|
@lex.state = :expr_arg
|
183
194
|
|
184
195
|
util_lex_token("x & y",
|
@@ -187,22 +198,22 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
187
198
|
:tIDENTIFIER, "y")
|
188
199
|
end
|
189
200
|
|
190
|
-
def
|
201
|
+
def test_and_meth
|
191
202
|
util_lex_fname "&", :tAMPER2
|
192
203
|
end
|
193
204
|
|
194
|
-
def
|
205
|
+
def test_assoc
|
195
206
|
util_lex_token "=>", :tASSOC, "=>"
|
196
207
|
end
|
197
208
|
|
198
|
-
def
|
209
|
+
def test_label__18
|
199
210
|
util_lex_token("{a:b",
|
200
211
|
:tLBRACE, "{",
|
201
212
|
:tIDENTIFIER, "a",
|
202
213
|
:tSYMBOL, "b")
|
203
214
|
end
|
204
215
|
|
205
|
-
def
|
216
|
+
def test_label_in_params__18
|
206
217
|
util_lex_token("foo(a:b",
|
207
218
|
:tIDENTIFIER, "foo",
|
208
219
|
:tLPAREN2, "(",
|
@@ -210,7 +221,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
210
221
|
:tSYMBOL, "b")
|
211
222
|
end
|
212
223
|
|
213
|
-
def
|
224
|
+
def test_label__19
|
214
225
|
setup_lexer 19
|
215
226
|
|
216
227
|
util_lex_token("{a:b",
|
@@ -219,7 +230,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
219
230
|
:tIDENTIFIER, "b")
|
220
231
|
end
|
221
232
|
|
222
|
-
def
|
233
|
+
def test_label_in_params__19
|
223
234
|
setup_lexer 19
|
224
235
|
|
225
236
|
util_lex_token("foo(a:b",
|
@@ -229,7 +240,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
229
240
|
:tIDENTIFIER, "b")
|
230
241
|
end
|
231
242
|
|
232
|
-
def
|
243
|
+
def test_command_start__19
|
233
244
|
setup_lexer 19
|
234
245
|
|
235
246
|
%w[case elsif for in until when while
|
@@ -244,7 +255,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
244
255
|
end
|
245
256
|
end
|
246
257
|
|
247
|
-
def
|
258
|
+
def test_mod_not_command_start__19
|
248
259
|
setup_lexer 19
|
249
260
|
|
250
261
|
%w[if unless while until rescue].each do |keyword|
|
@@ -258,43 +269,43 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
258
269
|
end
|
259
270
|
end
|
260
271
|
|
261
|
-
def
|
272
|
+
def test_back_ref
|
262
273
|
util_lex_token("[$&, $`, $', $+]",
|
263
274
|
:tLBRACK, "[",
|
264
|
-
:tBACK_REF,
|
265
|
-
:tBACK_REF,
|
266
|
-
:tBACK_REF,
|
267
|
-
:tBACK_REF,
|
275
|
+
:tBACK_REF, "$&", :tCOMMA, ",",
|
276
|
+
:tBACK_REF, "$`", :tCOMMA, ",",
|
277
|
+
:tBACK_REF, "$'", :tCOMMA, ",",
|
278
|
+
:tBACK_REF, "$+",
|
268
279
|
:tRBRACK, "]")
|
269
280
|
end
|
270
281
|
|
271
|
-
def
|
282
|
+
def test_backslash
|
272
283
|
util_lex_token("1 \\\n+ 2",
|
273
284
|
:tINTEGER, 1,
|
274
285
|
:tPLUS, "+",
|
275
286
|
:tINTEGER, 2)
|
276
287
|
end
|
277
288
|
|
278
|
-
def
|
289
|
+
def test_backslash_bad
|
279
290
|
util_bad_token("1 \\ + 2",
|
280
291
|
:tINTEGER, 1)
|
281
292
|
end
|
282
293
|
|
283
|
-
def
|
294
|
+
def test_backtick
|
284
295
|
util_lex_token("`ls`",
|
285
296
|
:tXSTRING_BEG, "`",
|
286
297
|
:tSTRING_CONTENT, "ls",
|
287
298
|
:tSTRING_END, "`")
|
288
299
|
end
|
289
300
|
|
290
|
-
def
|
301
|
+
def test_backtick_cmdarg
|
291
302
|
@lex.state = :expr_dot
|
292
303
|
util_lex_token("\n`", :tBACK_REF2, "`") # \n ensures expr_cmd
|
293
304
|
|
294
305
|
assert_equal :expr_arg, @lex.state
|
295
306
|
end
|
296
307
|
|
297
|
-
def
|
308
|
+
def test_backtick_dot
|
298
309
|
@lex.state = :expr_dot
|
299
310
|
util_lex_token("a.`(3)",
|
300
311
|
:tIDENTIFIER, "a",
|
@@ -305,54 +316,64 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
305
316
|
:tRPAREN, ")")
|
306
317
|
end
|
307
318
|
|
308
|
-
def
|
319
|
+
def test_backtick_method
|
309
320
|
@lex.state = :expr_fname
|
310
321
|
util_lex_token("`", :tBACK_REF2, "`")
|
311
322
|
assert_equal :expr_end, @lex.state
|
312
323
|
end
|
313
324
|
|
314
|
-
def
|
325
|
+
def test_bad_char
|
315
326
|
util_bad_token(" \010 ")
|
316
327
|
end
|
317
328
|
|
318
|
-
def
|
329
|
+
def test_bang
|
319
330
|
util_lex_token "!", :tBANG, "!"
|
320
331
|
end
|
321
332
|
|
322
|
-
def
|
333
|
+
def test_bang_equals
|
323
334
|
util_lex_token "!=", :tNEQ, "!="
|
324
335
|
end
|
325
336
|
|
326
|
-
def
|
337
|
+
def test_bang_tilde
|
327
338
|
util_lex_token "!~", :tNMATCH, "!~"
|
328
339
|
end
|
329
340
|
|
330
|
-
def
|
341
|
+
def test_carat
|
331
342
|
util_lex_token "^", :tCARET, "^"
|
332
343
|
end
|
333
344
|
|
334
|
-
def
|
345
|
+
def test_carat_equals
|
335
346
|
util_lex_token "^=", :tOP_ASGN, "^"
|
336
347
|
end
|
337
348
|
|
338
|
-
def
|
349
|
+
def test_colon2
|
339
350
|
util_lex_token("A::B",
|
340
351
|
:tCONSTANT, "A",
|
341
352
|
:tCOLON2, "::",
|
342
353
|
:tCONSTANT, "B")
|
354
|
+
|
355
|
+
@lex.state = :expr_arg
|
356
|
+
util_lex_token("::Array",
|
357
|
+
:tCOLON2, "::",
|
358
|
+
:tCONSTANT, "Array")
|
343
359
|
end
|
344
360
|
|
345
|
-
def
|
361
|
+
def test_colon3
|
346
362
|
util_lex_token("::Array",
|
347
363
|
:tCOLON3, "::",
|
348
364
|
:tCONSTANT, "Array")
|
365
|
+
|
366
|
+
@lex.state = :expr_arg
|
367
|
+
util_lex_token(" ::Array",
|
368
|
+
:tCOLON3, "::",
|
369
|
+
:tCONSTANT, "Array")
|
349
370
|
end
|
350
371
|
|
351
|
-
def
|
372
|
+
def test_comma
|
352
373
|
util_lex_token ",", :tCOMMA, ","
|
353
374
|
end
|
354
375
|
|
355
|
-
def
|
376
|
+
def test_comment
|
356
377
|
util_lex_token("1 # one\n# two\n2",
|
357
378
|
:tINTEGER, 1,
|
358
379
|
:tNL, nil,
|
@@ -360,18 +381,23 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
360
381
|
assert_equal "# one\n# two\n", @lex.comments
|
361
382
|
end
|
362
383
|
|
363
|
-
def
|
384
|
+
def test_comment_expr_beg
|
385
|
+
util_lex_token("{#1\n}",
|
386
|
+
:tLBRACE, "{",
|
387
|
+
:tRCURLY, "}")
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_comment_begin
|
364
391
|
util_lex_token("=begin\nblah\nblah\n=end\n42",
|
365
392
|
:tINTEGER, 42)
|
366
393
|
assert_equal "=begin\nblah\nblah\n=end\n", @lex.comments
|
367
394
|
end
|
368
395
|
|
369
|
-
def
|
396
|
+
def test_comment_begin_bad
|
370
397
|
util_bad_token("=begin\nblah\nblah\n")
|
371
|
-
assert_equal "", @lex.comments
|
372
398
|
end
|
373
399
|
|
374
|
-
def
|
400
|
+
def test_comment_begin_not_comment
|
375
401
|
util_lex_token("beginfoo = 5\np x \\\n=beginfoo",
|
376
402
|
:tIDENTIFIER, "beginfoo",
|
377
403
|
:tEQL, "=",
|
@@ -383,54 +409,54 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
383
409
|
:tIDENTIFIER, "beginfoo")
|
384
410
|
end
|
385
411
|
|
386
|
-
def
|
412
|
+
def test_comment_begin_space
|
387
413
|
util_lex_token("=begin blah\nblah\n=end\n")
|
388
414
|
assert_equal "=begin blah\nblah\n=end\n", @lex.comments
|
389
415
|
end
|
390
416
|
|
391
|
-
def
|
417
|
+
def test_comment_end_space_and_text
|
392
418
|
util_lex_token("=begin blah\nblah\n=end blab\n")
|
393
419
|
assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments
|
394
420
|
end
|
395
421
|
|
396
|
-
def
|
422
|
+
def test_comment_eos
|
397
423
|
util_lex_token("# comment")
|
398
424
|
end
|
399
425
|
|
400
|
-
def
|
426
|
+
def test_constant
|
401
427
|
util_lex_token("ArgumentError",
|
402
428
|
:tCONSTANT, "ArgumentError")
|
403
429
|
end
|
404
430
|
|
405
|
-
def
|
431
|
+
def test_constant_semi
|
406
432
|
util_lex_token("ArgumentError;",
|
407
433
|
:tCONSTANT, "ArgumentError",
|
408
434
|
:tSEMI, ";")
|
409
435
|
end
|
410
436
|
|
411
|
-
def
|
437
|
+
def test_cvar
|
412
438
|
util_lex_token "@@blah", :tCVAR, "@@blah"
|
413
439
|
end
|
414
440
|
|
415
|
-
def
|
441
|
+
def test_cvar_bad
|
416
442
|
util_bad_token "@@1"
|
417
443
|
end
|
418
444
|
|
419
|
-
def
|
445
|
+
def test_div
|
420
446
|
util_lex_token("a / 2",
|
421
447
|
:tIDENTIFIER, "a",
|
422
448
|
:tDIVIDE, "/",
|
423
449
|
:tINTEGER, 2)
|
424
450
|
end
|
425
451
|
|
426
|
-
def
|
452
|
+
def test_div_equals
|
427
453
|
util_lex_token("a /= 2",
|
428
454
|
:tIDENTIFIER, "a",
|
429
455
|
:tOP_ASGN, "/",
|
430
456
|
:tINTEGER, 2)
|
431
457
|
end
|
432
458
|
|
433
|
-
def
|
459
|
+
def test_do
|
434
460
|
util_lex_token("x do 42 end",
|
435
461
|
:tIDENTIFIER, "x",
|
436
462
|
:kDO, "do",
|
@@ -438,7 +464,17 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
438
464
|
:kEND, "end")
|
439
465
|
end
|
440
466
|
|
441
|
-
def
|
467
|
+
def test_do_cond
|
468
|
+
@lex.cond.push(true)
|
469
|
+
|
470
|
+
util_lex_token("x do 42 end",
|
471
|
+
:tIDENTIFIER, "x",
|
472
|
+
:kDO_COND, "do",
|
473
|
+
:tINTEGER, 42,
|
474
|
+
:kEND, "end")
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_do_block
|
442
478
|
@lex.state = :expr_endarg
|
443
479
|
|
444
480
|
util_lex_token("do 42 end",
|
@@ -448,7 +484,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
448
484
|
end
|
449
485
|
|
450
486
|
# TODO
|
451
|
-
# def
|
487
|
+
# def test_do_cond
|
452
488
|
# @lex.cond.push true
|
453
489
|
|
454
490
|
# util_lex_token("x do 42 end",
|
@@ -458,156 +494,149 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
458
494
|
# :kEND, "end")
|
459
495
|
# end
|
460
496
|
|
461
|
-
def
|
497
|
+
def test_dot
|
462
498
|
util_lex_token ".", :tDOT, "."
|
463
499
|
end
|
464
500
|
|
465
|
-
def
|
501
|
+
def test_dot2
|
466
502
|
util_lex_token "..", :tDOT2, ".."
|
467
503
|
end
|
468
504
|
|
469
|
-
def
|
505
|
+
def test_dot3
|
470
506
|
util_lex_token "...", :tDOT3, "..."
|
471
507
|
end
|
472
508
|
|
473
|
-
def
|
509
|
+
def test_equals
|
474
510
|
util_lex_token "=", :tEQL, "="
|
475
511
|
end
|
476
512
|
|
477
|
-
def
|
513
|
+
def test_equals2
|
478
514
|
util_lex_token "==", :tEQ, "=="
|
479
515
|
end
|
480
516
|
|
481
|
-
def
|
517
|
+
def test_equals3
|
482
518
|
util_lex_token "===", :tEQQ, "==="
|
483
519
|
end
|
484
520
|
|
485
|
-
def
|
521
|
+
def test_equals_tilde
|
486
522
|
util_lex_token "=~", :tMATCH, "=~"
|
487
523
|
end
|
488
524
|
|
489
|
-
def
|
525
|
+
def test_float
|
490
526
|
util_lex_token "1.0", :tFLOAT, 1.0
|
491
527
|
end
|
492
528
|
|
493
|
-
def
|
529
|
+
def test_float_bad_no_underscores
|
494
530
|
util_bad_token "1__0.0"
|
495
531
|
end
|
496
532
|
|
497
|
-
def
|
533
|
+
def test_float_bad_no_zero_leading
|
498
534
|
util_bad_token ".0"
|
499
535
|
end
|
500
536
|
|
501
|
-
def
|
537
|
+
def test_float_bad_trailing_underscore
|
502
538
|
util_bad_token "123_.0"
|
503
539
|
end
|
504
540
|
|
505
|
-
def
|
541
|
+
def test_float_call
|
506
542
|
util_lex_token("1.0.to_s",
|
507
543
|
:tFLOAT, 1.0,
|
508
544
|
:tDOT, ".",
|
509
545
|
:tIDENTIFIER, "to_s")
|
510
546
|
end
|
511
547
|
|
512
|
-
def
|
548
|
+
def test_float_dot_E
|
513
549
|
util_lex_token "1.0E10", :tFLOAT, 1.0e10
|
514
550
|
end
|
515
551
|
|
516
|
-
def
|
552
|
+
def test_float_dot_E_neg
|
517
553
|
util_lex_token("-1.0E10",
|
518
554
|
:tUMINUS_NUM, "-",
|
519
555
|
:tFLOAT, 1.0e10)
|
520
556
|
end
|
521
557
|
|
522
|
-
def
|
558
|
+
def test_float_dot_e
|
523
559
|
util_lex_token "1.0e10", :tFLOAT, 1.0e10
|
524
560
|
end
|
525
561
|
|
526
|
-
def
|
562
|
+
def test_float_dot_e_neg
|
527
563
|
util_lex_token("-1.0e10",
|
528
564
|
:tUMINUS_NUM, "-",
|
529
565
|
:tFLOAT, 1.0e10)
|
530
566
|
end
|
531
567
|
|
532
|
-
def
|
568
|
+
def test_float_e
|
533
569
|
util_lex_token "1e10", :tFLOAT, 1e10
|
534
570
|
end
|
535
571
|
|
536
|
-
def
|
572
|
+
def test_float_e_bad_trailing_underscore
|
537
573
|
util_bad_token "123_e10"
|
538
574
|
end
|
539
575
|
|
540
|
-
def
|
576
|
+
def test_float_e_minus
|
541
577
|
util_lex_token "1e-10", :tFLOAT, 1e-10
|
542
578
|
end
|
543
579
|
|
544
|
-
def
|
580
|
+
def test_float_e_neg
|
545
581
|
util_lex_token("-1e10",
|
546
582
|
:tUMINUS_NUM, "-",
|
547
583
|
:tFLOAT, 1e10)
|
548
584
|
end
|
549
585
|
|
550
|
-
def
|
586
|
+
def test_float_e_neg_minus
|
551
587
|
util_lex_token("-1e-10",
|
552
588
|
:tUMINUS_NUM, "-",
|
553
589
|
:tFLOAT, 1e-10)
|
554
590
|
end
|
555
591
|
|
556
|
-
def
|
592
|
+
def test_float_e_neg_plus
|
557
593
|
util_lex_token("-1e+10",
|
558
594
|
:tUMINUS_NUM, "-",
|
559
595
|
:tFLOAT, 1e10)
|
560
596
|
end
|
561
597
|
|
562
|
-
def
|
598
|
+
def test_float_e_plus
|
563
599
|
util_lex_token "1e+10", :tFLOAT, 1e10
|
564
600
|
end
|
565
601
|
|
566
|
-
def
|
602
|
+
def test_float_e_zero
|
567
603
|
util_lex_token "0e0", :tFLOAT, 0e0
|
568
604
|
end
|
569
605
|
|
570
|
-
def
|
606
|
+
def test_float_neg
|
571
607
|
util_lex_token("-1.0",
|
572
608
|
:tUMINUS_NUM, "-",
|
573
609
|
:tFLOAT, 1.0)
|
574
610
|
end
|
575
611
|
|
576
|
-
def
|
612
|
+
def test_ge
|
577
613
|
util_lex_token("a >= 2",
|
578
614
|
:tIDENTIFIER, "a",
|
579
615
|
:tGEQ, ">=",
|
580
616
|
:tINTEGER, 2)
|
581
617
|
end
|
582
618
|
|
583
|
-
def
|
619
|
+
def test_global
|
584
620
|
util_lex_token("$blah", :tGVAR, "$blah")
|
585
621
|
end
|
586
622
|
|
587
|
-
def
|
588
|
-
|
589
|
-
util_lex_token("$`", :tGVAR, "$`")
|
623
|
+
def test_global_backref
|
624
|
+
util_lex_token("$`", :tBACK_REF, "$`")
|
590
625
|
end
|
591
626
|
|
592
|
-
def
|
627
|
+
def test_global_dash_nothing
|
593
628
|
util_lex_token("$- ", :tGVAR, "$-")
|
594
629
|
end
|
595
630
|
|
596
|
-
def
|
631
|
+
def test_global_dash_something
|
597
632
|
util_lex_token("$-x", :tGVAR, "$-x")
|
598
633
|
end
|
599
634
|
|
600
|
-
def
|
601
|
-
|
602
|
-
util_lex_token("$1", :tGVAR, "$1")
|
603
|
-
end
|
604
|
-
|
605
|
-
def test_yylex_global_number_big
|
606
|
-
@lex.state = :expr_fname
|
607
|
-
util_lex_token("$1234", :tGVAR, "$1234")
|
635
|
+
def test_global_number
|
636
|
+
util_lex_token("$10", :tNTH_REF, 10)
|
608
637
|
end
|
609
638
|
|
610
|
-
def
|
639
|
+
def test_global_other
|
611
640
|
util_lex_token("[$~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $\"]",
|
612
641
|
:tLBRACK, "[",
|
613
642
|
:tGVAR, "$~", :tCOMMA, ",",
|
@@ -629,28 +658,28 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
629
658
|
:tRBRACK, "]")
|
630
659
|
end
|
631
660
|
|
632
|
-
def
|
661
|
+
def test_global_underscore
|
633
662
|
util_lex_token("$_",
|
634
663
|
:tGVAR, "$_")
|
635
664
|
end
|
636
665
|
|
637
|
-
def
|
666
|
+
def test_global_wierd
|
638
667
|
util_lex_token("$__blah",
|
639
668
|
:tGVAR, "$__blah")
|
640
669
|
end
|
641
670
|
|
642
|
-
def
|
671
|
+
def test_global_zero
|
643
672
|
util_lex_token("$0", :tGVAR, "$0")
|
644
673
|
end
|
645
674
|
|
646
|
-
def
|
675
|
+
def test_gt
|
647
676
|
util_lex_token("a > 2",
|
648
677
|
:tIDENTIFIER, "a",
|
649
678
|
:tGT, ">",
|
650
679
|
:tINTEGER, 2)
|
651
680
|
end
|
652
681
|
|
653
|
-
def
|
682
|
+
def test_heredoc_backtick
|
654
683
|
util_lex_token("a = <<`EOF`\n blah blah\nEOF\n",
|
655
684
|
:tIDENTIFIER, "a",
|
656
685
|
:tEQL, "=",
|
@@ -660,7 +689,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
660
689
|
:tNL, nil)
|
661
690
|
end
|
662
691
|
|
663
|
-
def
|
692
|
+
def test_heredoc_double
|
664
693
|
util_lex_token("a = <<\"EOF\"\n blah blah\nEOF\n",
|
665
694
|
:tIDENTIFIER, "a",
|
666
695
|
:tEQL, "=",
|
@@ -670,7 +699,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
670
699
|
:tNL, nil)
|
671
700
|
end
|
672
701
|
|
673
|
-
def
|
702
|
+
def test_heredoc_double_dash
|
674
703
|
util_lex_token("a = <<-\"EOF\"\n blah blah\n EOF\n",
|
675
704
|
:tIDENTIFIER, "a",
|
676
705
|
:tEQL, "=",
|
@@ -680,21 +709,21 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
680
709
|
:tNL, nil)
|
681
710
|
end
|
682
711
|
|
683
|
-
def
|
712
|
+
def test_heredoc_double_eos
|
684
713
|
util_bad_token("a = <<\"EOF\"\nblah",
|
685
714
|
:tIDENTIFIER, "a",
|
686
715
|
:tEQL, "=",
|
687
716
|
:tSTRING_BEG, "\"")
|
688
717
|
end
|
689
718
|
|
690
|
-
def
|
719
|
+
def test_heredoc_double_eos_nl
|
691
720
|
util_bad_token("a = <<\"EOF\"\nblah\n",
|
692
721
|
:tIDENTIFIER, "a",
|
693
722
|
:tEQL, "=",
|
694
723
|
:tSTRING_BEG, "\"")
|
695
724
|
end
|
696
725
|
|
697
|
-
def
|
726
|
+
def test_heredoc_double_interp
|
698
727
|
util_lex_token("a = <<\"EOF\"\n#x a \#@a b \#$b c \#{3} \nEOF\n",
|
699
728
|
:tIDENTIFIER, "a",
|
700
729
|
:tEQL, "=",
|
@@ -714,7 +743,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
714
743
|
:tNL, nil)
|
715
744
|
end
|
716
745
|
|
717
|
-
def
|
746
|
+
def test_heredoc_empty
|
718
747
|
util_lex_token("<<\"\"\n\#{x}\nblah2\n\n",
|
719
748
|
:tSTRING_BEG, "\"",
|
720
749
|
:tSTRING_DBEG, "\#{",
|
@@ -726,7 +755,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
726
755
|
:tNL, nil)
|
727
756
|
end
|
728
757
|
|
729
|
-
def
|
758
|
+
def test_heredoc_none
|
730
759
|
util_lex_token("a = <<EOF\nblah\nblah\nEOF",
|
731
760
|
:tIDENTIFIER, "a",
|
732
761
|
:tEQL, "=",
|
@@ -737,7 +766,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
737
766
|
:tNL, nil)
|
738
767
|
end
|
739
768
|
|
740
|
-
def
|
769
|
+
def test_heredoc_none_dash
|
741
770
|
util_lex_token("a = <<-EOF\nblah\nblah\n EOF",
|
742
771
|
:tIDENTIFIER, "a",
|
743
772
|
:tEQL, "=",
|
@@ -748,7 +777,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
748
777
|
:tNL, nil)
|
749
778
|
end
|
750
779
|
|
751
|
-
def
|
780
|
+
def test_heredoc_single
|
752
781
|
util_lex_token("a = <<'EOF'\n blah blah\nEOF\n",
|
753
782
|
:tIDENTIFIER, "a",
|
754
783
|
:tEQL, "=",
|
@@ -758,14 +787,14 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
758
787
|
:tNL, nil)
|
759
788
|
end
|
760
789
|
|
761
|
-
def
|
790
|
+
def test_heredoc_single_bad_eos_body
|
762
791
|
util_bad_token("a = <<'EOF'\nblah",
|
763
792
|
:tIDENTIFIER, "a",
|
764
793
|
:tEQL, "=",
|
765
794
|
:tSTRING_BEG, "'")
|
766
795
|
end
|
767
796
|
|
768
|
-
def
|
797
|
+
def test_heredoc_single_dash
|
769
798
|
util_lex_token("a = <<-'EOF'\n blah blah\n EOF\n",
|
770
799
|
:tIDENTIFIER, "a",
|
771
800
|
:tEQL, "=",
|
@@ -775,59 +804,64 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
775
804
|
:tNL, nil)
|
776
805
|
end
|
777
806
|
|
778
|
-
def
|
807
|
+
def test_identifier
|
779
808
|
util_lex_token("identifier", :tIDENTIFIER, "identifier")
|
780
809
|
end
|
781
810
|
|
782
|
-
def
|
783
|
-
util_lex_token("identifier!",
|
811
|
+
def test_identifier_bang
|
812
|
+
util_lex_token("identifier!",
|
813
|
+
:tFID, "identifier!")
|
814
|
+
|
815
|
+
util_lex_token("identifier!=",
|
816
|
+
:tFID, "identifier",
|
817
|
+
:tNEQ, "!=")
|
784
818
|
end
|
785
819
|
|
786
|
-
def
|
820
|
+
def test_identifier_cmp
|
787
821
|
util_lex_fname "<=>", :tCMP
|
788
822
|
end
|
789
823
|
|
790
|
-
def
|
824
|
+
def test_identifier_def
|
791
825
|
util_lex_fname "identifier", :tIDENTIFIER, :expr_end
|
792
826
|
end
|
793
827
|
|
794
|
-
def
|
828
|
+
def test_identifier_eh
|
795
829
|
util_lex_token("identifier?", :tFID, "identifier?")
|
796
830
|
end
|
797
831
|
|
798
|
-
def
|
832
|
+
def test_identifier_equals_arrow
|
799
833
|
util_lex_token(":blah==>",
|
800
834
|
:tSYMBOL, "blah=",
|
801
835
|
:tASSOC, "=>")
|
802
836
|
end
|
803
837
|
|
804
|
-
def
|
838
|
+
def test_identifier_equals3
|
805
839
|
util_lex_token(":a===b",
|
806
840
|
:tSYMBOL, "a",
|
807
841
|
:tEQQ, "===",
|
808
842
|
:tIDENTIFIER, "b")
|
809
843
|
end
|
810
844
|
|
811
|
-
def
|
845
|
+
def test_identifier_equals_equals_arrow
|
812
846
|
util_lex_token(":a==>b",
|
813
847
|
:tSYMBOL, "a=",
|
814
848
|
:tASSOC, "=>",
|
815
849
|
:tIDENTIFIER, "b")
|
816
850
|
end
|
817
851
|
|
818
|
-
def
|
852
|
+
def test_identifier_equals_caret
|
819
853
|
util_lex_fname "^", :tCARET
|
820
854
|
end
|
821
855
|
|
822
|
-
def
|
856
|
+
def test_identifier_equals_def
|
823
857
|
util_lex_fname "identifier=", :tIDENTIFIER, :expr_end
|
824
858
|
end
|
825
859
|
|
826
|
-
def
|
860
|
+
def test_identifier_equals_def2
|
827
861
|
util_lex_fname "==", :tEQ
|
828
862
|
end
|
829
863
|
|
830
|
-
def
|
864
|
+
def test_identifier_equals_expr
|
831
865
|
@lex.state = :expr_dot
|
832
866
|
util_lex_token("y = arg",
|
833
867
|
:tIDENTIFIER, "y",
|
@@ -837,193 +871,193 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
837
871
|
assert_equal :expr_arg, @lex.state
|
838
872
|
end
|
839
873
|
|
840
|
-
def
|
874
|
+
def test_identifier_equals_or
|
841
875
|
util_lex_fname "|", :tPIPE
|
842
876
|
end
|
843
877
|
|
844
|
-
def
|
878
|
+
def test_identifier_equals_slash
|
845
879
|
util_lex_fname "/", :tDIVIDE
|
846
880
|
end
|
847
881
|
|
848
|
-
def
|
882
|
+
def test_identifier_equals_tilde
|
849
883
|
@lex.state = :expr_fname # can only set via parser's defs
|
850
884
|
util_lex_token("identifier=~",
|
851
885
|
:tIDENTIFIER, "identifier",
|
852
886
|
:tMATCH, "=~")
|
853
887
|
end
|
854
888
|
|
855
|
-
def
|
889
|
+
def test_identifier_gt
|
856
890
|
util_lex_fname ">", :tGT
|
857
891
|
end
|
858
892
|
|
859
|
-
def
|
893
|
+
def test_identifier_le
|
860
894
|
util_lex_fname "<=", :tLEQ
|
861
895
|
end
|
862
896
|
|
863
|
-
def
|
897
|
+
def test_identifier_lt
|
864
898
|
util_lex_fname "<", :tLT
|
865
899
|
end
|
866
900
|
|
867
|
-
def
|
901
|
+
def test_identifier_tilde
|
868
902
|
util_lex_fname "~", :tTILDE
|
869
903
|
end
|
870
904
|
|
871
|
-
def
|
905
|
+
def test_index
|
872
906
|
util_lex_fname "[]", :tAREF
|
873
907
|
end
|
874
908
|
|
875
|
-
def
|
909
|
+
def test_index_equals
|
876
910
|
util_lex_fname "[]=", :tASET
|
877
911
|
end
|
878
912
|
|
879
|
-
def
|
913
|
+
def test_integer
|
880
914
|
util_lex_token "42", :tINTEGER, 42
|
881
915
|
end
|
882
916
|
|
883
|
-
def
|
917
|
+
def test_integer_bin
|
884
918
|
util_lex_token "0b101010", :tINTEGER, 42
|
885
919
|
end
|
886
920
|
|
887
|
-
def
|
921
|
+
def test_integer_bin_bad_none
|
888
922
|
util_bad_token "0b "
|
889
923
|
end
|
890
924
|
|
891
|
-
def
|
925
|
+
def test_integer_bin_bad_underscores
|
892
926
|
util_bad_token "0b10__01"
|
893
927
|
end
|
894
928
|
|
895
|
-
def
|
929
|
+
def test_integer_dec
|
896
930
|
util_lex_token "42", :tINTEGER, 42
|
897
931
|
end
|
898
932
|
|
899
|
-
def
|
933
|
+
def test_integer_dec_bad_underscores
|
900
934
|
util_bad_token "42__24"
|
901
935
|
end
|
902
936
|
|
903
|
-
def
|
937
|
+
def test_integer_dec_d
|
904
938
|
util_lex_token "0d42", :tINTEGER, 42
|
905
939
|
end
|
906
940
|
|
907
|
-
def
|
941
|
+
def test_integer_dec_d_bad_none
|
908
942
|
util_bad_token "0d"
|
909
943
|
end
|
910
944
|
|
911
|
-
def
|
945
|
+
def test_integer_dec_d_bad_underscores
|
912
946
|
util_bad_token "0d42__24"
|
913
947
|
end
|
914
948
|
|
915
|
-
def
|
949
|
+
def test_question_eh_a__18
|
916
950
|
setup_lexer 18
|
917
951
|
|
918
952
|
util_lex_token "?a", :tINTEGER, 97
|
919
953
|
end
|
920
954
|
|
921
|
-
def
|
955
|
+
def test_question_eh_a__19
|
922
956
|
setup_lexer 19
|
923
957
|
|
924
958
|
util_lex_token '?a', :tSTRING, "a"
|
925
959
|
end
|
926
960
|
|
927
|
-
def
|
961
|
+
def test_question_eh_escape_M_escape_C__18
|
928
962
|
setup_lexer 18
|
929
963
|
|
930
964
|
util_lex_token '?\M-\C-a', :tINTEGER, 129
|
931
965
|
end
|
932
966
|
|
933
|
-
def
|
967
|
+
def test_question_eh_escape_M_escape_C__19
|
934
968
|
setup_lexer 19
|
935
969
|
|
936
970
|
util_lex_token '?\M-\C-a', :tSTRING, "\M-\C-a"
|
937
971
|
end
|
938
972
|
|
939
|
-
def
|
973
|
+
def test_integer_hex
|
940
974
|
util_lex_token "0x2a", :tINTEGER, 42
|
941
975
|
end
|
942
976
|
|
943
|
-
def
|
977
|
+
def test_integer_hex_bad_none
|
944
978
|
util_bad_token "0x "
|
945
979
|
end
|
946
980
|
|
947
|
-
def
|
981
|
+
def test_integer_hex_bad_underscores
|
948
982
|
util_bad_token "0xab__cd"
|
949
983
|
end
|
950
984
|
|
951
|
-
def
|
985
|
+
def test_integer_oct
|
952
986
|
util_lex_token "052", :tINTEGER, 42
|
953
987
|
end
|
954
988
|
|
955
|
-
def
|
989
|
+
def test_integer_oct_bad_range
|
956
990
|
util_bad_token "08"
|
957
991
|
end
|
958
992
|
|
959
|
-
def
|
993
|
+
def test_integer_oct_bad_underscores
|
960
994
|
util_bad_token "01__23"
|
961
995
|
end
|
962
996
|
|
963
|
-
def
|
997
|
+
def test_integer_oct_O
|
964
998
|
util_lex_token "0O52", :tINTEGER, 42
|
965
999
|
end
|
966
1000
|
|
967
|
-
def
|
968
|
-
util_bad_token "
|
1001
|
+
def test_integer_oct_O_bad_range
|
1002
|
+
util_bad_token "0O1238"
|
969
1003
|
end
|
970
1004
|
|
971
|
-
def
|
1005
|
+
def test_integer_oct_O_bad_underscores
|
972
1006
|
util_bad_token "0O1__23"
|
973
1007
|
end
|
974
1008
|
|
975
|
-
def
|
1009
|
+
def test_integer_oct_O_not_bad_none
|
976
1010
|
util_lex_token "0O ", :tINTEGER, 0
|
977
1011
|
end
|
978
1012
|
|
979
|
-
def
|
1013
|
+
def test_integer_oct_o
|
980
1014
|
util_lex_token "0o52", :tINTEGER, 42
|
981
1015
|
end
|
982
1016
|
|
983
|
-
def
|
984
|
-
util_bad_token "
|
1017
|
+
def test_integer_oct_o_bad_range
|
1018
|
+
util_bad_token "0o1283"
|
985
1019
|
end
|
986
1020
|
|
987
|
-
def
|
1021
|
+
def test_integer_oct_o_bad_underscores
|
988
1022
|
util_bad_token "0o1__23"
|
989
1023
|
end
|
990
1024
|
|
991
|
-
def
|
1025
|
+
def test_integer_oct_o_not_bad_none
|
992
1026
|
util_lex_token "0o ", :tINTEGER, 0
|
993
1027
|
end
|
994
1028
|
|
995
|
-
def
|
1029
|
+
def test_integer_trailing
|
996
1030
|
util_lex_token("1.to_s",
|
997
1031
|
:tINTEGER, 1,
|
998
1032
|
:tDOT, '.',
|
999
1033
|
:tIDENTIFIER, 'to_s')
|
1000
1034
|
end
|
1001
1035
|
|
1002
|
-
def
|
1036
|
+
def test_integer_underscore
|
1003
1037
|
util_lex_token "4_2", :tINTEGER, 42
|
1004
1038
|
end
|
1005
1039
|
|
1006
|
-
def
|
1040
|
+
def test_integer_underscore_bad
|
1007
1041
|
util_bad_token "4__2"
|
1008
1042
|
end
|
1009
1043
|
|
1010
|
-
def
|
1044
|
+
def test_integer_zero
|
1011
1045
|
util_lex_token "0", :tINTEGER, 0
|
1012
1046
|
end
|
1013
1047
|
|
1014
|
-
def
|
1048
|
+
def test_ivar
|
1015
1049
|
util_lex_token "@blah", :tIVAR, "@blah"
|
1016
1050
|
end
|
1017
1051
|
|
1018
|
-
def
|
1052
|
+
def test_ivar_bad
|
1019
1053
|
util_bad_token "@1"
|
1020
1054
|
end
|
1021
1055
|
|
1022
|
-
def
|
1056
|
+
def test_ivar_bad_0_length
|
1023
1057
|
util_bad_token "1+@\n", :tINTEGER, 1, :tPLUS, "+"
|
1024
1058
|
end
|
1025
1059
|
|
1026
|
-
def
|
1060
|
+
def test_keyword_expr
|
1027
1061
|
@lex.state = :expr_endarg
|
1028
1062
|
|
1029
1063
|
util_lex_token("if", :kIF_MOD, "if")
|
@@ -1031,11 +1065,11 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1031
1065
|
assert_equal :expr_beg, @lex.state
|
1032
1066
|
end
|
1033
1067
|
|
1034
|
-
def
|
1068
|
+
def test_lt
|
1035
1069
|
util_lex_token "<", :tLT, "<"
|
1036
1070
|
end
|
1037
1071
|
|
1038
|
-
def
|
1072
|
+
def test_lt2
|
1039
1073
|
util_lex_token("a <\< b",
|
1040
1074
|
:tIDENTIFIER, "a",
|
1041
1075
|
:tLSHFT, "<\<",
|
@@ -1043,81 +1077,75 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1043
1077
|
|
1044
1078
|
end
|
1045
1079
|
|
1046
|
-
def
|
1080
|
+
def test_lt2_equals
|
1047
1081
|
util_lex_token("a <\<= b",
|
1048
1082
|
:tIDENTIFIER, "a",
|
1049
1083
|
:tOP_ASGN, "<\<",
|
1050
1084
|
:tIDENTIFIER, "b")
|
1051
1085
|
end
|
1052
1086
|
|
1053
|
-
def
|
1087
|
+
def test_lt_equals
|
1054
1088
|
util_lex_token "<=", :tLEQ, "<="
|
1055
1089
|
end
|
1056
1090
|
|
1057
|
-
def
|
1091
|
+
def test_minus
|
1058
1092
|
util_lex_token("1 - 2",
|
1059
1093
|
:tINTEGER, 1,
|
1060
1094
|
:tMINUS, "-",
|
1061
1095
|
:tINTEGER, 2)
|
1062
1096
|
end
|
1063
1097
|
|
1064
|
-
def
|
1098
|
+
def test_minus_equals
|
1065
1099
|
@lex.state = :expr_end
|
1066
1100
|
|
1067
1101
|
util_lex_token "-=", :tOP_ASGN, "-"
|
1068
1102
|
end
|
1069
1103
|
|
1070
|
-
def
|
1104
|
+
def test_minus_method
|
1071
1105
|
@lex.state = :expr_fname
|
1072
1106
|
util_lex_token "-", :tMINUS, "-"
|
1073
1107
|
end
|
1074
1108
|
|
1075
|
-
def
|
1109
|
+
def test_minus_unary_method
|
1076
1110
|
@lex.state = :expr_fname
|
1077
1111
|
util_lex_token "-@", :tUMINUS, "-@"
|
1078
1112
|
end
|
1079
1113
|
|
1080
|
-
def
|
1114
|
+
def test_minus_unary_number
|
1081
1115
|
util_lex_token("-42",
|
1082
1116
|
:tUMINUS_NUM, "-",
|
1083
1117
|
:tINTEGER, 42)
|
1084
1118
|
end
|
1085
1119
|
|
1086
|
-
def
|
1087
|
-
util_lex_token('[$1, $2, $3
|
1120
|
+
def test_nth_ref
|
1121
|
+
util_lex_token('[$1, $2, $3]',
|
1088
1122
|
:tLBRACK, "[",
|
1089
1123
|
:tNTH_REF, 1, :tCOMMA, ",",
|
1090
1124
|
:tNTH_REF, 2, :tCOMMA, ",",
|
1091
|
-
:tNTH_REF, 3,
|
1092
|
-
:tNTH_REF, 4, :tCOMMA, ",",
|
1093
|
-
:tNTH_REF, 5, :tCOMMA, ",",
|
1094
|
-
:tNTH_REF, 6, :tCOMMA, ",",
|
1095
|
-
:tNTH_REF, 7, :tCOMMA, ",",
|
1096
|
-
:tNTH_REF, 8, :tCOMMA, ",",
|
1097
|
-
:tNTH_REF, 9,
|
1125
|
+
:tNTH_REF, 3,
|
1098
1126
|
:tRBRACK, "]")
|
1099
1127
|
end
|
1100
1128
|
|
1101
|
-
def
|
1129
|
+
def test_open_bracket
|
1102
1130
|
util_lex_token("(", :tLPAREN, "(")
|
1103
1131
|
end
|
1104
1132
|
|
1105
|
-
def
|
1133
|
+
def test_open_bracket_cmdarg
|
1106
1134
|
util_lex_token("m (", :tIDENTIFIER, "m",
|
1107
1135
|
:tLPAREN_ARG, "(")
|
1108
1136
|
end
|
1109
1137
|
|
1110
|
-
def
|
1138
|
+
def test_open_bracket_exprarg
|
1111
1139
|
util_lex_token("m(", :tIDENTIFIER, "m",
|
1112
1140
|
:tLPAREN2, "(")
|
1113
1141
|
end
|
1114
1142
|
|
1115
|
-
def
|
1143
|
+
def test_open_curly_bracket
|
1116
1144
|
util_lex_token("{",
|
1117
1145
|
:tLBRACE, "{")
|
1118
1146
|
end
|
1119
1147
|
|
1120
|
-
def
|
1148
|
+
def test_open_curly_bracket_arg
|
1121
1149
|
util_lex_token("m { 3 }",
|
1122
1150
|
:tIDENTIFIER, "m",
|
1123
1151
|
:tLCURLY, "{",
|
@@ -1125,7 +1153,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1125
1153
|
:tRCURLY, "}")
|
1126
1154
|
end
|
1127
1155
|
|
1128
|
-
def
|
1156
|
+
def test_open_curly_bracket_block
|
1129
1157
|
@lex.state = :expr_endarg # seen m(3)
|
1130
1158
|
|
1131
1159
|
util_lex_token("{ 4 }",
|
@@ -1134,7 +1162,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1134
1162
|
:tRCURLY, "}")
|
1135
1163
|
end
|
1136
1164
|
|
1137
|
-
def
|
1165
|
+
def test_open_square_bracket_arg
|
1138
1166
|
util_lex_token("m [ 3 ]",
|
1139
1167
|
:tIDENTIFIER, "m",
|
1140
1168
|
:tLBRACK, "[",
|
@@ -1142,7 +1170,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1142
1170
|
:tRBRACK, "]")
|
1143
1171
|
end
|
1144
1172
|
|
1145
|
-
def
|
1173
|
+
def test_open_square_bracket_ary
|
1146
1174
|
util_lex_token("[1, 2, 3]",
|
1147
1175
|
:tLBRACK, "[",
|
1148
1176
|
:tINTEGER, 1,
|
@@ -1153,7 +1181,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1153
1181
|
:tRBRACK, "]")
|
1154
1182
|
end
|
1155
1183
|
|
1156
|
-
def
|
1184
|
+
def test_open_square_bracket_meth
|
1157
1185
|
util_lex_token("m[3]",
|
1158
1186
|
:tIDENTIFIER, "m",
|
1159
1187
|
:tLBRACK2, "[",
|
@@ -1161,60 +1189,60 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1161
1189
|
:tRBRACK, "]")
|
1162
1190
|
end
|
1163
1191
|
|
1164
|
-
def
|
1192
|
+
def test_or
|
1165
1193
|
util_lex_token "|", :tPIPE, "|"
|
1166
1194
|
end
|
1167
1195
|
|
1168
|
-
def
|
1196
|
+
def test_or2
|
1169
1197
|
util_lex_token "||", :tOROP, "||"
|
1170
1198
|
end
|
1171
1199
|
|
1172
|
-
def
|
1200
|
+
def test_or2_equals
|
1173
1201
|
util_lex_token "||=", :tOP_ASGN, "||"
|
1174
1202
|
end
|
1175
1203
|
|
1176
|
-
def
|
1204
|
+
def test_or_equals
|
1177
1205
|
util_lex_token "|=", :tOP_ASGN, "|"
|
1178
1206
|
end
|
1179
1207
|
|
1180
|
-
def
|
1208
|
+
def test_percent
|
1181
1209
|
util_lex_token("a % 2",
|
1182
1210
|
:tIDENTIFIER, "a",
|
1183
1211
|
:tPERCENT, "%",
|
1184
1212
|
:tINTEGER, 2)
|
1185
1213
|
end
|
1186
1214
|
|
1187
|
-
def
|
1215
|
+
def test_percent_equals
|
1188
1216
|
util_lex_token("a %= 2",
|
1189
1217
|
:tIDENTIFIER, "a",
|
1190
1218
|
:tOP_ASGN, "%",
|
1191
1219
|
:tINTEGER, 2)
|
1192
1220
|
end
|
1193
1221
|
|
1194
|
-
def
|
1222
|
+
def test_plus
|
1195
1223
|
util_lex_token("1 + 1", # TODO state?
|
1196
1224
|
:tINTEGER, 1,
|
1197
1225
|
:tPLUS, "+",
|
1198
1226
|
:tINTEGER, 1)
|
1199
1227
|
end
|
1200
1228
|
|
1201
|
-
def
|
1229
|
+
def test_plus_equals
|
1202
1230
|
@lex.state = :expr_end
|
1203
1231
|
|
1204
1232
|
util_lex_token "+=", :tOP_ASGN, "+"
|
1205
1233
|
end
|
1206
1234
|
|
1207
|
-
def
|
1235
|
+
def test_plus_method
|
1208
1236
|
@lex.state = :expr_fname
|
1209
1237
|
util_lex_token "+", :tPLUS, "+"
|
1210
1238
|
end
|
1211
1239
|
|
1212
|
-
def
|
1240
|
+
def test_plus_unary_method
|
1213
1241
|
@lex.state = :expr_fname
|
1214
1242
|
util_lex_token "+@", :tUPLUS, "+@"
|
1215
1243
|
end
|
1216
1244
|
|
1217
|
-
def
|
1245
|
+
def test_numbers
|
1218
1246
|
util_lex_token "0b10", :tINTEGER, 2
|
1219
1247
|
util_lex_token "0B10", :tINTEGER, 2
|
1220
1248
|
|
@@ -1253,28 +1281,28 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1253
1281
|
util_bad_token "1__1"
|
1254
1282
|
end
|
1255
1283
|
|
1256
|
-
def
|
1284
|
+
def test_plus_unary_number
|
1257
1285
|
util_lex_token("+42",
|
1258
1286
|
:tINTEGER, 42)
|
1259
1287
|
end
|
1260
1288
|
|
1261
|
-
def
|
1289
|
+
def test_question__18
|
1262
1290
|
setup_lexer 18
|
1263
1291
|
|
1264
1292
|
util_lex_token "?*", :tINTEGER, 42
|
1265
1293
|
end
|
1266
1294
|
|
1267
|
-
def
|
1295
|
+
def test_question__19
|
1268
1296
|
setup_lexer 19
|
1269
1297
|
|
1270
1298
|
util_lex_token "?*", :tSTRING, "*"
|
1271
1299
|
end
|
1272
1300
|
|
1273
|
-
def
|
1301
|
+
def test_question_bad_eos
|
1274
1302
|
util_bad_token "?"
|
1275
1303
|
end
|
1276
1304
|
|
1277
|
-
def
|
1305
|
+
def test_question_bad_ws
|
1278
1306
|
util_lex_token "? ", :tEH, "?"
|
1279
1307
|
util_lex_token "?\n", :tEH, "?"
|
1280
1308
|
util_lex_token "?\t", :tEH, "?"
|
@@ -1283,7 +1311,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1283
1311
|
util_lex_token "?\f", :tEH, "?"
|
1284
1312
|
end
|
1285
1313
|
|
1286
|
-
def
|
1314
|
+
def test_question_ws_backslashed__18
|
1287
1315
|
setup_lexer 18
|
1288
1316
|
|
1289
1317
|
@lex.state = :expr_beg
|
@@ -1300,7 +1328,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1300
1328
|
util_lex_token "?\\f", :tINTEGER, 12
|
1301
1329
|
end
|
1302
1330
|
|
1303
|
-
def
|
1331
|
+
def test_question_ws_backslashed__19
|
1304
1332
|
setup_lexer 19
|
1305
1333
|
|
1306
1334
|
@lex.state = :expr_beg
|
@@ -1317,15 +1345,15 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1317
1345
|
util_lex_token "?\\f", :tSTRING, "\f"
|
1318
1346
|
end
|
1319
1347
|
|
1320
|
-
def
|
1348
|
+
def test_rbracket
|
1321
1349
|
util_lex_token "]", :tRBRACK, "]"
|
1322
1350
|
end
|
1323
1351
|
|
1324
|
-
def
|
1352
|
+
def test_rcurly
|
1325
1353
|
util_lex_token "}", :tRCURLY, "}"
|
1326
1354
|
end
|
1327
1355
|
|
1328
|
-
def
|
1356
|
+
def test_regexp
|
1329
1357
|
util_lex_token("/regexp/",
|
1330
1358
|
:tREGEXP_BEG, "/",
|
1331
1359
|
:tSTRING_CONTENT, "regexp",
|
@@ -1333,7 +1361,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1333
1361
|
:tREGEXP_OPT, "")
|
1334
1362
|
end
|
1335
1363
|
|
1336
|
-
def
|
1364
|
+
def test_regexp_ambiguous
|
1337
1365
|
util_lex_token("method /regexp/",
|
1338
1366
|
:tIDENTIFIER, "method",
|
1339
1367
|
:tREGEXP_BEG, "/",
|
@@ -1342,13 +1370,14 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1342
1370
|
:tREGEXP_OPT, "")
|
1343
1371
|
end
|
1344
1372
|
|
1345
|
-
def
|
1373
|
+
def test_regexp_bad
|
1346
1374
|
util_bad_token("/.*/xyz",
|
1347
|
-
:tREGEXP_BEG,
|
1348
|
-
:tSTRING_CONTENT, ".*"
|
1375
|
+
:tREGEXP_BEG, "/",
|
1376
|
+
:tSTRING_CONTENT, ".*",
|
1377
|
+
:tSTRING_END, "/")
|
1349
1378
|
end
|
1350
1379
|
|
1351
|
-
def
|
1380
|
+
def test_regexp_escape_C
|
1352
1381
|
util_lex_token('/regex\\C-x/',
|
1353
1382
|
:tREGEXP_BEG, "/",
|
1354
1383
|
:tSTRING_CONTENT, "regex\\C-x",
|
@@ -1356,7 +1385,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1356
1385
|
:tREGEXP_OPT, "")
|
1357
1386
|
end
|
1358
1387
|
|
1359
|
-
def
|
1388
|
+
def test_regexp_escape_C_M
|
1360
1389
|
util_lex_token('/regex\\C-\\M-x/',
|
1361
1390
|
:tREGEXP_BEG, "/",
|
1362
1391
|
:tSTRING_CONTENT, "regex\\C-\\M-x",
|
@@ -1364,7 +1393,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1364
1393
|
:tREGEXP_OPT, "")
|
1365
1394
|
end
|
1366
1395
|
|
1367
|
-
def
|
1396
|
+
def test_regexp_escape_C_M_craaaazy
|
1368
1397
|
util_lex_token("/regex\\C-\\\n\\M-x/",
|
1369
1398
|
:tREGEXP_BEG, "/",
|
1370
1399
|
:tSTRING_CONTENT, "regex\\C-\\M-x",
|
@@ -1372,27 +1401,27 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1372
1401
|
:tREGEXP_OPT, "")
|
1373
1402
|
end
|
1374
1403
|
|
1375
|
-
def
|
1404
|
+
def test_regexp_escape_C_bad_dash
|
1376
1405
|
util_bad_token '/regex\\Cx/', :tREGEXP_BEG, "/"
|
1377
1406
|
end
|
1378
1407
|
|
1379
|
-
def
|
1408
|
+
def test_regexp_escape_C_bad_dash_eos
|
1380
1409
|
util_bad_token '/regex\\C-/', :tREGEXP_BEG, "/"
|
1381
1410
|
end
|
1382
1411
|
|
1383
|
-
def
|
1412
|
+
def test_regexp_escape_C_bad_dash_eos2
|
1384
1413
|
util_bad_token '/regex\\C-', :tREGEXP_BEG, "/"
|
1385
1414
|
end
|
1386
1415
|
|
1387
|
-
def
|
1416
|
+
def test_regexp_escape_C_bad_eos
|
1388
1417
|
util_bad_token '/regex\\C/', :tREGEXP_BEG, "/"
|
1389
1418
|
end
|
1390
1419
|
|
1391
|
-
def
|
1420
|
+
def test_regexp_escape_C_bad_eos2
|
1392
1421
|
util_bad_token '/regex\\c', :tREGEXP_BEG, "/"
|
1393
1422
|
end
|
1394
1423
|
|
1395
|
-
def
|
1424
|
+
def test_regexp_escape_M
|
1396
1425
|
util_lex_token('/regex\\M-x/',
|
1397
1426
|
:tREGEXP_BEG, "/",
|
1398
1427
|
:tSTRING_CONTENT, "regex\\M-x",
|
@@ -1400,7 +1429,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1400
1429
|
:tREGEXP_OPT, "")
|
1401
1430
|
end
|
1402
1431
|
|
1403
|
-
def
|
1432
|
+
def test_regexp_escape_M_C
|
1404
1433
|
util_lex_token('/regex\\M-\\C-x/',
|
1405
1434
|
:tREGEXP_BEG, "/",
|
1406
1435
|
:tSTRING_CONTENT, "regex\\M-\\C-x",
|
@@ -1408,23 +1437,23 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1408
1437
|
:tREGEXP_OPT, "")
|
1409
1438
|
end
|
1410
1439
|
|
1411
|
-
def
|
1440
|
+
def test_regexp_escape_M_bad_dash
|
1412
1441
|
util_bad_token '/regex\\Mx/', :tREGEXP_BEG, "/"
|
1413
1442
|
end
|
1414
1443
|
|
1415
|
-
def
|
1444
|
+
def test_regexp_escape_M_bad_dash_eos
|
1416
1445
|
util_bad_token '/regex\\M-/', :tREGEXP_BEG, "/"
|
1417
1446
|
end
|
1418
1447
|
|
1419
|
-
def
|
1448
|
+
def test_regexp_escape_M_bad_dash_eos2
|
1420
1449
|
util_bad_token '/regex\\M-', :tREGEXP_BEG, "/"
|
1421
1450
|
end
|
1422
1451
|
|
1423
|
-
def
|
1452
|
+
def test_regexp_escape_M_bad_eos
|
1424
1453
|
util_bad_token '/regex\\M/', :tREGEXP_BEG, "/"
|
1425
1454
|
end
|
1426
1455
|
|
1427
|
-
def
|
1456
|
+
def test_regexp_escape_backslash_slash
|
1428
1457
|
util_lex_token('/\\//',
|
1429
1458
|
:tREGEXP_BEG, "/",
|
1430
1459
|
:tSTRING_CONTENT, '\\/',
|
@@ -1432,43 +1461,43 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1432
1461
|
:tREGEXP_OPT, "")
|
1433
1462
|
end
|
1434
1463
|
|
1435
|
-
def
|
1464
|
+
def test_regexp_escape_backslash_terminator
|
1436
1465
|
util_lex_token('%r%blah\\%blah%',
|
1437
|
-
:tREGEXP_BEG, "%r",
|
1466
|
+
:tREGEXP_BEG, "%r%",
|
1438
1467
|
:tSTRING_CONTENT, "blah\\%blah",
|
1439
1468
|
:tSTRING_END, "%",
|
1440
1469
|
:tREGEXP_OPT, "")
|
1441
1470
|
end
|
1442
1471
|
|
1443
|
-
def
|
1472
|
+
def test_regexp_escape_backslash_terminator_meta1
|
1444
1473
|
util_lex_token('%r{blah\\}blah}',
|
1445
|
-
:tREGEXP_BEG, "%r",
|
1474
|
+
:tREGEXP_BEG, "%r{",
|
1446
1475
|
:tSTRING_CONTENT, "blah\\}blah",
|
1447
1476
|
:tSTRING_END, "}",
|
1448
1477
|
:tREGEXP_OPT, "")
|
1449
1478
|
end
|
1450
1479
|
|
1451
|
-
def
|
1480
|
+
def test_regexp_escape_backslash_terminator_meta2
|
1452
1481
|
util_lex_token('%r/blah\\/blah/',
|
1453
|
-
:tREGEXP_BEG, "%r",
|
1482
|
+
:tREGEXP_BEG, "%r/",
|
1454
1483
|
:tSTRING_CONTENT, "blah\\/blah",
|
1455
1484
|
:tSTRING_END, "/",
|
1456
1485
|
:tREGEXP_OPT, "")
|
1457
1486
|
end
|
1458
1487
|
|
1459
|
-
def
|
1488
|
+
def test_regexp_escape_backslash_terminator_meta3
|
1460
1489
|
util_lex_token('%r/blah\\%blah/',
|
1461
|
-
:tREGEXP_BEG, "%r",
|
1490
|
+
:tREGEXP_BEG, "%r/",
|
1462
1491
|
:tSTRING_CONTENT, "blah\\%blah",
|
1463
1492
|
:tSTRING_END, "/",
|
1464
1493
|
:tREGEXP_OPT, "")
|
1465
1494
|
end
|
1466
1495
|
|
1467
|
-
def
|
1496
|
+
def test_regexp_escape_bad_eos
|
1468
1497
|
util_bad_token '/regex\\', :tREGEXP_BEG, "/"
|
1469
1498
|
end
|
1470
1499
|
|
1471
|
-
def
|
1500
|
+
def test_regexp_escape_bs
|
1472
1501
|
util_lex_token('/regex\\\\regex/',
|
1473
1502
|
:tREGEXP_BEG, "/",
|
1474
1503
|
:tSTRING_CONTENT, "regex\\\\regex",
|
@@ -1476,7 +1505,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1476
1505
|
:tREGEXP_OPT, "")
|
1477
1506
|
end
|
1478
1507
|
|
1479
|
-
def
|
1508
|
+
def test_regexp_escape_c
|
1480
1509
|
util_lex_token('/regex\\cxxx/',
|
1481
1510
|
:tREGEXP_BEG, "/",
|
1482
1511
|
:tSTRING_CONTENT, "regex\\cxxx",
|
@@ -1484,7 +1513,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1484
1513
|
:tREGEXP_OPT, "")
|
1485
1514
|
end
|
1486
1515
|
|
1487
|
-
def
|
1516
|
+
def test_regexp_escape_c_backslash
|
1488
1517
|
util_lex_token('/regex\\c\\n/',
|
1489
1518
|
:tREGEXP_BEG, "/",
|
1490
1519
|
:tSTRING_CONTENT, "regex\\c\\n",
|
@@ -1492,7 +1521,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1492
1521
|
:tREGEXP_OPT, "")
|
1493
1522
|
end
|
1494
1523
|
|
1495
|
-
def
|
1524
|
+
def test_regexp_escape_chars
|
1496
1525
|
util_lex_token('/re\\tge\\nxp/',
|
1497
1526
|
:tREGEXP_BEG, "/",
|
1498
1527
|
:tSTRING_CONTENT, "re\\tge\\nxp",
|
@@ -1500,7 +1529,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1500
1529
|
:tREGEXP_OPT, "")
|
1501
1530
|
end
|
1502
1531
|
|
1503
|
-
def
|
1532
|
+
def test_regexp_escape_double_backslash
|
1504
1533
|
regexp = '/[\\/\\\\]$/'
|
1505
1534
|
util_lex_token(regexp,
|
1506
1535
|
:tREGEXP_BEG, "/",
|
@@ -1509,7 +1538,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1509
1538
|
:tREGEXP_OPT, "")
|
1510
1539
|
end
|
1511
1540
|
|
1512
|
-
def
|
1541
|
+
def test_regexp_escape_hex
|
1513
1542
|
util_lex_token('/regex\\x61xp/',
|
1514
1543
|
:tREGEXP_BEG, "/",
|
1515
1544
|
:tSTRING_CONTENT, "regex\\x61xp",
|
@@ -1517,11 +1546,11 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1517
1546
|
:tREGEXP_OPT, "")
|
1518
1547
|
end
|
1519
1548
|
|
1520
|
-
def
|
1549
|
+
def test_regexp_escape_hex_bad
|
1521
1550
|
util_bad_token '/regex\\xzxp/', :tREGEXP_BEG, "/"
|
1522
1551
|
end
|
1523
1552
|
|
1524
|
-
def
|
1553
|
+
def test_regexp_escape_hex_one
|
1525
1554
|
util_lex_token('/^[\\xd\\xa]{2}/on',
|
1526
1555
|
:tREGEXP_BEG, '/',
|
1527
1556
|
:tSTRING_CONTENT, '^[\\xd\\xa]{2}',
|
@@ -1529,7 +1558,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1529
1558
|
:tREGEXP_OPT, 'on')
|
1530
1559
|
end
|
1531
1560
|
|
1532
|
-
def
|
1561
|
+
def test_regexp_escape_oct1
|
1533
1562
|
util_lex_token('/regex\\0xp/',
|
1534
1563
|
:tREGEXP_BEG, "/",
|
1535
1564
|
:tSTRING_CONTENT, "regex\\0xp",
|
@@ -1537,7 +1566,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1537
1566
|
:tREGEXP_OPT, "")
|
1538
1567
|
end
|
1539
1568
|
|
1540
|
-
def
|
1569
|
+
def test_regexp_escape_oct2
|
1541
1570
|
util_lex_token('/regex\\07xp/',
|
1542
1571
|
:tREGEXP_BEG, "/",
|
1543
1572
|
:tSTRING_CONTENT, "regex\\07xp",
|
@@ -1545,7 +1574,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1545
1574
|
:tREGEXP_OPT, "")
|
1546
1575
|
end
|
1547
1576
|
|
1548
|
-
def
|
1577
|
+
def test_regexp_escape_oct3
|
1549
1578
|
util_lex_token('/regex\\10142/',
|
1550
1579
|
:tREGEXP_BEG, "/",
|
1551
1580
|
:tSTRING_CONTENT, "regex\\10142",
|
@@ -1553,7 +1582,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1553
1582
|
:tREGEXP_OPT, "")
|
1554
1583
|
end
|
1555
1584
|
|
1556
|
-
def
|
1585
|
+
def test_regexp_escape_return
|
1557
1586
|
util_lex_token("/regex\\\nregex/",
|
1558
1587
|
:tREGEXP_BEG, "/",
|
1559
1588
|
:tSTRING_CONTENT, "regexregex",
|
@@ -1561,7 +1590,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1561
1590
|
:tREGEXP_OPT, "")
|
1562
1591
|
end
|
1563
1592
|
|
1564
|
-
def
|
1593
|
+
def test_regexp_nm
|
1565
1594
|
util_lex_token("/.*/nm",
|
1566
1595
|
:tREGEXP_BEG, "/",
|
1567
1596
|
:tSTRING_CONTENT, ".*",
|
@@ -1569,25 +1598,25 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1569
1598
|
:tREGEXP_OPT, "nm")
|
1570
1599
|
end
|
1571
1600
|
|
1572
|
-
def
|
1601
|
+
def test_rparen
|
1573
1602
|
util_lex_token ")", :tRPAREN, ")"
|
1574
1603
|
end
|
1575
1604
|
|
1576
|
-
def
|
1605
|
+
def test_rshft
|
1577
1606
|
util_lex_token("a >> 2",
|
1578
1607
|
:tIDENTIFIER, "a",
|
1579
1608
|
:tRSHFT, ">>",
|
1580
1609
|
:tINTEGER, 2)
|
1581
1610
|
end
|
1582
1611
|
|
1583
|
-
def
|
1612
|
+
def test_rshft_equals
|
1584
1613
|
util_lex_token("a >>= 2",
|
1585
1614
|
:tIDENTIFIER, "a",
|
1586
1615
|
:tOP_ASGN, ">>",
|
1587
1616
|
:tINTEGER, 2)
|
1588
1617
|
end
|
1589
1618
|
|
1590
|
-
def
|
1619
|
+
def test_star
|
1591
1620
|
util_lex_token("a * ",
|
1592
1621
|
:tIDENTIFIER, "a",
|
1593
1622
|
:tSTAR2, "*")
|
@@ -1595,7 +1624,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1595
1624
|
assert_equal :expr_beg, @lex.state
|
1596
1625
|
end
|
1597
1626
|
|
1598
|
-
def
|
1627
|
+
def test_star2
|
1599
1628
|
util_lex_token("a ** ",
|
1600
1629
|
:tIDENTIFIER, "a",
|
1601
1630
|
:tPOW, "**")
|
@@ -1603,7 +1632,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1603
1632
|
assert_equal :expr_beg, @lex.state
|
1604
1633
|
end
|
1605
1634
|
|
1606
|
-
def
|
1635
|
+
def test_star2_equals
|
1607
1636
|
util_lex_token("a **= ",
|
1608
1637
|
:tIDENTIFIER, "a",
|
1609
1638
|
:tOP_ASGN, "**")
|
@@ -1611,7 +1640,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1611
1640
|
assert_equal :expr_beg, @lex.state
|
1612
1641
|
end
|
1613
1642
|
|
1614
|
-
def
|
1643
|
+
def test_star_arg
|
1615
1644
|
@lex.state = :expr_arg
|
1616
1645
|
|
1617
1646
|
util_lex_token(" *a",
|
@@ -1621,7 +1650,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1621
1650
|
assert_equal :expr_arg, @lex.state
|
1622
1651
|
end
|
1623
1652
|
|
1624
|
-
def
|
1653
|
+
def test_star_arg_beg
|
1625
1654
|
@lex.state = :expr_beg
|
1626
1655
|
|
1627
1656
|
util_lex_token("*a",
|
@@ -1631,7 +1660,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1631
1660
|
assert_equal :expr_arg, @lex.state
|
1632
1661
|
end
|
1633
1662
|
|
1634
|
-
def
|
1663
|
+
def test_star_arg_beg_fname
|
1635
1664
|
@lex.state = :expr_fname
|
1636
1665
|
|
1637
1666
|
util_lex_token("*a",
|
@@ -1641,7 +1670,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1641
1670
|
assert_equal :expr_arg, @lex.state
|
1642
1671
|
end
|
1643
1672
|
|
1644
|
-
def
|
1673
|
+
def test_star_equals
|
1645
1674
|
util_lex_token("a *= ",
|
1646
1675
|
:tIDENTIFIER, "a",
|
1647
1676
|
:tOP_ASGN, "*")
|
@@ -1649,97 +1678,97 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1649
1678
|
assert_equal :expr_beg, @lex.state
|
1650
1679
|
end
|
1651
1680
|
|
1652
|
-
def
|
1681
|
+
def test_string_bad_eos
|
1653
1682
|
util_bad_token('%',
|
1654
1683
|
:tSTRING_BEG, '%')
|
1655
1684
|
end
|
1656
1685
|
|
1657
|
-
def
|
1686
|
+
def test_string_bad_eos_quote
|
1658
1687
|
util_bad_token('%{nest',
|
1659
1688
|
:tSTRING_BEG, '%}')
|
1660
1689
|
end
|
1661
1690
|
|
1662
|
-
def
|
1691
|
+
def test_string_double
|
1663
1692
|
util_lex_token('"string"',
|
1664
1693
|
:tSTRING, "string")
|
1665
1694
|
end
|
1666
1695
|
|
1667
|
-
def
|
1696
|
+
def test_string_double_escape_C
|
1668
1697
|
util_lex_token('"\\C-a"',
|
1669
1698
|
:tSTRING, "\001")
|
1670
1699
|
end
|
1671
1700
|
|
1672
|
-
def
|
1701
|
+
def test_string_double_escape_C_backslash
|
1673
1702
|
util_lex_token('"\\C-\\\\"',
|
1674
1703
|
:tSTRING, "\034")
|
1675
1704
|
end
|
1676
1705
|
|
1677
|
-
def
|
1706
|
+
def test_string_double_escape_C_escape
|
1678
1707
|
util_lex_token('"\\C-\\M-a"',
|
1679
1708
|
:tSTRING, "\201")
|
1680
1709
|
end
|
1681
1710
|
|
1682
|
-
def
|
1711
|
+
def test_string_double_escape_C_question
|
1683
1712
|
util_lex_token('"\\C-?"',
|
1684
1713
|
:tSTRING, "\177")
|
1685
1714
|
end
|
1686
1715
|
|
1687
|
-
def
|
1716
|
+
def test_string_double_escape_M
|
1688
1717
|
util_lex_token('"\\M-a"',
|
1689
1718
|
:tSTRING, "\341")
|
1690
1719
|
end
|
1691
1720
|
|
1692
|
-
def
|
1721
|
+
def test_string_double_escape_M_backslash
|
1693
1722
|
util_lex_token('"\\M-\\\\"',
|
1694
1723
|
:tSTRING, "\334")
|
1695
1724
|
end
|
1696
1725
|
|
1697
|
-
def
|
1726
|
+
def test_string_double_escape_M_escape
|
1698
1727
|
util_lex_token('"\\M-\\C-a"',
|
1699
1728
|
:tSTRING, "\201")
|
1700
1729
|
end
|
1701
1730
|
|
1702
|
-
def
|
1731
|
+
def test_string_double_escape_bs1
|
1703
1732
|
util_lex_token('"a\\a\\a"',
|
1704
1733
|
:tSTRING, "a\a\a")
|
1705
1734
|
end
|
1706
1735
|
|
1707
|
-
def
|
1736
|
+
def test_string_double_escape_bs2
|
1708
1737
|
util_lex_token('"a\\\\a"',
|
1709
1738
|
:tSTRING, "a\\a")
|
1710
1739
|
end
|
1711
1740
|
|
1712
|
-
def
|
1741
|
+
def test_string_double_escape_c
|
1713
1742
|
util_lex_token('"\\ca"',
|
1714
1743
|
:tSTRING, "\001")
|
1715
1744
|
end
|
1716
1745
|
|
1717
|
-
def
|
1746
|
+
def test_string_double_escape_c_escape
|
1718
1747
|
util_lex_token('"\\c\\M-a"',
|
1719
1748
|
:tSTRING, "\201")
|
1720
1749
|
end
|
1721
1750
|
|
1722
|
-
def
|
1751
|
+
def test_string_double_escape_c_question
|
1723
1752
|
util_lex_token('"\\c?"',
|
1724
1753
|
:tSTRING, "\177")
|
1725
1754
|
end
|
1726
1755
|
|
1727
|
-
def
|
1756
|
+
def test_string_double_escape_chars
|
1728
1757
|
util_lex_token('"s\\tri\\ng"',
|
1729
1758
|
:tSTRING, "s\tri\ng")
|
1730
1759
|
end
|
1731
1760
|
|
1732
|
-
def
|
1761
|
+
def test_string_double_escape_hex
|
1733
1762
|
util_lex_token('"n = \\x61\\x62\\x63"',
|
1734
1763
|
:tSTRING, "n = abc")
|
1735
1764
|
end
|
1736
1765
|
|
1737
|
-
def
|
1766
|
+
def test_string_double_escape_octal
|
1738
1767
|
util_lex_token('"n = \\101\\102\\103"',
|
1739
1768
|
:tSTRING, "n = ABC")
|
1740
1769
|
end
|
1741
1770
|
|
1742
|
-
def
|
1771
|
+
def test_string_double_interp
|
1743
1772
|
util_lex_token("\"blah #x a \#@a b \#$b c \#{3} # \"",
|
1744
1773
|
:tSTRING_BEG, "\"",
|
1745
1774
|
:tSTRING_CONTENT, "blah #x a ",
|
@@ -1756,12 +1785,12 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1756
1785
|
:tSTRING_END, "\"")
|
1757
1786
|
end
|
1758
1787
|
|
1759
|
-
def
|
1788
|
+
def test_string_double_nested_curlies
|
1760
1789
|
util_lex_token('%{nest{one{two}one}nest}',
|
1761
1790
|
:tSTRING, "nest{one{two}one}nest")
|
1762
1791
|
end
|
1763
1792
|
|
1764
|
-
def
|
1793
|
+
def test_string_double_no_interp
|
1765
1794
|
util_lex_token("\"# blah\"", # pound first
|
1766
1795
|
:tSTRING, "# blah")
|
1767
1796
|
|
@@ -1769,19 +1798,19 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1769
1798
|
:tSTRING, "blah # blah")
|
1770
1799
|
end
|
1771
1800
|
|
1772
|
-
def
|
1801
|
+
def test_string_escape_x_single
|
1773
1802
|
util_lex_token('"\\x0"',
|
1774
1803
|
:tSTRING, "\000")
|
1775
1804
|
end
|
1776
1805
|
|
1777
|
-
def
|
1806
|
+
def test_string_pct_Q
|
1778
1807
|
util_lex_token("%Q[s1 s2]",
|
1779
1808
|
:tSTRING, "s1 s2")
|
1780
1809
|
end
|
1781
1810
|
|
1782
|
-
def
|
1811
|
+
def test_string_pct_W
|
1783
1812
|
util_lex_token("%W[s1 s2\ns3]", # TODO: add interpolation to these
|
1784
|
-
:tWORDS_BEG, "%W",
|
1813
|
+
:tWORDS_BEG, "%W[",
|
1785
1814
|
:tSTRING_CONTENT, "s1",
|
1786
1815
|
:tSPACE, nil,
|
1787
1816
|
:tSTRING_CONTENT, "s2",
|
@@ -1791,9 +1820,9 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1791
1820
|
:tSTRING_END, ']')
|
1792
1821
|
end
|
1793
1822
|
|
1794
|
-
def
|
1823
|
+
def test_string_pct_W_bs_nl
|
1795
1824
|
util_lex_token("%W[s1 \\\ns2]", # TODO: add interpolation to these
|
1796
|
-
:tWORDS_BEG, "%W",
|
1825
|
+
:tWORDS_BEG, "%W[",
|
1797
1826
|
:tSTRING_CONTENT, "s1",
|
1798
1827
|
:tSPACE, nil,
|
1799
1828
|
:tSTRING_CONTENT, "\ns2",
|
@@ -1801,28 +1830,28 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1801
1830
|
:tSTRING_END, ']')
|
1802
1831
|
end
|
1803
1832
|
|
1804
|
-
def
|
1833
|
+
def test_string_pct_angle
|
1805
1834
|
util_lex_token("%<blah>",
|
1806
1835
|
:tSTRING, "blah")
|
1807
1836
|
end
|
1808
1837
|
|
1809
|
-
def
|
1838
|
+
def test_string_pct_other
|
1810
1839
|
util_lex_token("%%blah%",
|
1811
1840
|
:tSTRING, "blah")
|
1812
1841
|
end
|
1813
1842
|
|
1814
|
-
def
|
1843
|
+
def test_string_pct_w
|
1815
1844
|
util_bad_token("%w[s1 s2 ",
|
1816
|
-
:tQWORDS_BEG, "%w",
|
1845
|
+
:tQWORDS_BEG, "%w[",
|
1817
1846
|
:tSTRING_CONTENT, "s1",
|
1818
1847
|
:tSPACE, nil,
|
1819
1848
|
:tSTRING_CONTENT, "s2",
|
1820
1849
|
:tSPACE, nil)
|
1821
1850
|
end
|
1822
1851
|
|
1823
|
-
def
|
1852
|
+
def test_string_pct_w_bs_nl
|
1824
1853
|
util_lex_token("%w[s1 \\\ns2]",
|
1825
|
-
:tQWORDS_BEG, "%w",
|
1854
|
+
:tQWORDS_BEG, "%w[",
|
1826
1855
|
:tSTRING_CONTENT, "s1",
|
1827
1856
|
:tSPACE, nil,
|
1828
1857
|
:tSTRING_CONTENT, "\ns2",
|
@@ -1830,9 +1859,9 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1830
1859
|
:tSTRING_END, ']')
|
1831
1860
|
end
|
1832
1861
|
|
1833
|
-
def
|
1862
|
+
def test_string_pct_w_bs_sp
|
1834
1863
|
util_lex_token("%w[s\\ 1 s\\ 2]",
|
1835
|
-
:tQWORDS_BEG, "%w",
|
1864
|
+
:tQWORDS_BEG, "%w[",
|
1836
1865
|
:tSTRING_CONTENT, "s 1",
|
1837
1866
|
:tSPACE, nil,
|
1838
1867
|
:tSTRING_CONTENT, "s 2",
|
@@ -1840,9 +1869,9 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1840
1869
|
:tSTRING_END, ']')
|
1841
1870
|
end
|
1842
1871
|
|
1843
|
-
def
|
1872
|
+
def test_string_pct_w_tab
|
1844
1873
|
util_lex_token("%w[abc\tdef]",
|
1845
|
-
:tQWORDS_BEG, "%w",
|
1874
|
+
:tQWORDS_BEG, "%w[",
|
1846
1875
|
:tSTRING_CONTENT, "abc",
|
1847
1876
|
:tSPACE, nil,
|
1848
1877
|
:tSTRING_CONTENT, "def",
|
@@ -1850,42 +1879,45 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1850
1879
|
:tSTRING_END, ']')
|
1851
1880
|
end
|
1852
1881
|
|
1853
|
-
def
|
1882
|
+
def test_string_single
|
1854
1883
|
util_lex_token("'string'",
|
1855
1884
|
:tSTRING, "string")
|
1856
1885
|
end
|
1857
1886
|
|
1858
|
-
def
|
1887
|
+
def test_string_single_escape_chars
|
1859
1888
|
util_lex_token("'s\\tri\\ng'",
|
1860
1889
|
:tSTRING, "s\\tri\\ng")
|
1861
1890
|
end
|
1862
1891
|
|
1863
|
-
def
|
1892
|
+
def test_string_single_nl
|
1864
1893
|
util_lex_token("'blah\\\nblah'",
|
1865
|
-
:
|
1894
|
+
:tSTRING_BEG, "'",
|
1895
|
+
:tSTRING_CONTENT, "blah\\\n",
|
1896
|
+
:tSTRING_CONTENT, "blah",
|
1897
|
+
:tSTRING_END, "'")
|
1866
1898
|
end
|
1867
1899
|
|
1868
|
-
def
|
1900
|
+
def test_symbol
|
1869
1901
|
util_lex_token(":symbol",
|
1870
1902
|
:tSYMBOL, "symbol")
|
1871
1903
|
end
|
1872
1904
|
|
1873
|
-
def
|
1905
|
+
def test_symbol_bad_zero
|
1874
1906
|
util_bad_token(":\"blah\0\"",
|
1875
1907
|
:tSYMBEG, ":")
|
1876
1908
|
end
|
1877
1909
|
|
1878
|
-
def
|
1910
|
+
def test_symbol_double
|
1879
1911
|
util_lex_token(":\"symbol\"",
|
1880
1912
|
:tSYMBOL, "symbol")
|
1881
1913
|
end
|
1882
1914
|
|
1883
|
-
def
|
1915
|
+
def test_symbol_single
|
1884
1916
|
util_lex_token(":'symbol'",
|
1885
1917
|
:tSYMBOL, "symbol")
|
1886
1918
|
end
|
1887
1919
|
|
1888
|
-
def
|
1920
|
+
def test_ternary
|
1889
1921
|
util_lex_token("a ? b : c",
|
1890
1922
|
:tIDENTIFIER, "a",
|
1891
1923
|
:tEH, "?",
|
@@ -1911,39 +1943,42 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1911
1943
|
:tEH, "?")
|
1912
1944
|
end
|
1913
1945
|
|
1914
|
-
def
|
1946
|
+
def test_tilde
|
1915
1947
|
util_lex_token "~", :tTILDE, "~"
|
1916
1948
|
end
|
1917
1949
|
|
1918
|
-
def
|
1950
|
+
def test_tilde_unary
|
1919
1951
|
@lex.state = :expr_fname
|
1920
1952
|
util_lex_token "~@", :tTILDE, "~@"
|
1921
1953
|
end
|
1922
1954
|
|
1923
|
-
def
|
1955
|
+
def test_uminus
|
1924
1956
|
util_lex_token("-blah",
|
1925
1957
|
:tUMINUS, "-",
|
1926
1958
|
:tIDENTIFIER, "blah")
|
1927
1959
|
end
|
1928
1960
|
|
1929
|
-
def
|
1961
|
+
def test_underscore
|
1930
1962
|
util_lex_token("_var", :tIDENTIFIER, "_var")
|
1931
1963
|
end
|
1932
1964
|
|
1933
|
-
def
|
1934
|
-
|
1965
|
+
def test_underscore_end
|
1966
|
+
source_buffer = Parser::Source::Buffer.new('(underscore_end)')
|
1967
|
+
source_buffer.source = "__END__\n"
|
1968
|
+
|
1969
|
+
@lex.source_buffer = source_buffer
|
1935
1970
|
|
1936
1971
|
tok, = @lex.advance
|
1937
1972
|
refute tok
|
1938
1973
|
end
|
1939
1974
|
|
1940
|
-
def
|
1975
|
+
def test_uplus
|
1941
1976
|
util_lex_token("+blah",
|
1942
1977
|
:tUPLUS, "+",
|
1943
1978
|
:tIDENTIFIER, "blah")
|
1944
1979
|
end
|
1945
1980
|
|
1946
|
-
def
|
1981
|
+
def test_if_unless_mod
|
1947
1982
|
util_lex_token("return if true unless false",
|
1948
1983
|
:kRETURN, "return",
|
1949
1984
|
:kIF_MOD, "if",
|
@@ -1952,7 +1987,7 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1952
1987
|
:kFALSE, "false")
|
1953
1988
|
end
|
1954
1989
|
|
1955
|
-
def
|
1990
|
+
def test_if_stmt
|
1956
1991
|
util_lex_token("if true\n return end",
|
1957
1992
|
:kIF, "if",
|
1958
1993
|
:kTRUE, "true",
|
@@ -1961,9 +1996,9 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1961
1996
|
:kEND, "end")
|
1962
1997
|
end
|
1963
1998
|
|
1964
|
-
def
|
1999
|
+
def test_static_env
|
1965
2000
|
env = Parser::StaticEnvironment.new
|
1966
|
-
env.declare
|
2001
|
+
env.declare "a"
|
1967
2002
|
|
1968
2003
|
@lex.static_env = env
|
1969
2004
|
|
@@ -1973,4 +2008,213 @@ class TestLexer < MiniTest::Unit::TestCase
|
|
1973
2008
|
:tINTEGER, 42,
|
1974
2009
|
:tRBRACK, "]")
|
1975
2010
|
end
|
2011
|
+
|
2012
|
+
#
|
2013
|
+
# Tests for bugs.
|
2014
|
+
#
|
2015
|
+
# These tests should be moved from nursery and properly
|
2016
|
+
# categorized when it's clear how to do that.
|
2017
|
+
#
|
2018
|
+
|
2019
|
+
def test_bug_sclass_joined
|
2020
|
+
util_lex_token("class<<self",
|
2021
|
+
:kCLASS, "class",
|
2022
|
+
:tLSHFT, "<<",
|
2023
|
+
:kSELF, "self")
|
2024
|
+
end
|
2025
|
+
|
2026
|
+
def test_bug_expr_beg_div
|
2027
|
+
@lex.state = :expr_beg
|
2028
|
+
util_lex_token("/=/",
|
2029
|
+
:tREGEXP_BEG, "/",
|
2030
|
+
:tSTRING_CONTENT, "=",
|
2031
|
+
:tSTRING_END, "/",
|
2032
|
+
:tREGEXP_OPT, "")
|
2033
|
+
|
2034
|
+
@lex.state = :expr_beg
|
2035
|
+
util_lex_token("/ = /",
|
2036
|
+
:tREGEXP_BEG, "/",
|
2037
|
+
:tSTRING_CONTENT, " = ",
|
2038
|
+
:tSTRING_END, "/",
|
2039
|
+
:tREGEXP_OPT, "")
|
2040
|
+
end
|
2041
|
+
|
2042
|
+
def test_bug_expr_beg_percent
|
2043
|
+
@lex.state = :expr_beg
|
2044
|
+
util_lex_token("%=foo=",
|
2045
|
+
:tSTRING, "foo")
|
2046
|
+
|
2047
|
+
@lex.state = :expr_beg
|
2048
|
+
util_lex_token("% = ",
|
2049
|
+
:tSTRING, "=")
|
2050
|
+
end
|
2051
|
+
|
2052
|
+
def test_bug_expr_beg_document
|
2053
|
+
@lex.state = :expr_beg
|
2054
|
+
util_lex_token(" \n=begin\n=end\nend",
|
2055
|
+
:kEND, "end")
|
2056
|
+
|
2057
|
+
end
|
2058
|
+
|
2059
|
+
def test_bug_expr_beg_number
|
2060
|
+
@lex.state = :expr_beg
|
2061
|
+
util_lex_token("86400_000_000",
|
2062
|
+
:tINTEGER, 86400000000)
|
2063
|
+
end
|
2064
|
+
|
2065
|
+
def test_bug_expr_beg_backspace_nl
|
2066
|
+
@lex.state = :expr_beg
|
2067
|
+
util_lex_token("\n/foo/",
|
2068
|
+
:tREGEXP_BEG, "/",
|
2069
|
+
:tSTRING_CONTENT, "foo",
|
2070
|
+
:tSTRING_END, "/",
|
2071
|
+
:tREGEXP_OPT, "")
|
2072
|
+
end
|
2073
|
+
|
2074
|
+
def test_bug_expr_arg_percent
|
2075
|
+
@lex.state = :expr_arg
|
2076
|
+
util_lex_token("%[",
|
2077
|
+
:tPERCENT, "%",
|
2078
|
+
:tLBRACK, "[")
|
2079
|
+
|
2080
|
+
@lex.state = :expr_arg
|
2081
|
+
util_lex_token("%=1",
|
2082
|
+
:tOP_ASGN, "%",
|
2083
|
+
:tINTEGER, 1)
|
2084
|
+
|
2085
|
+
@lex.state = :expr_arg
|
2086
|
+
util_lex_token(" %[1]",
|
2087
|
+
:tSTRING, "1")
|
2088
|
+
|
2089
|
+
@lex.state = :expr_arg
|
2090
|
+
util_lex_token(" %=1=",
|
2091
|
+
:tOP_ASGN, "%",
|
2092
|
+
:tINTEGER, 1,
|
2093
|
+
:tEQL, "=")
|
2094
|
+
end
|
2095
|
+
|
2096
|
+
def test_bug_expr_arg_lt_lt
|
2097
|
+
@lex.state = :expr_arg
|
2098
|
+
util_lex_token("<<EOS\nEOS",
|
2099
|
+
:tLSHFT, "<<",
|
2100
|
+
:tCONSTANT, "EOS",
|
2101
|
+
:tNL, nil,
|
2102
|
+
:tCONSTANT, "EOS")
|
2103
|
+
|
2104
|
+
@lex.state = :expr_arg
|
2105
|
+
util_lex_token(" <<EOS\nEOS",
|
2106
|
+
:tSTRING_BEG, "\"",
|
2107
|
+
:tSTRING_END, "EOS",
|
2108
|
+
:tNL, nil)
|
2109
|
+
end
|
2110
|
+
|
2111
|
+
def test_bug_expr_arg_slash
|
2112
|
+
@lex.state = :expr_arg
|
2113
|
+
util_lex_token("/1",
|
2114
|
+
:tDIVIDE, "/",
|
2115
|
+
:tINTEGER, 1)
|
2116
|
+
|
2117
|
+
@lex.state = :expr_arg
|
2118
|
+
util_lex_token("/ 1",
|
2119
|
+
:tDIVIDE, "/",
|
2120
|
+
:tINTEGER, 1)
|
2121
|
+
|
2122
|
+
@lex.state = :expr_arg
|
2123
|
+
util_lex_token(" /1/",
|
2124
|
+
:tREGEXP_BEG, "/",
|
2125
|
+
:tSTRING_CONTENT, "1",
|
2126
|
+
:tSTRING_END, "/",
|
2127
|
+
:tREGEXP_OPT, "")
|
2128
|
+
|
2129
|
+
@lex.state = :expr_arg
|
2130
|
+
util_lex_token(" / 1",
|
2131
|
+
:tDIVIDE, "/",
|
2132
|
+
:tINTEGER, 1)
|
2133
|
+
end
|
2134
|
+
|
2135
|
+
def test_bug_heredoc_continuation
|
2136
|
+
@lex.state = :expr_arg
|
2137
|
+
util_lex_token(" <<EOS\nEOS\nend",
|
2138
|
+
:tSTRING_BEG, "\"",
|
2139
|
+
:tSTRING_END, "EOS",
|
2140
|
+
:tNL, nil,
|
2141
|
+
:kEND, "end")
|
2142
|
+
end
|
2143
|
+
|
2144
|
+
def test_bug_eh_symbol_no_newline
|
2145
|
+
util_lex_token("?\"\nfoo",
|
2146
|
+
:tINTEGER, 34,
|
2147
|
+
:tNL, nil,
|
2148
|
+
:tIDENTIFIER, "foo")
|
2149
|
+
end
|
2150
|
+
|
2151
|
+
def test_bug_expr_arg_newline
|
2152
|
+
@lex.state = :expr_arg
|
2153
|
+
util_lex_token("\nfoo",
|
2154
|
+
:tNL, nil,
|
2155
|
+
:tIDENTIFIER, "foo")
|
2156
|
+
|
2157
|
+
@lex.state = :expr_arg
|
2158
|
+
util_lex_token(" \nfoo",
|
2159
|
+
:tNL, nil,
|
2160
|
+
:tIDENTIFIER, "foo")
|
2161
|
+
|
2162
|
+
@lex.state = :expr_arg
|
2163
|
+
util_lex_token("#foo\nfoo",
|
2164
|
+
:tNL, nil,
|
2165
|
+
:tIDENTIFIER, "foo")
|
2166
|
+
end
|
2167
|
+
|
2168
|
+
def test_bug_heredoc_backspace_nl
|
2169
|
+
util_lex_token(" <<'XXX'\nf \\\nXXX\n",
|
2170
|
+
:tSTRING_BEG, "'",
|
2171
|
+
:tSTRING_CONTENT, "f \\\n",
|
2172
|
+
:tSTRING_END, "XXX",
|
2173
|
+
:tNL, nil)
|
2174
|
+
end
|
2175
|
+
|
2176
|
+
def test_bug_expr_dot_comment
|
2177
|
+
util_lex_token("foo. #bar\nbaz",
|
2178
|
+
:tIDENTIFIER, 'foo',
|
2179
|
+
:tDOT, '.',
|
2180
|
+
:tIDENTIFIER, 'baz')
|
2181
|
+
end
|
2182
|
+
|
2183
|
+
def test_bug_expr_mid_comment
|
2184
|
+
util_lex_token("rescue #bar\nprint",
|
2185
|
+
:kRESCUE, 'rescue',
|
2186
|
+
:tNL, nil,
|
2187
|
+
:tIDENTIFIER, 'print')
|
2188
|
+
end
|
2189
|
+
|
2190
|
+
def test_bug_expr_end_colon
|
2191
|
+
util_lex_token("'foo':'bar'",
|
2192
|
+
:tSTRING, 'foo',
|
2193
|
+
:tCOLON, ':',
|
2194
|
+
:tSTRING, 'bar')
|
2195
|
+
end
|
2196
|
+
|
2197
|
+
def test_bug_symbol_newline
|
2198
|
+
util_lex_token(":foo\n",
|
2199
|
+
:tSYMBOL, 'foo',
|
2200
|
+
:tNL, nil)
|
2201
|
+
|
2202
|
+
util_lex_token(":foo=\n",
|
2203
|
+
:tSYMBOL, 'foo=',
|
2204
|
+
:tNL, nil)
|
2205
|
+
end
|
2206
|
+
|
2207
|
+
def test_bug_ragel_stack
|
2208
|
+
util_lex_token("\"\#{$2 ? $2 : 1}\"",
|
2209
|
+
:tSTRING_BEG, "\"",
|
2210
|
+
:tSTRING_DBEG, "\#{",
|
2211
|
+
:tNTH_REF, 2,
|
2212
|
+
:tEH, "?",
|
2213
|
+
:tNTH_REF, 2,
|
2214
|
+
:tCOLON, ":",
|
2215
|
+
:tINTEGER, 1,
|
2216
|
+
:tRCURLY, "}",
|
2217
|
+
:tSTRING_END, "\"")
|
2218
|
+
end
|
2219
|
+
|
1976
2220
|
end
|