2014-09-03 07:30:56 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Oga do
|
2015-01-08 22:01:53 +00:00
|
|
|
it 'parses an XML document' do
|
2014-09-16 12:30:46 +00:00
|
|
|
document = described_class.parse_xml('<root>foo</root>')
|
2014-09-03 07:30:56 +00:00
|
|
|
|
2014-09-16 12:30:46 +00:00
|
|
|
document.is_a?(Oga::XML::Document).should == true
|
|
|
|
end
|
|
|
|
|
2015-01-08 22:01:53 +00:00
|
|
|
it 'parses an HTML document' do
|
2014-09-16 12:30:46 +00:00
|
|
|
document = described_class.parse_xml('<html><body></body></html>')
|
|
|
|
|
|
|
|
document.is_a?(Oga::XML::Document).should == true
|
2014-09-03 07:30:56 +00:00
|
|
|
end
|
|
|
|
|
2015-01-08 22:01:53 +00:00
|
|
|
describe 'SAX parsing' do
|
2014-09-16 12:30:46 +00:00
|
|
|
before do
|
|
|
|
klass = Class.new do
|
|
|
|
attr_reader :name
|
|
|
|
|
|
|
|
def on_element(namespace, name, attrs = {})
|
|
|
|
@name = name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@handler = klass.new
|
|
|
|
end
|
|
|
|
|
2015-01-08 22:01:53 +00:00
|
|
|
it 'parses an XML document using the SAX parser' do
|
2014-09-16 12:30:46 +00:00
|
|
|
Oga.sax_parse_xml(@handler, '<foo />')
|
|
|
|
|
|
|
|
@handler.name.should == 'foo'
|
|
|
|
end
|
|
|
|
|
2015-01-08 22:01:53 +00:00
|
|
|
it 'parses an HTML document using the SAX parser' do
|
2015-02-15 21:35:03 +00:00
|
|
|
Oga.sax_parse_html(@handler, '<link>')
|
2014-09-03 07:30:56 +00:00
|
|
|
|
2014-09-16 12:30:46 +00:00
|
|
|
@handler.name.should == 'link'
|
2014-09-03 07:30:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|