test/input_test.rb in citrus-2.2.2 vs test/input_test.rb in citrus-2.3.0
- old
+ new
@@ -1,12 +1,11 @@
require File.expand_path('../helper', __FILE__)
class InputTest < Test::Unit::TestCase
def test_memoized?
- input = Input.new('')
- input.memoize!
- assert(input.memoized?)
+ assert !Input.new('').memoized?
+ assert MemoizingInput.new('').memoized?
end
def test_offsets_new
input = Input.new("abc\ndef\nghi")
assert_equal(0, input.line_offset)
@@ -23,79 +22,79 @@
assert_equal(2, input.line_number)
assert_equal("def\n", input.line)
end
def test_events
- a = Rule.new('a')
- b = Rule.new('b')
- c = Rule.new('c')
- s = Rule.new([ a, b, c ])
+ a = Rule.for('a')
+ b = Rule.for('b')
+ c = Rule.for('c')
+ s = Rule.for([ a, b, c ])
r = Repeat.new(s, 0, Infinity)
input = Input.new("abcabcabc")
events = input.exec(r)
expected_events = [
- r.id,
- s.id,
- a.id, CLOSE, 1,
- b.id, CLOSE, 1,
- c.id, CLOSE, 1,
+ r,
+ s,
+ a, CLOSE, 1,
+ b, CLOSE, 1,
+ c, CLOSE, 1,
CLOSE, 3,
- s.id,
- a.id, CLOSE, 1,
- b.id, CLOSE, 1,
- c.id, CLOSE, 1,
+ s,
+ a, CLOSE, 1,
+ b, CLOSE, 1,
+ c, CLOSE, 1,
CLOSE, 3,
- s.id,
- a.id, CLOSE, 1,
- b.id, CLOSE, 1,
- c.id, CLOSE, 1,
+ s,
+ a, CLOSE, 1,
+ b, CLOSE, 1,
+ c, CLOSE, 1,
CLOSE, 3,
CLOSE, 9
]
assert_equal(expected_events, events)
end
def test_events2
- a = Rule.new('a')
- b = Rule.new('b')
+ a = Rule.for('a')
+ b = Rule.for('b')
c = Choice.new([ a, b ])
r = Repeat.new(c, 0, Infinity)
- s = Rule.new([ a, r ])
+ s = Rule.for([ a, r ])
input = Input.new('abbababba')
events = input.exec(s)
expected_events = [
- s.id,
- a.id, CLOSE, 1,
- r.id,
- c.id,
- b.id, CLOSE, 1,
+ s,
+ a, CLOSE, 1,
+ r,
+ c,
+ b, CLOSE, 1,
CLOSE, 1,
- c.id,
- b.id, CLOSE, 1,
+ c,
+ b, CLOSE, 1,
CLOSE, 1,
- c.id,
- a.id, CLOSE, 1,
+ c,
+ a, CLOSE, 1,
CLOSE, 1,
- c.id,
- b.id, CLOSE, 1,
+ c,
+ b, CLOSE, 1,
CLOSE, 1,
- c.id,
- a.id, CLOSE, 1,
+ c,
+ a, CLOSE, 1,
CLOSE, 1,
- c.id,
- b.id, CLOSE, 1,
+ c,
+ b, CLOSE, 1,
CLOSE, 1,
- c.id,
- b.id, CLOSE, 1,
+ c,
+ b, CLOSE, 1,
CLOSE, 1,
- c.id,
- a.id, CLOSE, 1,
+ c,
+ a, CLOSE, 1,
CLOSE, 1,
CLOSE, 8,
CLOSE, 9
]
@@ -119,25 +118,22 @@
"a"
end
end
def test_cache_hits1
- input = Input.new('a')
- input.memoize!
+ input = MemoizingInput.new('a')
input.exec(LetterA.rule(:top))
assert_equal(3, input.cache_hits)
end
def test_cache_hits2
- input = Input.new('aa')
- input.memoize!
+ input = MemoizingInput.new('aa')
input.exec(LetterA.rule(:top))
assert_equal(2, input.cache_hits)
end
def test_cache_hits3
- input = Input.new('aaa')
- input.memoize!
+ input = MemoizingInput.new('aaa')
input.exec(LetterA.rule(:top))
assert_equal(0, input.cache_hits)
end
grammar :Addition do