require 'test/unit' require 'rockit/grammar' include Rockit require 'strscan' class UTestRegexpTerminal < Test::Unit::TestCase def setup @ret = RegexpTerminal.new(/a/) @retas = RegexpTerminal.new(/a+/) end def test_01_smoke assert_kind_of(RegexpTerminal, @ret) assert_kind_of(GrammarSymbol, @ret) end def test_02_inspect assert_kind_of(String, @ret.inspect) assert_equal("/a/", @ret.inspect) end def test_03_regexp assert_kind_of(Regexp, @ret.regexp) assert_equal(/\s*(a)/, @ret.regexp) assert_equal(/\s*(a+)/, @retas.regexp) end def test_04_scan s = StringScanner.new("a") assert_equal("a", @ret.scan(s)) assert_equal(1, s.pos) s = StringScanner.new("b") assert_equal(nil, @ret.scan(s)) assert_equal(0, s.pos) end def test_05_dont_scan_over_whitespace s = StringScanner.new("a b") assert_equal("a", @ret.scan(s)) assert_equal(1, s.pos) end end