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>
|
Mon Sep 20 03:46:54 2004 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* parse.y [ripper]: spaces before heredoc marker was lost.
|
* parse.y [ripper]: spaces before heredoc marker was lost.
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# test_scanner_events.rb
|
# test_scanner_events.rb
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'ripper.so'
|
require 'ripper'
|
||||||
raise 'ripper version differ' unless Ripper::Version == '0.1.0'
|
raise 'ripper version differ' unless Ripper::Version == '0.1.0'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
|
@ -10,38 +10,26 @@ class TestRipper_ScannerEvents < Test::Unit::TestCase
|
||||||
|
|
||||||
class R < Ripper
|
class R < Ripper
|
||||||
def R.scan(target, src)
|
def R.scan(target, src)
|
||||||
r = new(src, target)
|
new(src, target).parse.map {|id, tok| tok }
|
||||||
r.parse
|
|
||||||
r.tokens.map {|id, tok| tok }
|
|
||||||
end
|
|
||||||
|
|
||||||
def R.lex(src)
|
|
||||||
r = new(src, 'scan')
|
|
||||||
r.parse
|
|
||||||
r.tokens
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(src, target)
|
def initialize(src, target)
|
||||||
super src
|
super src
|
||||||
|
if target
|
||||||
@target = ('on__' + target).intern
|
@target = ('on__' + target).intern
|
||||||
|
else
|
||||||
|
@target = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse
|
||||||
@tokens = []
|
@tokens = []
|
||||||
|
super
|
||||||
|
@tokens
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :tokens
|
def on__scan(type, tok)
|
||||||
|
@tokens.push [type,tok] if !@target or type == @target
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def warn(fmt, *args)
|
def warn(fmt, *args)
|
||||||
|
@ -58,13 +46,17 @@ class TestRipper_ScannerEvents < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_scan
|
def test_scan
|
||||||
assert_equal [],
|
assert_equal [],
|
||||||
R.scan('scan', '')
|
R.scan(nil, '')
|
||||||
assert_equal ['a'],
|
assert_equal ['a'],
|
||||||
R.scan('scan', 'a')
|
R.scan(nil, 'a')
|
||||||
assert_equal ['1'],
|
assert_equal ['1'],
|
||||||
R.scan('scan', '1')
|
R.scan(nil, '1')
|
||||||
assert_equal ['1', ';', 'def', ' ', 'm', '(', 'arg', ')', 'end'],
|
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
|
end
|
||||||
|
|
||||||
def test_backref
|
def test_backref
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue