0
@@ -20,8 +20,7 @@ module ChoiceSpec
0
it "upon parsing a string matching the first alternative, returns a Propagation with the result of the first alternative as its result" do
0
+ result = parse('foo', :return_propagations => true)
0
result.should be_an_instance_of(Runtime::Propagation)
0
result.element.should be_terminal
0
result.element.text_value.should == 'foo'
0
@@ -31,67 +30,98 @@ module ChoiceSpec
0
- @result = parse('bar'
)
0
+ @result = parse('bar'
, :return_propagations => true)
0
describe "the result" do
0
it "is an instance Propagation" do
0
result.should be_an_instance_of(Runtime::Propagation)
0
it "has the result of the second alternative as its #element" do
0
result.element.should be_terminal
0
result.element.text_value.should == 'bar'
0
- it "has the failing result of the first alternative and the successful result of the second alternative as its dependencies" do
0
+ it "has the successful result of the second alternative and the failing result of the first alternative as its dependencies" do
0
dependencies = result.dependencies
0
dependencies.size.should == 2
0
- dependencies[0].should be_an_instance_of(Runtime::TerminalParseFailure)
0
- dependencies[0].expected_string.should == 'foo'
0
- dependencies[1].should == result.element
0
+ dependencies[0].should == result.element
0
+ dependencies[1].should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies[1].expected_string.should == 'foo'
0
- it "records the failure of the first terminal"
0
- it "upon parsing a string matching the second alternative, records the failure of the first terminal" do
0
- terminal_failures = parser.terminal_failures
0
- terminal_failures.size.should == 1
0
- failure = terminal_failures[0]
0
- failure.expected_string.should == 'foo'
0
- failure.index.should == 0
0
+ it "records the failure of the first terminal" do
0
+ terminal_failures = parser.terminal_failures
0
+ terminal_failures.size.should == 1
0
+ failure = terminal_failures[0]
0
+ failure.expected_string.should == 'foo'
0
+ failure.index.should == 0
0
describe "upon parsing a string matching the third alternative" do
0
+ @result = parse("baz", :return_propagations => true)
0
describe "the result" do
0
- it "is an instance Propagation"
0
- it "has the result of the third alternative as its #result"
0
- it "has the failing results of the first and second alternatives and the successful result of the third alternative as its dependencies"
0
+ it "is an instance Propagation" do
0
+ result.should be_an_instance_of(Runtime::Propagation)
0
+ it "has the result of the third alternative as its #element" do
0
+ result.element.should be_terminal
0
+ result.element.text_value.should == 'baz'
0
+ it "has the successful result of the third alternative and the failing results of the first and second alternatives as its dependencies" do
0
+ dependencies = result.dependencies
0
+ dependencies.size.should == 3
0
+ dependencies[0].should == result.element
0
+ dependencies[1].should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies[1].expected_string.should == 'foo'
0
+ dependencies[2].should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies[2].expected_string.should == 'bar'
0
- it "records the failure of the first terminal and second terminals"
0
+ it "records the failure of the first terminal and second terminals" do
0
+ terminal_failures = parser.terminal_failures
0
+ terminal_failures.size.should == 2
0
+ failure_1 = terminal_failures[0]
0
+ failure_1.expected_string == 'foo'
0
+ failure_1.index.should == 0
0
+ failure_2 = terminal_failures[1]
0
+ failure_2.expected_string == 'bar'
0
+ failure_2.index.should == 0
0
- it "upon parsing a string matching the third alternative, records the failure of the first two terminals" do
0
- terminal_failures = parser.terminal_failures
0
- terminal_failures.size.should == 2
0
- failure_1 = terminal_failures[0]
0
- failure_1.expected_string == 'foo'
0
- failure_1.index.should == 0
0
- failure_2 = terminal_failures[1]
0
- failure_2.expected_string == 'bar'
0
- failure_2.index.should == 0
0
+ describe "the result of parsing non-matching input" do
0
+ @result = parse('cat', :return_parse_failure => true)
0
+ it "is a ParseFailure that depends on the failure of all 3 alternatives" do
0
+ result.should be_an_instance_of(Runtime::ParseFailure)
0
+ dependencies = result.dependencies
0
+ dependencies.size.should == 3
0
+ dependencies[0].should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies[0].expected_string.should == 'foo'
0
+ dependencies[1].should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies[1].expected_string.should == 'bar'
0
+ dependencies[2].should be_an_instance_of(Runtime::TerminalParseFailure)
0
+ dependencies[2].expected_string.should == 'baz'
0
@@ -109,7 +139,7 @@ module ChoiceSpec
0
it "extends a match of any of its subexpressions with a module created from the block" do
0
['a', 'b', 'c'].each do |letter|
0
- parse(letter).
should respond_to(:a_method)
0
+ parse(letter).
element.should respond_to(:a_method)
0
@@ -124,7 +154,7 @@ module ChoiceSpec
0
it "extends a match of any of its subexpressions with a module created from the block" do
0
['a', 'b', 'c'].each do |letter|
0
- parse(letter).
should respond_to(:a_method)
0
+ parse(letter).
element.should respond_to(:a_method)
Comments
No one has commented yet.