Sha256: b893d124afc88aafa7d700140f49cac329f304d3045b6c23c71d46bc5a155e37
Contents?: true
Size: 1.17 KB
Versions: 7
Compression:
Stored size: 1.17 KB
Contents
require File.dirname(__FILE__) + '/helper' class SequenceTest < Test::Unit::TestCase def test_terminal? rule = Sequence.new assert_equal(false, rule.terminal?) end def test_match rule = Sequence.new(%w<a b>) match = rule.match(input('')) assert_equal(nil, match) match = rule.match(input('a')) assert_equal(nil, match) match = rule.match(input('ab')) assert(match) assert_equal('ab', match.text) assert_equal(2, match.length) end def test_match_mixed rule = Sequence.new([/\d+/, '+', /\d+/]) match = rule.match(input('1+2')) assert(match) assert_equal('1+2', match.text) assert_equal(3, match.length) end def test_match_embed rule = Sequence.new([/[0-9]+/, Choice.new(%w<+ ->), /\d+/]) match = rule.match(input('1+2')) assert(match) assert_equal('1+2', match.text) assert_equal(3, match.length) end def test_to_s rule = Sequence.new(%w<a b>) assert_equal('"a" "b"', rule.to_s) end def test_to_s_embed rule1 = Sequence.new(%w<a b>) rule2 = Sequence.new(%w<c d>) rule = Sequence.new([rule1, rule2]) assert_equal('("a" "b") ("c" "d")', rule.to_s) end end
Version data entries
7 entries across 7 versions & 1 rubygems