#!/usr/bin/env ruby require 'test/unit' require 'hpricot' require 'load_files' class TestPreserved < Test::Unit::TestCase def assert_roundtrip str doc = Hpricot(str) yield doc if block_given? str2 = doc.to_original_html [*str].zip([*str2]).each do |s1, s2| assert_equal s1, s2 end end def assert_html str1, str2 doc = Hpricot(str2) yield doc if block_given? assert_equal str1, doc.to_original_html end def test_simple str = "
Hpricot is a you know uh fine thing.
" assert_html str, str assert_html "Hpricot is a you know uh fine thing.
", str do |doc| (doc/:p).set('class', 'new') end end def test_parent str = "Paragraph one.
Paragraph two.
Paragraph one.
Paragraph two.