From: Marius Gavrilescu
Date: Thu, 25 Dec 2014 20:34:36 +0000 (+0200)
Subject: Fix tests
X-Git-Tag: 5.200_001~17
X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=d4b9a41af9be3575f07fe96d77ede6b4caf8dee5;p=html-element-library.git
Fix tests
---
diff --git a/Makefile.PL b/Makefile.PL
index 60d6ffe..7d2fdb4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -17,7 +17,8 @@ WriteMakefile(
qw/File::Slurp 0
HTML::PrettyPrinter 0
HTML::TreeBuilder 0
- Test::More 0/,
+ Test::More 0
+ Test::XML 0/,
},
PREREQ_PM => {
qw/Array::Group 0
diff --git a/t/TestUtils.pm b/t/TestUtils.pm
deleted file mode 100644
index e4bb274..0000000
--- a/t/TestUtils.pm
+++ /dev/null
@@ -1,35 +0,0 @@
-package TestUtils;
-
-use HTML::PrettyPrinter;
-use FileHandle;
-use File::Slurp;
-
-require Exporter;
-@ISA=qw(Exporter);
-@EXPORT = qw(ptree html_dir strip_ws);
-
-sub html_dir {
- 't/html/'
-}
-
-sub ptree {
- my $tree = shift or die 'must supply tree';
- my $out = shift or die 'must supply outfile';
-
- my $hpp = HTML::PrettyPrinter->new
- (tabify => 0, allow_forced_nl => 1, quote_attr => 1);
- my $lines = $hpp->format($tree);
-
- write_file $out, @$lines;
- join '', @$lines;
-}
-
-sub strip_ws {
- my($str)=@_;
-
- $str =~ s/\s+//g;
- $str;
-}
-
-
-1;
diff --git a/t/crunch.t b/t/crunch.t
index 383d5ed..627ef2a 100644
--- a/t/crunch.t
+++ b/t/crunch.t
@@ -1,11 +1,9 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;use warnings;
-use lib qw(t/ t/m/);
-use File::Slurp;
+use File::Slurp qw/read_file/;
use Test::More;
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
use Test::XML;
@@ -16,17 +14,9 @@ sub tage {
my $tree = HTML::TreeBuilder->new_from_file("$root.initial")->guts;
-
$tree->crunch(look_down => [ class => 'imageElement' ], leave => 1);
- my $generated_html = strip_ws ( ptree($tree, "$root.gen") );
- # must put read_file() in scalar context so that a string instead of first line is returned.
- my $expected_html = strip_ws(scalar File::Slurp::read_file("$root.exp"));
-
- #warn "g:$generated_html";
- #warn "e:$expected_html";
-
- is ($generated_html, $expected_html, "HTML for crunch");
+ is_xml $tree->as_XML, scalar read_file("$root.exp"), 'XML for crunch';
}
diff --git a/t/defmap.t b/t/defmap.t
index c26ab43..26eeeed 100644
--- a/t/defmap.t
+++ b/t/defmap.t
@@ -1,12 +1,10 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;use warnings;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
use Test::XML;
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
@@ -22,11 +20,11 @@ sub tage {
$tree->defmap(smap => \%data, 1);
- my $g = ptree($tree, "$root.gen");
+ my $g = $tree->as_XML;
my $e = File::Slurp::read_file("$root.exp");
warn "generated:$g:\nexpected:$e:";
- is_xml ($g, $e, "HTML for defmap");
+ is_xml ($g, $e, "XML for defmap");
}
diff --git a/t/dual_iter.t b/t/dual_iter.t
index dfe5b2f..dbcfb28 100644
--- a/t/dual_iter.t
+++ b/t/dual_iter.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
# this is a simpler call to iter2()
@@ -47,7 +46,6 @@ $tree->iter2(
);
- my $generated_html = ptree($tree, "$root.gen");
- is ($generated_html, File::Slurp::read_file("$root.exp"),
- "HTML for generated li");
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"),
+ "XML for generated li");
diff --git a/t/fillinform.t b/t/fillinform.t
index 3a6c0f2..d989f4e 100644
--- a/t/fillinform.t
+++ b/t/fillinform.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;use warnings;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
sub tage {
@@ -19,9 +18,7 @@ sub tage {
my $new_tree = HTML::TreeBuilder->new_from_content( $tree->fillinform(\%data) ) ;
- my $generated_html = ptree($new_tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for fillinform");
+ is_xml ($new_tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "HTML for fillinform");
}
diff --git a/t/hashmap.t b/t/hashmap.t
index 285f64c..9ed2864 100644
--- a/t/hashmap.t
+++ b/t/hashmap.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
sub replace_age {
my $branch = shift;
@@ -29,15 +28,11 @@ sub tage {
$tree->hash_map
(hash => \%data,
to_attr => 'sid',
- excluding => [ 'email' ],
- debug => 1
+ excluding => [ 'email' ]
);
- my $generated_html = ptree($tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for same_as");
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "XML for same_as");
}
tage();
-
diff --git a/t/highlander.t b/t/highlander.t
index 061cc5f..e9f754c 100644
--- a/t/highlander.t
+++ b/t/highlander.t
@@ -1,14 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
-
+use Test::XML;
sub tage {
my $age = shift;
@@ -27,9 +25,8 @@ sub tage {
my $root = "t/html/highlander-$age";
- my $generated_html = ptree($tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for $age");
+ local $_; # XML::Parser does not like read-only $_ (RT #101129)
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "XML for $age");
}
diff --git a/t/highlander2.t b/t/highlander2.t
index 479553f..c145b68 100644
--- a/t/highlander2.t
+++ b/t/highlander2.t
@@ -1,13 +1,12 @@
# This might look like shell script, but it's actually -*- perl -*-
use strict;
-use lib qw(t/ t/m/);
use File::Slurp;
use Test::More qw(no_plan);
-use TestUtils;
use HTML::TreeBuilder;
use HTML::Element::Library;
+use Test::XML;
sub replace_age {
my $branch = shift;
@@ -41,9 +40,8 @@ sub tage {
my $root = "t/html/highlander2-$age";
- my $generated_html = ptree($tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for $age");
+ local $_; # XML::Parser does not like read-only $_ (RT #101129)
+ is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"), "HTML for $age");
}
diff --git a/t/html/crunch/crunch.exp b/t/html/crunch/crunch.exp
index 5c5b118..272e334 100644
--- a/t/html/crunch/crunch.exp
+++ b/t/html/crunch/crunch.exp
@@ -1,30 +1,30 @@
-
-
-
-
-
-
-
-
-
-
-
-
Item 1 Title
-
Item 1 Description
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
Item 1 Title
+
Item 1 Description
+
+
+
+
+
diff --git a/t/html/crunch/crunch.gen b/t/html/crunch/crunch.gen
deleted file mode 100644
index 5c5b118..0000000
--- a/t/html/crunch/crunch.gen
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
Item 1 Title
-
Item 1 Description
-
-
-
-
-
diff --git a/t/html/defmap/defmap.gen b/t/html/defmap/defmap.gen
deleted file mode 100644
index f5aabd8..0000000
--- a/t/html/defmap/defmap.gen
+++ /dev/null
@@ -1,5 +0,0 @@
-
- Yes |
- arsenal rules |
- No |
-
diff --git a/t/html/dual_iter.gen b/t/html/dual_iter.gen
deleted file mode 100644
index 64c6c8f..0000000
--- a/t/html/dual_iter.gen
+++ /dev/null
@@ -1,15 +0,0 @@
-
-
-
-
- - the pros
- - never have to worry about service again
- - the cons
- - upfront extra charge on purchase
- - our choice
- - go with the extended service plan
- - sample header
- - sample data
-
-
-
diff --git a/t/html/fillinform/fillinform.exp b/t/html/fillinform/fillinform.exp
index ed123ac..bbe603e 100644
--- a/t/html/fillinform/fillinform.exp
+++ b/t/html/fillinform/fillinform.exp
@@ -5,18 +5,18 @@
Dialer
-
-
diff --git a/t/html/fillinform/fillinform.gen b/t/html/fillinform/fillinform.gen
deleted file mode 100644
index ed123ac..0000000
--- a/t/html/fillinform/fillinform.gen
+++ /dev/null
@@ -1,23 +0,0 @@
-
-