summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-19 19:13:19 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-19 19:13:19 +0000
commitf43e22190c355fc41fd97c70cbf96436d29fefd1 (patch)
treeeb25e5f6c8430202505190fd1b1bfe7fbb76db1b
parent0ad4ae91ea6c9c489946a390b231e90c1bf9eedd (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--test/ripper/test_scanner_events.rb52
2 files changed, 27 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 8451c7cb081..43f507d0409 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 28b65eb1b67..31457c35ba4 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -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
- @target = ('on__' + target).intern
+ 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