#!/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 = "Test

Paragraph one.

Paragraph two.

" assert_html str, str assert_html "

Paragraph one.

Paragraph two.

", str do |doc| (doc/:head).remove (doc/:div).set('id', 'all') (doc/:p).wrap('
') end end def test_files assert_roundtrip TestFiles::BASIC assert_roundtrip TestFiles::BOINGBOING assert_roundtrip TestFiles::CY0 end end