test/match_test.rb in citrus-2.4.1 vs test/match_test.rb in citrus-2.5.0

- old
+ new

@@ -18,10 +18,27 @@ match2 = Match.new('b') assert_equal(false, match1 == match2) assert_equal(false, match2 == match1) end + def test_source + match1 = Match.new('abcdef') + assert_equal 'abcdef', match1.source + + path = Struct.new(:to_path).new(__FILE__) + match2 = Match.new(Input.new(path)) + assert_equal path, match2.source + end + + def test_string + match1 = Match.new('abcdef') + assert_equal 'abcdef', match1.string + + match2 = Match.new('abcdef', [Rule.for('bcd'), -1, 3], 1) + assert_equal 'bcd', match2.string + end + def test_matches a = Rule.for('a') b = Rule.for('b') c = Rule.for('c') s = Rule.for([ a, b, c ]) @@ -57,14 +74,21 @@ b, CLOSE, 1, c, CLOSE, 1, CLOSE, 3 ] - match.matches.each do |m| + match.matches.each_with_index do |m, i| assert_equal(sub_events, m.events) + assert_equal(i*3, m.offset) + assert_equal(3, m.length) + assert_equal("abc", m.string) assert_equal("abc", m) assert(m.matches) assert_equal(3, m.matches.length) + m.matches.each_with_index do |m2,i2| + assert_equal(i*3+i2, m2.offset) + assert_equal(1, m2.length) + end end end grammar :Addition do rule :additive do