spec/rex_spec.rb in raabro-0.9.0 vs spec/rex_spec.rb in raabro-1.0.0
- old
+ new
@@ -8,34 +8,45 @@
require 'spec_helper'
describe Raabro do
- before :each do
-
- @input = Raabro::Input.new('toto')
- end
-
describe '.rex' do
- it 'returns a tree with result == 0 in case of failure' do
+ it 'hits' do
- t = Raabro.rex(nil, @input, /t[ua]/)
+ 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(@input.offset).to eq(0)
+ expect(i.offset).to eq(0)
end
- it "returns a tree with result == 1 in case of success" do
+ it 'misses' do
- t = Raabro.rex(nil, @input, /(to)+/)
+ 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(@input.offset).to eq(4)
+ 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