File: test_seq.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 (51 lines) | stat: -rw-r--r-- 1,157 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
require "#{File.dirname(__FILE__)}/helpers.rb"

class TestSeq < TC
  def test_seq
    p = seq('a', 'b', 'c')
    ase ['a','b','c'], p.parse('abc')
    ase INVALID, p.parse('a')
    ase INVALID, p.parse('b')
    ase INVALID, p.parse('c')
    ase INVALID, p.parse('bc')
    ase INVALID, p.parse('ab')
  end

  def test_seq_
    p = seq_('abc', 'ef', 'vv')
    ase %w[abc ef vv], p.parse("abc    ef vv")
    p = seq_('abc', 'ef', 'vv', skip: /\s+/)
    ase %w[abc ef vv], p.parse("abc    ef vv")
    ase INVALID, p.parse("abcef vv")
  end

  def test_seq_mix
    p = seq('e', seq_('a','b','c'), 'd')
    ase ['e', ['a','b','c'], 'd'], p.parse('eabcd')
  end
  
  def test_seq_one
    p = seq('a', 'b', 'c')[1]
    ase 'b', p.parse('abc')
    p = seq('abc', /\s*/, 'd')[2]
    ase 'd', p.parse('abc d')
  end

  def test_seq_one_
    p = seq_('a', 'b', 'c')[1]
    ase 'b', p.parse('a bc')
    p = seq_('abc', /\s*/, 'd')[2]
    ase 'd', p.parse('abc d')
  end

  def test_fall
    p = 'a'.r >> 'b'
    ase 'b', p.parse!('ab')
    p = p << 'c'
    ase 'b', p.parse!('abc')

    p = p._?
    ase ['b'], p.eof.parse!('abc')
    ase [], p.eof.parse!('')
  end
end