File: jseq_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 (83 lines) | stat: -rw-r--r-- 1,894 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

#
# specifying raabro
#
# Mon Sep 21 06:55:35 JST 2015
#

require 'spec_helper'


describe Raabro do

  describe '.jseq' do

    it 'parses elts joined by a separator' do

      i = Raabro::Input.new('a,b,c')

      t = Raabro.jseq(:j, i, :cha, :com)

      expect(t.to_a(:leaves => true)).to eq(
        [ :j, 1, 0, 5, nil, :jseq, [
          [ nil, 1, 0, 1, nil, :rex, 'a' ],
          [ nil, 1, 1, 1, nil, :str, ',' ],
          [ nil, 1, 2, 1, nil, :rex, 'b' ],
          [ nil, 1, 3, 1, nil, :str, ',' ],
          [ nil, 1, 4, 1, nil, :rex, 'c' ],
          [ nil, 0, 5, 0, nil, :str, [] ]
        ] ]
      )
      expect(i.offset).to eq(5)
    end

    it 'prunes' do

      i = Raabro::Input.new('a,b,c', :prune => true)

      t = Raabro.jseq(:j, i, :cha, :com)

      expect(t.to_a(:leaves => true)).to eq(
        [ :j, 1, 0, 5, nil, :jseq, [
          [ nil, 1, 0, 1, nil, :rex, 'a' ],
          [ nil, 1, 1, 1, nil, :str, ',' ],
          [ nil, 1, 2, 1, nil, :rex, 'b' ],
          [ nil, 1, 3, 1, nil, :str, ',' ],
          [ nil, 1, 4, 1, nil, :rex, 'c' ]
        ] ]
      )
      expect(i.offset).to eq(5)
    end

    it 'fails when 0 elements' do

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

      t = Raabro.jseq(:j, i, :cha, :com)

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

    it 'does not include trailing separators' do

      i = Raabro::Input.new('a,b,', :prune => false)

      t = Raabro.jseq(:j, i, :cha, :com)

      expect(t.to_a(:leaves => true)).to eq(
        [:j, 1, 0, 3, nil, :jseq, [
          [nil, 1, 0, 1, nil, :rex, 'a'],
          [nil, 1, 1, 1, nil, :str, ','],
          [nil, 1, 2, 1, nil, :rex, 'b'],
          [nil, 0, 3, 1, nil, :str, []],
          [nil, 0, 4, 0, nil, :rex, []]]]
      )
    end
  end
end