Sha256: 2ea1defad30ba47e097c8a64cfd251e38d95e079ab3a52cbce8a6da97a7b6bbe
Contents?: true
Size: 1.91 KB
Versions: 6
Compression:
Stored size: 1.91 KB
Contents
require File.dirname(__FILE__) + '/helper' class MatchTest < Test::Unit::TestCase Double = Grammar.new { include MatchTest::TestGrammar root :double rule :double do one_or_more(:num) end } Sentence = Grammar.new { include MatchTest::TestGrammar root :sentence rule :word do one_or_more(:alpha) end rule :sentence do [ :word, zero_or_more([ ' ', :word ]) ] end } def test_string match = Match.new('hello') assert_equal('hello', match.text) assert_equal(5, match.length) end def test_array_string match1 = Match.new('a') match2 = Match.new('b') match = Match.new([match1, match2]) assert_equal('ab', match.text) assert_equal(2, match.length) end def test_match_data match = Match.new('hello world'.match(/^(\w+) /)) assert_equal('hello ', match.text) assert_equal(6, match.length) end def test_array_match_data match1 = Match.new('hello') match2 = Match.new(' world'.match(/.+/)) match = Match.new([match1, match2]) assert_equal('hello world', match.text) assert_equal(11, match.length) end def test_equality match1 = Match.new('a') match2 = Match.new('a') assert(match1 == 'a') assert(match1 == match2) assert(match2 == match1) match3 = Match.new('b') assert_equal(false, match1 == match3) assert_equal(false, match3 == match1) end def test_matches match = Double.parse('123') assert(match) assert_equal(3, match.matches.length) assert_equal(3, match.find(:num).length) end def test_match match = Double.parse('456') assert(match) assert_equal(3, match.matches.length) num = match.first(:num) assert(num) assert_equal('4', num.text) assert_equal(4, num.value) end def test_matches_deep match = Sentence.parse('one two three four') assert(match) assert_equal(15, match.find(:alpha).length) end end
Version data entries
6 entries across 6 versions & 1 rubygems