Projects

Ticket #749: test.rb

File test.rb, 0.9 KB (added by kitchen.andy@…, 2 years ago)

Unit test that exhibits the problem, run with MRI for correct output.

Line 
1require 'strscan'
2require "test/unit"
3
4class TestStringScanner < Test::Unit::TestCase
5  def test_lookahead
6    match = []
7    ss = StringScanner.new($str)
8   
9    while ss.skip_until(/class(?![^ \n])|def(?![^ \n])|end(?![^ \n])|if(?![^ \n])|then(?![^ \n])|else(?![^ \n])/)
10    # while ss.skip_until(/(class|def|end|if|then|else)(?![^ \n])/)
11                        a = ss.pos - ss.matched_size
12                        b = ss.matched_size
13
14      warn "[#{a}, #{b}] = \"#{ss.matched}\""
15      x = [a,b,ss.matched]
16                        match << x
17                end
18               
19    assert_equal(match[0], [0, 5, "class"])
20    assert_equal(match[1], [120, 3, "def"])
21  end
22 
23end
24
25$str = <<EOT
26class PrintProxy
27  # instance_methods.each {
28  #   |m| undef_method m unless m =~ /(^__|^send$|^object_id$)/
29  # }
30 
31  def initialize(obj, &block)
32    @obj = obj
33  end
34
35  protected
36
37  def method_missing(symbol, *args, &block)
38    print "foo"
39    if @block then print "foo\n" else print "\n" end
40   
41    @obj.send(symbol, *args, &block)
42  end
43end
44EOT