spec/dendroid/syntax/choice_spec.rb in dendroid-0.0.7 vs spec/dendroid/syntax/choice_spec.rb in dendroid-0.0.8

- old
+ new

@@ -49,6 +49,20 @@ my_alt2 = Dendroid::Syntax::SymbolSeq.new([foo_symb, minus_symb, expr_symb]) instance = described_class.new(foo_symb, [my_alt1, my_alt2]) expect(instance.nonterminals).to eq([expr_symb, foo_symb]) end end # context + + context 'Errors:' do + it 'fails when initialized with one alternative only' do + err = StandardError + err_msg = 'The choice for `expression` must have at least two alternatives.' + expect { described_class.new(expr_symb, [alt1]) }.to raise_error(err, err_msg) + end + + it 'fails in presence of duplicate rhs' do + err = StandardError + err_msg = 'Duplicate alternatives: expression => NUMBER PLUS NUMBER' + expect { described_class.new(expr_symb, [alt1, alt2, alt1]) }.to raise_error(err, err_msg) + end + end # context end # describe