#!/usr/bin/env rspec # Copyright, 2015, by Samuel G. D. Williams. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require 'utopia/content/markup' module Utopia::Content::MarkupSpec class TestDelegate def initialize @events = [] end attr :events def method_missing(*args) @events << args end end describe Utopia::Content::Markup do it "should format open tags correctly" do foo_tag = Utopia::Content::Tag.new("foo", bar: nil, baz: 'bob') expect(foo_tag[:bar]).to be nil expect(foo_tag[:baz]).to be == 'bob' expect(foo_tag.to_s('content')).to be == 'content' end def parse(string) delegate = TestDelegate.new buffer = Trenni::Buffer.new(string) Utopia::Content::Markup.new(buffer, delegate).parse! return delegate end it "should parse single tag" do delegate = parse %Q{} foo_tag = Utopia::Content::Tag.new("foo") expected_events = [ [:tag_begin, foo_tag], [:tag_end, foo_tag], ] expect(delegate.events).to be == expected_events expect(foo_tag.to_s) end it "should parse and escape text" do delegate = parse %Q{Bob & Barley} foo_tag = Utopia::Content::Tag.new("foo") expected_events = [ [:tag_begin, foo_tag], [:cdata, "Bob & Barley"], [:cdata, ""], [:cdata, ""], [:tag_end, foo_tag], ] expect(delegate.events).to be == expected_events end it "should fail with incorrect closing tag" do expect{parse %Q{

Foobar}}.to raise_exception(Utopia::Content::Markup::UnbalancedTagError) end it "should fail with unclosed tag" do expect{parse %Q{

Foobar}}.to raise_exception(Utopia::Content::Markup::UnbalancedTagError) end end end