require 'test/unit'
require 'vooly'
class Rectangle < Struct.new(:x, :y, :w, :h)
end
class Point < Struct.new(:x, :y)
def initialize(string)
super *string.split.map { |s| Integer(s) }
end
end
class VoolyTest < Test::Unit::TestCase
DOCUMENT = <>
<< ho >>
>>
>>
EOF
HTML = <
Business as usual.
EOF def test_parse pull = Vooly::Pull.new(DOCUMENT) [ [nil, nil], [:text, "A test of Vooly:\n"], [:open, "html"], [:text, "bar quux "], [:open, "em"], [:text, "yeah"], [:close, nil], [:open, "ul"], [:open, nil], [:text, "hey"], [:close, nil], [:open, nil], [:text, "ho"], [:close, nil], [:close, nil], [:close, nil], [nil, nil] ].each { |state, text| assert_equal [state, text], [pull.state, pull.text] pull.next } end def test_parse_with_whitespace_strip pull = Vooly::Pull.new(DOCUMENT, true) [ [nil, nil], [:text, "A test of Vooly:"], [:open, "html"], [:text, "bar quux"], [:open, "em"], [:text, "yeah"], [:close, nil], [:open, "ul"], [:open, nil], [:text, "hey"], [:close, nil], [:open, nil], [:text, "ho"], [:close, nil], [:close, nil], [:close, nil], [nil, nil] ].each { |state, text| assert_equal [state, text], [pull.state, pull.text] pull.next } end def test_parse_with_whitespace pull = Vooly::Pull.new(DOCUMENT, nil) [ [nil, nil], [:text, "A test of Vooly:\n"], [:open, "html"], [:text, " bar quux "], [:open, "em"], [:text, " yeah"], [:close, nil], [:text, "\n "], [:open, "ul"], [:text, "\n "], [:open, nil], [:text, " hey "], [:close, nil], [:text, "\n "], [:open, nil], [:text, " ho "], [:close, nil], [:text, "\n "], [:close, nil], [:text, "\n"], [:close, nil], [:text, "\n"], [nil, nil] ].each { |state, text| assert_equal [state, text], [pull.state, pull.text] pull.next } end def test_parse_and_html pull = Vooly::Pull.new(HTML) assert_equal [nil, nil], [pull.state, pull.text] [ [:text, "\nThis is just plain, "], [:open, "em"], [:text, "stupid"], [:close, nil], [:text, " HTML.\n
\n\nBusiness as usual.\n
\n"], ].each { |state, text| assert_equal true, pull.next assert_equal [state, text], [pull.state, pull.text] } assert_equal false, pull.next assert_equal [nil, nil], [pull.state, pull.text] end def test_slurp assert_equal [ "A test of Vooly:", Vooly::TaggedArray.new("html", "bar quux", Vooly::TaggedArray.new("em", "yeah"), Vooly::TaggedArray.new("ul", ["hey"], ["ho"])) ], Vooly::Slurp.new(DOCUMENT, true).slurp end def test_slurp_with_whitespace assert_equal [ "A test of Vooly:\n", Vooly::TaggedArray.new("html", " bar quux ", Vooly::TaggedArray.new("em", " yeah"), "\n ", Vooly::TaggedArray.new("ul", "\n ", [" hey "], "\n ", [" ho "], "\n "), "\n"), "\n", ], Vooly::Slurp.new(DOCUMENT, nil).slurp end def test_slurp_with_mapping s = <