require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper")) module Nokogiri module HTML class TestDocument < Nokogiri::TestCase def setup @html = Nokogiri::HTML.parse(File.read(HTML_FILE)) end def test_HTML_function html = Nokogiri::HTML(File.read(HTML_FILE)) assert html.html? end def test_parse_io assert doc = File.open(HTML_FILE, 'rb') { |f| Document.read_io(f, nil, 'UTF-8', PARSE_NOERROR | PARSE_NOWARNING) } end def test_to_xhtml assert_match 'XHTML', @html.to_xhtml assert_match 'XHTML', @html.to_xhtml('UTF-8') assert_match 'UTF-8', @html.to_xhtml('UTF-8') end def test_no_xml_header html = Nokogiri::HTML(<<-eohtml) eohtml assert html.to_html.length > 0, 'html length is too short' assert_no_match(/^<\?xml/, html.to_html) end def test_document_has_error html = Nokogiri::HTML(<<-eohtml)
inside red
inside green
RED
RED
GREEN
GREEN
eohtml list = doc.css('.red') assert_equal 2, list.length assert_equal %w{ RED RED }, list.map { |x| x.text } end def test_parse_can_take_io html = nil File.open(HTML_FILE, 'rb') { |f| html = Nokogiri::HTML(f) } assert html.html? end def test_html? assert !@html.xml? assert @html.html? end def test_serialize assert @html.serialize assert @html.to_html end end end end