File: test_pattern.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 (53 lines) | stat: -rw-r--r-- 991 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
44
45
46
47
48
49
50
51
52
53
require "#{File.dirname(__FILE__)}/helpers.rb"

class TestPattern < TC
  def test_create
    p1 = 'x'.r
    asp 'x', p1
    p1 = 'abc'.r
    asp 'abc', p1
    
    asr do
      p1.eof.parse! 'abcd'
    end
    ase INVALID, p1.eof.parse('abcd')
    
    asr do 
      p1.eof.parse! 'xabc'
    end
    ase INVALID, p1.eof.parse('xabc')

    # with map block
    p = 'x'.r{ 'y' }
    ase INVALID, p.parse('y')
    ase 'y', p.parse('x')
  end

  def test_until
    p = 'ef'.r.until
    asp 'xef', p
    asp "x\nef", p
    
    p = 'e'.r.until
    asp 'xe', p
    asp "x\ne", p

    # with map block
    p = 'e'.r.until{|s| s*2}
    ase 'xexe', p.parse('xe')
  end

  def test_word
    p = word('abc')
    ase INVALID, p.parse('abcd')
    ase INVALID, seq_(p, 'd').parse('abcd')
    ase 'abc', p.parse('abc')
    ase ['abc', 'd'], seq_(p, 'd').parse('abc d')
  end

  def test_symbol
    p = symbol('*')
    ase '*', p.parse(' * ')
  end

end