doctype test
Simon Elliott [Wed, 24 Mar 2010 20:17:33 +0000 (20:17 +0000)]
t/doctype.t [new file with mode: 0644]
t/synopsis.t

diff --git a/t/doctype.t b/t/doctype.t
new file mode 100644 (file)
index 0000000..b0e5e1b
--- /dev/null
@@ -0,0 +1,17 @@
+use strict;
+use warnings FATAL => 'all';
+use Test::More qw(no_plan);
+
+use HTML::Zoom;
+my $template = <<HTML;
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
+<html></html>
+HTML
+
+my $output = HTML::Zoom
+  ->from_html($template)->to_html;
+my $expect = <<HTML;
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
+<html></html>
+HTML
+is($output, $expect, 'Synopsis code works ok');;
index 4089bf9..8a3ac11 100644 (file)
@@ -1,3 +1,71 @@
+use strict;
+use warnings FATAL => 'all';
 use Test::More qw(no_plan);
 
-fail 'You forgot to run maint/synopsis-extract. Go do that.';
+use HTML::Zoom;
+my $template = <<HTML;
+<html>
+  <head>
+    <title>Hello people</title>
+  </head>
+  <body>
+    <h1 id="greeting">Placeholder</h1>
+    <div id="list">
+      <span>
+        <p>Name: <span class="name">Bob</span></p>
+        <p>Age: <span class="age">23</span></p>
+      </span>
+      <hr class="between" />
+    </div>
+  </body>
+</html>
+HTML
+my $output = HTML::Zoom
+  ->from_html($template)
+  ->select('title, #greeting')->replace_content('Hello world & dog!')
+  ->select('#list')->repeat_content(
+      [
+        sub {
+          $_->select('.name')->replace_content('Matt')
+            ->select('.age')->replace_content('26')
+        },
+        sub {
+          $_->select('.name')->replace_content('Mark')
+            ->select('.age')->replace_content('0x29')
+        },
+        sub {
+          $_->select('.name')->replace_content('Epitaph')
+            ->select('.age')->replace_content('<redacted>')
+        },
+      ],
+      { repeat_between => '.between' }
+    )
+  ->to_html;
+my $expect = <<HTML;
+<html>
+  <head>
+    <title>Hello world &amp; dog!</title>
+  </head>
+  <body>
+    <h1 id="greeting">Hello world &amp; dog!</h1>
+    <div id="list">
+      <span>
+        <p>Name: <span class="name">Matt</span></p>
+        <p>Age: <span class="age">26</span></p>
+      </span>
+      <hr class="between" />
+      <span>
+        <p>Name: <span class="name">Mark</span></p>
+        <p>Age: <span class="age">0x29</span></p>
+      </span>
+      <hr class="between" />
+      <span>
+        <p>Name: <span class="name">Epitaph</span></p>
+        <p>Age: <span class="age">&lt;redacted&gt;</span></p>
+      </span>
+      
+    </div>
+  </body>
+</html>
+HTML
+is($output, $expect, 'Synopsis code works ok');;