Sha256: 57b3da085b05ec3586b30e7a0605b35672d2e85a48c8b3e21a02587d1e31791f

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rockit-0.7.1 tests/unit/rockit/utest_regexp_terminal.rb