File: rex_spec.rb

package info (click to toggle)
ruby-raabro 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 220 kB
  • sloc: ruby: 1,682; makefile: 32
file content (52 lines) | stat: -rw-r--r-- 862 bytes parent folder | download
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

#
# specifying raabro
#
# Sun Sep 20 07:12:35 JST 2015
#

require 'spec_helper'


describe Raabro do

  describe '.rex' do

    it 'hits' do

      i = Raabro::Input.new('toto')

      t = Raabro.rex(nil, i, /t[ua]/)

      expect(t.to_a).to eq(
        [ nil, 0, 0, 0, nil, :rex, [] ]
      )
      expect(i.offset).to eq(0)
    end

    it 'misses' do

      i = Raabro::Input.new('toto')

      t = Raabro.rex(nil, i, /(to)+/)

      expect(t.to_a(:leaves => true)).to eq(
        [ nil, 1, 0, 4, nil, :rex, 'toto' ]
      )
      expect(i.offset).to eq(4)
    end

    it 'misses if the match is not at the current input offset' do

      i = Raabro::Input.new('tato')

      t = Raabro.rex(:biga, i, /(to)+/)

      expect(t.to_a(:leaves => true)).to eq(
        [ :biga, 0, 0, 0, nil, :rex, [] ]
      )
      expect(i.offset).to eq(0)
    end
  end
end