spec/wml_shared_examples.rb in weskit-0.2.1 vs spec/wml_shared_examples.rb in weskit-0.3.0

- old
+ new

@@ -41,10 +41,53 @@ container[:foo].should match_value_of(:bar) container[0].should have_same_representation_as(element) end end +shared_examples_for 'basic parser' do + context 'ignores' do + specify 'directives' do + data = <<-DOC + {~/path/to.cfg} + #undef SOME_STUFF + DOC + + parsed = Weskit::WML::Parser.string data, parser + parsed.should be_nil + end + + specify 'blank lines' do + parsed = Weskit::WML::Parser.string document_with_empty_lines, parser + parsed.should_not be_nil + end + end + + context 'attribute' do + specify 'raw' do + parsed = Weskit::WML::Parser.string 'a=b', parser + parsed[:a].should match_value_of(:b) + end + + specify 'escape sequence' do + parsed = Weskit::WML::Parser.string %Q{ a= "b "" c" }, parser + parsed[:a].should match_value_of('b " c') + end + end + + context 'element' do + specify 'default' do + parsed = Weskit::WML::Parser.string "[foo]\n[/foo]", parser + parsed[0].should have_identifier_of(:foo) + end + + specify 'amending' do + parsed = Weskit::WML::Parser.string document_with_amendment, parser + parsed[0][:bat].should match_value_of(:baz) + end + end +end + shared_examples_for 'a searchable' do specify 'append amending elements' do searchable << Weskit::WML::Element.new(:bar) searchable << sample_amendment @@ -63,6 +106,49 @@ searchable.find_recursively do |item| item.name == :b end.size.should eq(2) end -end \ No newline at end of file +end + +shared_examples_for 'basic parser' do + context 'ignores' do + specify 'directives' do + data = <<-DOC + {~/path/to.cfg} + #undef SOME_STUFF + DOC + + parsed = Weskit::WML::Parser.string data, parser + parsed.should be_nil + end + + specify 'blank lines' do + parsed = Weskit::WML::Parser.string document_with_empty_lines, parser + parsed.should_not be_nil + end + end + + context 'attribute' do + specify 'raw' do + parsed = Weskit::WML::Parser.string 'a=b', parser + parsed[:a].should match_value_of(:b) + end + + specify 'escape sequence' do + parsed = Weskit::WML::Parser.string %Q{ a= "b "" c" }, parser + parsed[:a].should match_value_of('b " c') + end + end + + context 'element' do + specify 'default' do + parsed = Weskit::WML::Parser.string "[foo]\n[/foo]", parser + parsed[0].should have_identifier_of(:foo) + end + + specify 'amending' do + parsed = Weskit::WML::Parser.string document_with_amendment, parser + parsed[0][:bat].should match_value_of(:baz) + end + end +end