mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ripper/test_scanner_events.rb: test spaces before heredoc mark.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0ad4ae91ea
commit
f43e22190c
2 changed files with 27 additions and 30 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Sep 20 04:13:00 2004 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* test/ripper/test_scanner_events.rb: test spaces before heredoc
|
||||
mark.
|
||||
|
||||
Mon Sep 20 03:46:54 2004 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* parse.y [ripper]: spaces before heredoc marker was lost.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# test_scanner_events.rb
|
||||
#
|
||||
|
||||
require 'ripper.so'
|
||||
require 'ripper'
|
||||
raise 'ripper version differ' unless Ripper::Version == '0.1.0'
|
||||
require 'test/unit'
|
||||
|
||||
|
@ -10,38 +10,26 @@ class TestRipper_ScannerEvents < Test::Unit::TestCase
|
|||
|
||||
class R < Ripper
|
||||
def R.scan(target, src)
|
||||
r = new(src, target)
|
||||
r.parse
|
||||
r.tokens.map {|id, tok| tok }
|
||||
end
|
||||
|
||||
def R.lex(src)
|
||||
r = new(src, 'scan')
|
||||
r.parse
|
||||
r.tokens
|
||||
new(src, target).parse.map {|id, tok| tok }
|
||||
end
|
||||
|
||||
def initialize(src, target)
|
||||
super src
|
||||
if target
|
||||
@target = ('on__' + target).intern
|
||||
else
|
||||
@target = nil
|
||||
end
|
||||
end
|
||||
|
||||
def parse
|
||||
@tokens = []
|
||||
super
|
||||
@tokens
|
||||
end
|
||||
|
||||
attr_reader :tokens
|
||||
|
||||
def method_missing(mid, *args)
|
||||
case mid.to_s
|
||||
when /\Aon__scan/
|
||||
if @target == :on__scan
|
||||
@tokens.push args
|
||||
else
|
||||
@tokens.push args if @target == args[0]
|
||||
end
|
||||
when /\Aon__/
|
||||
;
|
||||
else
|
||||
raise NoMethodError, "no such method: #{mid}"
|
||||
end
|
||||
def on__scan(type, tok)
|
||||
@tokens.push [type,tok] if !@target or type == @target
|
||||
end
|
||||
|
||||
def warn(fmt, *args)
|
||||
|
@ -58,13 +46,17 @@ class TestRipper_ScannerEvents < Test::Unit::TestCase
|
|||
|
||||
def test_scan
|
||||
assert_equal [],
|
||||
R.scan('scan', '')
|
||||
R.scan(nil, '')
|
||||
assert_equal ['a'],
|
||||
R.scan('scan', 'a')
|
||||
R.scan(nil, 'a')
|
||||
assert_equal ['1'],
|
||||
R.scan('scan', '1')
|
||||
R.scan(nil, '1')
|
||||
assert_equal ['1', ';', 'def', ' ', 'm', '(', 'arg', ')', 'end'],
|
||||
R.scan('scan', "1;def m(arg)end")
|
||||
R.scan(nil, "1;def m(arg)end")
|
||||
assert_equal ['print', '(', '<<EOS', "heredoc\n", "EOS\n", ')', "\n"],
|
||||
R.scan(nil, "print(<<EOS)\nheredoc\nEOS\n")
|
||||
assert_equal ['print', '(', ' ', '<<EOS', "heredoc\n", "EOS\n", ')', "\n"],
|
||||
R.scan(nil, "print( <<EOS)\nheredoc\nEOS\n")
|
||||
end
|
||||
|
||||
def test_backref
|
||||
|
|
Loading…
Reference in a new issue