2004-09-12 13:34:30 -04:00
|
|
|
#
|
|
|
|
# test_scanner_events.rb
|
|
|
|
#
|
|
|
|
|
2004-09-19 15:13:19 -04:00
|
|
|
require 'ripper'
|
2004-09-12 13:34:30 -04:00
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
class TestRipper_ScannerEvents < Test::Unit::TestCase
|
|
|
|
|
2005-09-22 16:58:10 -04:00
|
|
|
def test_event_coverage
|
|
|
|
dispatched = Ripper::SCANNER_EVENTS.map {|event,_| event }
|
|
|
|
dispatched.each do |e|
|
|
|
|
assert_equal true, respond_to?("test_#{e}", true), "event not tested: #{e}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-09-23 06:49:11 -04:00
|
|
|
def scan(target, str)
|
2004-10-09 14:20:46 -04:00
|
|
|
sym = "on_#{target}".intern
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex(str).select {|_,type,_| type == sym }.map {|_,_,tok| tok }
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
2004-10-09 14:20:46 -04:00
|
|
|
def test_tokenize
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-10-09 14:20:46 -04:00
|
|
|
Ripper.tokenize('')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['a'],
|
2004-10-09 14:20:46 -04:00
|
|
|
Ripper.tokenize('a')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1'],
|
2004-10-09 14:20:46 -04:00
|
|
|
Ripper.tokenize('1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1', ';', 'def', ' ', 'm', '(', 'arg', ')', 'end'],
|
2004-10-09 14:20:46 -04:00
|
|
|
Ripper.tokenize("1;def m(arg)end")
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal ['print', '(', '<<EOS', ')', "\n", "heredoc\n", "EOS\n"],
|
2004-10-09 14:20:46 -04:00
|
|
|
Ripper.tokenize("print(<<EOS)\nheredoc\nEOS\n")
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal ['print', '(', ' ', '<<EOS', ')', "\n", "heredoc\n", "EOS\n"],
|
2004-10-09 14:20:46 -04:00
|
|
|
Ripper.tokenize("print( <<EOS)\nheredoc\nEOS\n")
|
|
|
|
assert_equal ["\#\n", "\n", "\#\n", "\n", "nil", "\n"],
|
|
|
|
Ripper.tokenize("\#\n\n\#\n\nnil\n")
|
|
|
|
end
|
|
|
|
|
2005-02-04 12:25:09 -05:00
|
|
|
def test_lex
|
2004-10-09 14:20:46 -04:00
|
|
|
assert_equal [],
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex('')
|
2004-10-09 14:20:46 -04:00
|
|
|
assert_equal [[[1,0], :on_ident, "a"]],
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex('a')
|
2004-10-09 14:20:46 -04:00
|
|
|
assert_equal [[[1, 0], :on_kw, "nil"]],
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex("nil")
|
2004-10-09 14:20:46 -04:00
|
|
|
assert_equal [[[1, 0], :on_kw, "def"],
|
|
|
|
[[1, 3], :on_sp, " "],
|
|
|
|
[[1, 4], :on_ident, "m"],
|
|
|
|
[[1, 5], :on_lparen, "("],
|
|
|
|
[[1, 6], :on_ident, "a"],
|
|
|
|
[[1, 7], :on_rparen, ")"],
|
|
|
|
[[1, 8], :on_kw, "end"]],
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex("def m(a)end")
|
2004-10-09 14:20:46 -04:00
|
|
|
assert_equal [[[1, 0], :on_int, "1"],
|
|
|
|
[[1, 1], :on_nl, "\n"],
|
|
|
|
[[2, 0], :on_int, "2"],
|
|
|
|
[[2, 1], :on_nl, "\n"],
|
|
|
|
[[3, 0], :on_int, "3"]],
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex("1\n2\n3")
|
2004-10-09 14:20:46 -04:00
|
|
|
assert_equal [[[1, 0], :on_heredoc_beg, "<<EOS"],
|
|
|
|
[[1, 5], :on_nl, "\n"],
|
|
|
|
[[2, 0], :on_tstring_content, "heredoc\n"],
|
|
|
|
[[3, 0], :on_heredoc_end, "EOS"]],
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex("<<EOS\nheredoc\nEOS")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
2004-09-20 02:14:09 -04:00
|
|
|
def test_location
|
|
|
|
validate_location ""
|
|
|
|
validate_location " "
|
|
|
|
validate_location "@"
|
|
|
|
validate_location "\n"
|
|
|
|
validate_location "\r\n"
|
|
|
|
validate_location "\n\n\n\n\n\r\n\n\n"
|
|
|
|
validate_location "\n;\n;\n;\n;\n"
|
|
|
|
validate_location "nil"
|
|
|
|
validate_location "@ivar"
|
|
|
|
validate_location "1;2;3"
|
|
|
|
validate_location "1\n2\n3"
|
|
|
|
validate_location "1\n2\n3\n"
|
|
|
|
validate_location "def m(a) nil end"
|
|
|
|
validate_location "if true then false else nil end"
|
|
|
|
validate_location "BEGIN{print nil}"
|
|
|
|
validate_location "%w(a b\nc\r\nd \ne )"
|
|
|
|
validate_location %Q["a\nb\r\nc"]
|
|
|
|
validate_location "print(<<EOS)\nheredoc\nEOS\n"
|
|
|
|
validate_location %Q[print(<<-"EOS")\nheredoc\n EOS\n]
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_location(src)
|
|
|
|
buf = ''
|
2005-02-04 12:25:09 -05:00
|
|
|
Ripper.lex(src).each do |pos, type, tok|
|
2004-09-23 06:49:11 -04:00
|
|
|
line, col = *pos
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal buf.count("\n") + 1, line,
|
|
|
|
"wrong lineno: #{tok.inspect} (#{type}) [#{line}:#{col}]"
|
|
|
|
assert_equal buf.sub(/\A.*\n/m, '').size, col,
|
|
|
|
"wrong column: #{tok.inspect} (#{type}) [#{line}:#{col}]"
|
|
|
|
buf << tok
|
|
|
|
end
|
|
|
|
assert_equal src, buf
|
|
|
|
end
|
|
|
|
|
2004-09-12 13:34:30 -04:00
|
|
|
def test_backref
|
|
|
|
assert_equal ["$`", "$&", "$'", '$1', '$2', '$3'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('backref', %q[m($~, $`, $&, $', $1, $2, $3)])
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_backtick
|
|
|
|
assert_equal ["`"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('backtick', %q[p `make all`])
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_comma
|
|
|
|
assert_equal [','] * 6,
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comma', %q[ m(0,1,2,3,4,5,6) ])
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comma', %q[".,.,.,.,.,.,.."])
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comma', %Q[<<EOS\n,,,,,,,,,,\nEOS])
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_period
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('period', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['.'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('period', 'a.b')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['.'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('period', 'Object.new')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('period', '"."')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('period', '1..2')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('period', '1...3')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_const
|
|
|
|
assert_equal ['CONST'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', 'CONST')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['C'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', 'C')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['CONST_A'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', 'CONST_A')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['Const', 'Const2', 'Const3'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', 'Const; Const2; Const3')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['Const'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', 'Const(a)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['M', 'A', 'A2'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', 'M(A,A2)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('const', 'm(lvar, @ivar, @@cvar, $gvar)')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_cvar
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@@cvar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', '@@cvar')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@@__cvar__'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', '@@__cvar__')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@@CVAR'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', '@@CVAR')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@@cvar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', ' @@cvar#comment')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@@cvar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', ':@@cvar')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@@cvar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', 'm(lvar, @ivar, @@cvar, $gvar)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('cvar', '"@@cvar"')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_embexpr_beg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_beg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['#{'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_beg', '"#{expr}"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_beg', '%q[#{expr}]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['#{'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_beg', '%Q[#{expr}]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['#{'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_beg', "m(<<EOS)\n\#{expr}\nEOS")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_embexpr_end
|
2005-09-22 16:58:10 -04:00
|
|
|
=begin
|
|
|
|
# currently detected as "rbrace"
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_end', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['}'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_end', '"#{expr}"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_end', '%q[#{expr}]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['}'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_end', '%Q[#{expr}]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['}'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embexpr_end', "m(<<EOS)\n\#{expr}\nEOS")
|
2004-09-12 13:34:30 -04:00
|
|
|
=end
|
2005-09-22 16:58:10 -04:00
|
|
|
end
|
2004-09-12 13:34:30 -04:00
|
|
|
|
|
|
|
def test_embvar
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['#'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '"#$gvar"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['#'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '"#@ivar"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['#'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '"#@@cvar"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '"#lvar"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '"#"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '"\#$gvar"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '"\#@ivar"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '%q[#@ivar]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['#'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embvar', '%Q[#@ivar]')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_float
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1.000'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', '1.000')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['123.456'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', '123.456')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1.2345678901234567890123456789'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', '1.2345678901234567890123456789')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1.000'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', ' 1.000# comment')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1.234e5'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', '1.234e5')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1.234e1234567890'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', '1.234e1234567890')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1.0'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('float', 'm(a,b,1.0,c,d)')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gvar
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('gvar', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['$a'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('gvar', '$a')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['$A'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('gvar', '$A')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['$gvar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('gvar', 'm(lvar, @ivar, @@cvar, $gvar)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w($_ $~ $* $$ $? $! $@ $/ $\\ $; $, $. $= $: $< $> $"),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('gvar', 'm($_, $~, $*, $$, $?, $!, $@, $/, $\\, $;, $,, $., $=, $:, $<, $>, $")')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_ident
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ident', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['lvar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ident', 'lvar')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['m', 'lvar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ident', 'm(lvar, @ivar, @@cvar, $gvar)')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_int
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('int', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['1', '10', '100000000000000'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('int', 'm(1,10,100000000000000)')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_ivar
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ivar', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@ivar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ivar', '@ivar')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@__ivar__'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ivar', '@__ivar__')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@IVAR'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ivar', '@IVAR')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['@ivar'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ivar', 'm(lvar, @ivar, @@cvar, $gvar)')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_kw
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(not),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'not 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(and),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '1 and 2')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(or),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '1 or 2')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(if then else end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'if 1 then 2 else 3 end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(if then elsif else end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'if 1 then 2 elsif 3 else 4 end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(unless then end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'unless 1 then end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(if true),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '1 if true')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(unless false),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '2 unless false')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(case when when else end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'case n; when 1; when 2; else 3 end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(while do nil end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'while 1 do nil end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(until do nil end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'until 1 do nil end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(while),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '1 while 2')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(until),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '1 until 2')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(while break next retry end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'while 1; break; next; retry end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(for in next break end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'for x in obj; next 1; break 2 end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(begin rescue retry end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'begin 1; rescue; retry; end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(rescue),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', '1 rescue 2')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(def redo return end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'def m() redo; return end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(def yield yield end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'def m() yield; yield 1 end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(def super super super end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'def m() super; super(); super(1) end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(alias),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'alias a b')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(undef),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'undef public')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(class end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'class A < Object; end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(module end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'module M; end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(class end),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'class << obj; end')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(BEGIN),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'BEGIN { }')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(END),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'END { }')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(self),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'self.class')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(nil true false),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'p(nil, true, false)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(__FILE__ __LINE__),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'p __FILE__, __LINE__')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(defined?),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('kw', 'defined?(Object)')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_lbrace
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbrace', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['{'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbrace', '3.times{ }')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['{'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbrace', '3.times { }')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['{'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbrace', '3.times{}')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbrace', '"{}"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['{'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbrace', '{1=>2}')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rbrace
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbrace', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['}'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbrace', '3.times{ }')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['}'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbrace', '3.times { }')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['}'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbrace', '3.times{}')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbrace', '"{}"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['}'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbrace', '{1=>2}')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_lbracket
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbracket', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['['],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbracket', '[]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['['],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbracket', 'a[1]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lbracket', 'm(%q[])')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rbracket
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbracket', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [']'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbracket', '[]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [']'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbracket', 'a[1]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rbracket', 'm(%q[])')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_lparen
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lparen', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['('],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lparen', '()')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['('],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lparen', 'm()')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['('],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lparen', 'm (a)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lparen', '"()"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('lparen', '"%w()"')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_rparen
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rparen', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [')'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rparen', '()')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [')'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rparen', 'm()')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [')'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rparen', 'm (a)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rparen', '"()"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('rparen', '"%w()"')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_op
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['|'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 | 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['^'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 ^ 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['&'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 & 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<=>'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 <=> 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['=='],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 == 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['==='],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 === 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['=~'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 =~ 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['>'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 > 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['>='],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 >= 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 < 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<='],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 <= 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<<'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 << 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['>>'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 >> 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['+'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 + 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['-'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 - 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['*'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 * 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['/'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 / 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 % 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['**'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '1 ** 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['~'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '~1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['-'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '-a')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['+'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', '+a')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['[]'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', ':[]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['[]='],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', ':[]=')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('op', %q[`make all`])
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_symbeg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('symbeg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [':'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('symbeg', ':sym')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [':'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('symbeg', '[1,2,3,:sym]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('symbeg', '":sym"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('symbeg', 'a ? b : c')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tstring_beg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_beg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['"'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_beg', '"abcdef"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%q['],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_beg', '%q[abcdef]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%Q['],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_beg', '%Q[abcdef]')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tstring_content
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['abcdef'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', '"abcdef"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['abcdef'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', '%q[abcdef]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['abcdef'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', '%Q[abcdef]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['abc', 'def'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', '"abc#{1}def"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['sym'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', ':"sym"')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tstring_end
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_end', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['"'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_end', '"abcdef"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [']'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_end', '%q[abcdef]')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [']'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_end', '%Q[abcdef]')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_regexp_beg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('regexp_beg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['/'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('regexp_beg', '/re/')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%r<'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('regexp_beg', '%r<re>')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('regexp_beg', '5 / 5')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_regexp_end
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('regexp_end', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['/'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('regexp_end', '/re/')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['>'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('regexp_end', '%r<re>')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_words_beg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_beg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%W('],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_beg', '%W()')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%W('],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_beg', '%W(w w w)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%W( '],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_beg', '%W( w w w )')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_qwords_beg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('qwords_beg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%w('],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('qwords_beg', '%w()')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%w('],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('qwords_beg', '%w(w w w)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['%w( '],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('qwords_beg', '%w( w w w )')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# FIXME: Close paren must not present (`words_end' scanner event?).
|
|
|
|
def test_words_sep
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_sep', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [')'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_sep', '%w()')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [' ', ' ', ')'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_sep', '%w(w w w)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [' ', ' ', ' )'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_sep', '%w( w w w )')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["\n", ' ', ' )'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('words_sep', "%w( w\nw w )")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_heredoc_beg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<<EOS'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', "<<EOS\nheredoc\nEOS")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<<EOS'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', "<<EOS\nheredoc\nEOS\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<<EOS'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', "<<EOS\nheredoc\nEOS \n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<<-EOS'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', "<<-EOS\nheredoc\n\tEOS \n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['<<"EOS"'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', %Q[<<"EOS"\nheredoc\nEOS])
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [%q(<<'EOS')],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', "<<'EOS'\nheredoc\nEOS")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [%q(<<`EOS`)],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', "<<`EOS`\nheredoc\nEOS")
|
2004-09-20 01:40:23 -04:00
|
|
|
assert_equal [%q(<<" ")],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_beg', %Q[<<" "\nheredoc\nEOS])
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
2004-09-20 01:40:23 -04:00
|
|
|
def test_tstring_content_HEREDOC
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["heredoc\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', "<<EOS\nheredoc\nEOS")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["heredoc\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', "<<EOS\nheredoc\nEOS\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["heredoc \n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', "<<EOS\nheredoc \nEOS \n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["heredoc\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('tstring_content', "<<-EOS\nheredoc\n\tEOS \n")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_heredoc_end
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_end', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["EOS"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_end', "<<EOS\nheredoc\nEOS")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["EOS\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_end', "<<EOS\nheredoc\nEOS\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["EOS \n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_end', "<<EOS\nheredoc\nEOS \n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["\tEOS \n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('heredoc_end', "<<-EOS\nheredoc\n\tEOS \n")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_semicolon
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('semicolon', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(;),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('semicolon', ';')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(; ;),
|
2005-06-07 23:30:56 -04:00
|
|
|
scan('semicolon', '; ;')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(; ; ;),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('semicolon', 'nil;nil;nil;')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal %w(; ; ;),
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('semicolon', 'nil;nil;nil;nil')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('semicolon', '";"')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('semicolon', '%w(;)')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('semicolon', '/;/')
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_comment
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comment', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ['# comment'],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comment', '# comment')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["# comment\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comment', "# comment\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["# comment\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comment', "# comment\n1 + 1")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["# comment\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('comment', "1 + 1 + 1# comment\n1 + 1")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_embdoc_beg
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc_beg', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["=begin\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc_beg', "=begin\ndoc\n=end")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["=begin \n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc_beg', "=begin \ndoc\n=end\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["=begin comment\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc_beg', "=begin comment\ndoc\n=end\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_embdoc
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["doc\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc', "=begin\ndoc\n=end")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["doc\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc', "=begin\ndoc\n=end\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_embdoc_end
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc_end', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["=end"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc_end', "=begin\ndoc\n=end")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["=end\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('embdoc_end', "=begin\ndoc\n=end\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_sp
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [' '],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', ' ')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [' '],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', ' 1')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', "\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [' '],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', " \n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [' ', ' '],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', "1 + 1")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', "' '")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', "%w( )")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', "%w( w )")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('sp', "p(/ /)")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# `nl' event always means End-Of-Statement.
|
|
|
|
def test_nl
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', "\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', "1 + 1\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["\n", "\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', "1 + 1\n2 + 2\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', "1 +\n1")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', "1;\n")
|
2004-09-19 23:03:12 -04:00
|
|
|
assert_equal ["\r\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', "1 + 1\r\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('nl', "1;\r\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_ignored_nl
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', '')
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', "\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', "1 + 1\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', "1 + 1\n2 + 2\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', "1 +\n1")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', "1;\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', "1 + 1\r\n")
|
2004-09-19 23:03:12 -04:00
|
|
|
assert_equal ["\r\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('ignored_nl', "1;\r\n")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test___end__
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('__end__', "")
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal ["__END__"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('__end__', "__END__")
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal ["__END__\n"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('__end__', "__END__\n")
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal ["__END__\n"],
|
2004-10-09 14:20:46 -04:00
|
|
|
Ripper.tokenize("__END__\njunk junk junk")
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal ["__END__"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('__end__', "1\n__END__")
|
2004-09-20 02:14:09 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('__end__', "print('__END__')")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_CHAR
|
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('CHAR', "")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal ["@"],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('CHAR', "@")
|
2004-09-12 13:34:30 -04:00
|
|
|
assert_equal [],
|
2004-09-23 06:49:11 -04:00
|
|
|
scan('CHAR', "@ivar")
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|
|
|
|
|
2005-09-22 16:58:10 -04:00
|
|
|
def test_label
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_lambda
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_lambeg
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_lambda_arg
|
|
|
|
end
|
|
|
|
|
2004-09-12 13:34:30 -04:00
|
|
|
end
|