describe UnderOs::Parser::HTML do
def parse(src)
@parser ||= UnderOs::Parser::HTML.new
@parser.parse(src)
end
it "should parse simple tags" do
parse(%Q{
asdf
}).should == [{
tag: 'page',
text: 'asdf',
attrs: {}
}]
end
it "should parse tag attributes" do
parse(%Q{
}).should == [{
tag: 'page',
attrs: {
title: "My Page",
id: "my-page"
}
}]
end
it "should parse tad data-attributes" do
parse(%Q{
}).should == [{
tag: 'view',
attrs: {
data: {
one: '1',
two: '2',
three: true,
fourAndHalf: 'four/2'
}
}
}]
end
it "should process nested views" do
parse(%Q{
}).should == [{
tag: "page", attrs: {}, children: [
{tag: "view", attrs: {id: "my-view"}, children: [
{tag: "view", attrs: {class: "my-view"}}
]}
]
}]
end
it "should handle terminal nodes correctly" do
parse(%Q{
}).should == [{
tag: "page", attrs: {}, children: [
{tag: "img", attrs: {src: "my-image.jpg"}},
{tag: "button", attrs: {}, text: "Boo Hoo"}
]
}]
end
it "should handle same tags correctly" do
parse(%Q{
}).should == [{
tag: "view", attrs: {id: "level1"}, children: [
{tag: "view", attrs: {id: "level2"}, children: [
{tag: "button", attrs: {}, text: "A"},
{tag: "button", attrs: {}, text: "B"},
{tag: "view", attrs: {id: "level3"}, children: [
{tag: "img", attrs: {src: "test.png"}}
]},
{tag: "view", attrs: {id: "level4"}, children: [
{tag: "icon", attrs: {type: "ok"}},
{tag: "label", attrs: {}, text: "A"},
{tag: "label", attrs: {}, text: "B"}
]}
]}
]}
]
end
it "should handle multiple single tags correctly" do
parse(%Q{