File: choice_test.rb

package info (click to toggle)
ruby-citrus 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 420 kB
  • sloc: ruby: 3,417; makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,008 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require File.expand_path('../helper', __FILE__)

class ChoiceTest < Test::Unit::TestCase
  def test_terminal?
    rule = Choice.new
    assert_equal(false, rule.terminal?)
  end

  def test_exec
    a = Rule.for('a')
    b = Rule.for('b')
    rule = Choice.new([ a, b ])

    events = rule.exec(Input.new(''))
    assert_equal([], events)

    events = rule.exec(Input.new('a'))
    assert(events)
    assert_equal([rule, a, CLOSE, 1, CLOSE, 1], events)

    events = rule.exec(Input.new('b'))
    assert(events)
    assert_equal([rule, b, CLOSE, 1, CLOSE, 1], events)
  end

  def test_to_s
    rule = Choice.new(%w<a b>)
    assert_equal('"a" | "b"', rule.to_s)
  end

  def test_to_embedded_s
    rule1 = Choice.new(%w<a b>)
    rule2 = Choice.new(%w<c d>)
    rule = Choice.new([rule1, rule2])
    assert_equal('("a" | "b") | ("c" | "d")', rule.to_s)
  end

  def test_to_s_with_label
    rule = Choice.new(%w<a b>)
    rule.label = 'a_label'
    assert_equal('a_label:("a" | "b")', rule.to_s)
  end
end