File: test_one_of.rb

package info (click to toggle)
ruby-rsec 0.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 272 kB
  • sloc: ruby: 2,130; lisp: 13; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 782 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
require "#{File.dirname(__FILE__)}/helpers.rb"

class TestOneOf < TC
  def test_one_of
    p = one_of('abcd')
    ase 'c', p.parse('c')
    ase INVALID, p.parse('e')
    p = one_of('+=')
    ase '=', p.parse('=')

    begin
      p = one_of('')
      assert false, "should raise exception for empty string"
    rescue
    end

    # with map block
    p = one_of('x+'){|v| v * 2}
    ase '++', p.parse('+')
  end

  def test_one_of_
    p = one_of_('abcd')
    ase 'a', p.parse('a')
    ase INVALID, p.parse('e')
    ase 'd', p.parse(' d ')
    ase 'a', p.parse(' a')
    ase 'c', p.parse('c ')

    assert_raise(ArgumentError) {
      p = one_of_('')
    }

    # with map block
    p = one_of_('w'){'v'}
    ase 'v', p.parse('w')
  end

end