From 271d5078dc10f92db0d9927bd84065a0b9a38397 Mon Sep 17 00:00:00 2001 From: Terrence Brannon Date: Tue, 5 Jul 2011 14:23:33 -0400 Subject: [PATCH] all tests pass --- .gitignore | 1 + dist.ini | 4 +- lib/HTML/Element/Library.pm | 20 ++++ lib/HTML/Element/Library.pod | 74 ++++++++++++- t/crunch.t | 3 +- t/html/crunch/crunch.exp | 30 +++++ t/html/crunch/crunch.gen | 60 +++++----- t/html/table2-table_ld-arrayref.exp | 4 +- t/html/table2-table_ld-arrayref.gen | 4 +- t/html/table2-table_ld-arrayref.html | 4 +- t/html/table2-table_ld-coderef.exp | 4 +- t/html/table2-table_ld-coderef.gen | 4 +- t/html/table2-table_ld-coderef.html | 4 +- t/html/table2-table_ld-default.exp | 4 +- t/html/table2-table_ld-default.gen | 4 +- t/html/table2-table_ld-default.html | 4 +- t/html/table2-tr_ld-coderef.exp | 5 +- t/html/table2-tr_ld-coderef.gen | 5 +- t/html/table2-tr_ld-coderef.html | 4 +- t/html/table2-tr_ld-default.exp | 160 +++++++++++++++++++++++++++ t/html/table2.exp | 5 +- t/html/table2.gen | 5 +- t/html/table2.html | 4 +- t/newnode.t | 50 +++++++++ t/table2-table_ld.t | 4 +- t/table2.t | 9 +- 26 files changed, 387 insertions(+), 92 deletions(-) create mode 100644 t/html/crunch/crunch.exp create mode 100644 t/html/table2-tr_ld-default.exp create mode 100644 t/newnode.t diff --git a/.gitignore b/.gitignore index a06f387..e5e7ab1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ blib/* pm_to_blib Makefile .emacs.desktop +.build/* diff --git a/dist.ini b/dist.ini index ed727c1..d8740f8 100644 --- a/dist.ini +++ b/dist.ini @@ -10,5 +10,5 @@ version = 4.4 [AutoPrereqs] -[Prereqs] -Test::XML = 0 \ No newline at end of file +skip = (Test::XML|Arsenal|SimpleClass|SelectData|TestUtils|data::table2) + diff --git a/lib/HTML/Element/Library.pm b/lib/HTML/Element/Library.pm index 024e114..cb9cec3 100644 --- a/lib/HTML/Element/Library.pm +++ b/lib/HTML/Element/Library.pm @@ -98,6 +98,26 @@ sub HTML::Element::prune { $self; } +sub HTML::Element::newnode { + my ($lol, $node_label, $new_node)=@_; + + use Data::Rmap qw(rmap_array); + + my ($mapresult) = rmap_array { + + + if ($_->[0] eq $node_label) { + $_ = $new_node; + Data::Rmap::cut($_); + } else { + $_; + } + + } $lol; + + $mapresult; + +} sub HTML::Element::crunch { my $container = shift; diff --git a/lib/HTML/Element/Library.pod b/lib/HTML/Element/Library.pod index c7cde76..909aa9e 100644 --- a/lib/HTML/Element/Library.pod +++ b/lib/HTML/Element/Library.pod @@ -1089,27 +1089,89 @@ to display: +=head2 Tree-Killing Methods +=head3 $tree->prune -=head1 SEE ALSO +This removes any nodes from the tree which consist of nothing or nothing but whitespace. +See also delete_ignorable_whitespace in L. -=over +=head2 Loltree Functions + +A loltree is an arrayref consisting of arrayrefs which is used by +C<< new_from__lol >> in L to produce HTML trees. +The CPAN distro L creates such XML trees by parsing XML files, +analagous to L. The purpose of the functions in this section is to allow +you manipulate a loltree programmatically. -=item * L +These could not be methods because if you bless a loltree, then HTML::Tree will barf. -A perl package for creating and manipulating HTML trees +=head3 HTML::Element::replace_node($lol, $node_label, $new_node) -=item * L +Given this initial loltree: + + my $initial_lol = [ note => [ shopping => [ item => 'sample' ] ] ]; + +This code: + + sub shopping_items { + my @shopping_items = map { [ item => _ ] } qw(bread butter beans) ; + \@shopping_items; + } + + my $new_lol = HTML::Element::newnode($initial_lol, item => shopping_items()); + + will replace the single sample with a list of shopping items: + + + [ + 'note', + [ + 'shopping', + [ + [ + 'item', + 'bread' + ], + [ + 'item', + 'butter' + ], + [ + 'item', + 'beans' + ] + ] + ] + ]; + +Thanks to kcott and the other Perlmonks in this thread: +http://www.perlmonks.org/?node_id=912416 + + +=head1 SEE ALSO + +=head2 L + +A perl package for creating and manipulating HTML trees. + +=head2 L An L - based module which allows for manipulation of HTML trees using cartesian coordinations. -=item * L +=head2 * L An L - based module inspired by XMLC (L), allowing for dynamic HTML generation via tree rewriting. +=head2 Push-style tmeplating systems + +A comprehensive cross-language +L. + + =head1 TODO =over diff --git a/t/crunch.t b/t/crunch.t index b4a42e3..275a021 100644 --- a/t/crunch.t +++ b/t/crunch.t @@ -3,7 +3,7 @@ use strict;use warnings; use lib qw(t/ t/m/); use File::Slurp; -use Test::More qw(no_plan); +use Test::More; use TestUtils; use HTML::TreeBuilder; @@ -26,3 +26,4 @@ sub tage { tage(); +done_testing; diff --git a/t/html/crunch/crunch.exp b/t/html/crunch/crunch.exp new file mode 100644 index 0000000..5c5b118 --- /dev/null +++ b/t/html/crunch/crunch.exp @@ -0,0 +1,30 @@ + + + + + + + + + +
+
+

Item 1 Title

+

Item 1 Description

+ + Item 1 Title thumbnail of Item 1 Title
+
+ + diff --git a/t/html/crunch/crunch.gen b/t/html/crunch/crunch.gen index 0e6e3e1..5c5b118 100644 --- a/t/html/crunch/crunch.gen +++ b/t/html/crunch/crunch.gen @@ -1,30 +1,30 @@ - - - - - - - - - -
-
-

Item 1 Title

-

Item 1 Description

- - Item 1 Title thumbnail of Item 1 Title
-
- - + + + + + + + + + +
+
+

Item 1 Title

+

Item 1 Description

+ + Item 1 Title thumbnail of Item 1 Title
+
+ + diff --git a/t/html/table2-table_ld-arrayref.exp b/t/html/table2-table_ld-arrayref.exp index ed2919a..328a429 100644 --- a/t/html/table2-table_ld-arrayref.exp +++ b/t/html/table2-table_ld-arrayref.exp @@ -1,6 +1,4 @@ - +
diff --git a/t/html/table2-table_ld-arrayref.gen b/t/html/table2-table_ld-arrayref.gen index ed2919a..328a429 100644 --- a/t/html/table2-table_ld-arrayref.gen +++ b/t/html/table2-table_ld-arrayref.gen @@ -1,6 +1,4 @@ -
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-table_ld-arrayref.html b/t/html/table2-table_ld-arrayref.html index 544553b..cffaba2 100644 --- a/t/html/table2-table_ld-arrayref.html +++ b/t/html/table2-table_ld-arrayref.html @@ -23,9 +23,7 @@

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-table_ld-coderef.exp b/t/html/table2-table_ld-coderef.exp index ed2919a..328a429 100644 --- a/t/html/table2-table_ld-coderef.exp +++ b/t/html/table2-table_ld-coderef.exp @@ -1,6 +1,4 @@ -
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-table_ld-coderef.gen b/t/html/table2-table_ld-coderef.gen index ed2919a..328a429 100644 --- a/t/html/table2-table_ld-coderef.gen +++ b/t/html/table2-table_ld-coderef.gen @@ -1,6 +1,4 @@ -
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-table_ld-coderef.html b/t/html/table2-table_ld-coderef.html index 544553b..cffaba2 100644 --- a/t/html/table2-table_ld-coderef.html +++ b/t/html/table2-table_ld-coderef.html @@ -23,9 +23,7 @@

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-table_ld-default.exp b/t/html/table2-table_ld-default.exp index ed2919a..328a429 100644 --- a/t/html/table2-table_ld-default.exp +++ b/t/html/table2-table_ld-default.exp @@ -1,6 +1,4 @@ -
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-table_ld-default.gen b/t/html/table2-table_ld-default.gen index ed2919a..328a429 100644 --- a/t/html/table2-table_ld-default.gen +++ b/t/html/table2-table_ld-default.gen @@ -1,6 +1,4 @@ -
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-table_ld-default.html b/t/html/table2-table_ld-default.html index 544553b..cffaba2 100644 --- a/t/html/table2-table_ld-default.html +++ b/t/html/table2-table_ld-default.html @@ -23,9 +23,7 @@

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-tr_ld-coderef.exp b/t/html/table2-tr_ld-coderef.exp index 6df0c73..81399d8 100644 --- a/t/html/table2-tr_ld-coderef.exp +++ b/t/html/table2-tr_ld-coderef.exp @@ -11,10 +11,7 @@ href="http://search.cpan.org/search?query=Element%3A%3ALibrary&mode=all"> HTML::Element::Library.

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-tr_ld-coderef.gen b/t/html/table2-tr_ld-coderef.gen index 6df0c73..81399d8 100644 --- a/t/html/table2-tr_ld-coderef.gen +++ b/t/html/table2-tr_ld-coderef.gen @@ -11,10 +11,7 @@ href="http://search.cpan.org/search?query=Element%3A%3ALibrary&mode=all"> HTML::Element::Library.

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-tr_ld-coderef.html b/t/html/table2-tr_ld-coderef.html index 544553b..cffaba2 100644 --- a/t/html/table2-tr_ld-coderef.html +++ b/t/html/table2-tr_ld-coderef.html @@ -23,9 +23,7 @@

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2-tr_ld-default.exp b/t/html/table2-tr_ld-default.exp new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-tr_ld-default.exp @@ -0,0 +1,160 @@ +
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
Code-Page
ID
Name ACP OEMCP Windows
NT 3.1
Windows
NT 3.51
Windows
95
1200Unicode (BMP of ISO/IEC-10646)XX*
1250Windows 3.1 Eastern EuropeanXXXX
1251Windows 3.1 CyrillicXXXX
1252Windows 3.1 US (ANSI)XXXX
1253Windows 3.1 GreekXXXX
1254Windows 3.1 TurkishXXXX
1255HebrewXX
1256ArabicXX
1257BalticXX
1361Korean (Johab)X**X
437MS-DOS United StatesXXXX
708Arabic (ASMO 708)XX
709Arabic (ASMO 449+, BCON V4)XX
710Arabic (Transparent Arabic)XX
720Arabic (Transparent ASMO)XX
diff --git a/t/html/table2.exp b/t/html/table2.exp index 5ec9675..db2e10b 100644 --- a/t/html/table2.exp +++ b/t/html/table2.exp @@ -11,10 +11,7 @@ href="http://search.cpan.org/search?query=Element%3A%3ALibrary&mode=all"> HTML::Element::Library .

- +
diff --git a/t/html/table2.gen b/t/html/table2.gen index 5ec9675..db2e10b 100644 --- a/t/html/table2.gen +++ b/t/html/table2.gen @@ -11,10 +11,7 @@ href="http://search.cpan.org/search?query=Element%3A%3ALibrary&mode=all"> HTML::Element::Library.

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/html/table2.html b/t/html/table2.html index 544553b..cffaba2 100644 --- a/t/html/table2.html +++ b/t/html/table2.html @@ -23,9 +23,7 @@

-

CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
+
diff --git a/t/newnode.t b/t/newnode.t new file mode 100644 index 0000000..5ca7122 --- /dev/null +++ b/t/newnode.t @@ -0,0 +1,50 @@ +#!/usr/bin/perl -T + + +use warnings; +use strict; + +use Test::More; +use Test::XML; + +BEGIN { + use_ok('HTML::TreeBuilder'); + use_ok('HTML::Element::Library'); +} + + +my $initial_lol = [ note => [ shopping => [ item => 'sample' ] ] ]; +my $new_lol = HTML::Element::newnode($initial_lol, item => shopping_items()); + + +sub shopping_items { + my @shopping_items = map { [ item => $_ ] } qw(bread butter beans); + \@shopping_items; +} + +my $expected = [ + 'note', + [ + 'shopping', + [ + [ + 'item', + 'bread' + ], + [ + 'item', + 'butter' + ], + [ + 'item', + 'beans' + ] + ] + ] + ]; + +is_deeply($new_lol, $expected, 'test unrolling'); + + + +done_testing; diff --git a/t/table2-table_ld.t b/t/table2-table_ld.t index ba7bdab..3b3942b 100644 --- a/t/table2-table_ld.t +++ b/t/table2-table_ld.t @@ -9,7 +9,7 @@ use lib qw(t/ t/m/); use File::Slurp; -use Test::More qw(no_plan); +use Test::More; use TestUtils; use HTML::TreeBuilder; @@ -69,3 +69,5 @@ $generated_html = ptree($table, "$root.gen"); is ($generated_html, File::Slurp::read_file("$root.exp"), $root); + +done_testing; diff --git a/t/table2.t b/t/table2.t index eb0bb02..a8bff3e 100644 --- a/t/table2.t +++ b/t/table2.t @@ -4,7 +4,8 @@ use lib qw(t/ t/m/); use File::Slurp; -use Test::More qw(no_plan); +use Test::More; +use Test::XML; use TestUtils; @@ -48,5 +49,7 @@ for my $dataset (keys %$d) { my $generated_html = ptree($tree, "$root.gen"); -is ($generated_html, File::Slurp::read_file("$root.exp"), - "HTML for non-alternating table"); +is($generated_html, File::Slurp::read_file("$root.exp"), 'genhtml'); + + +done_testing; -- 2.39.2
CODE-PAGE SUPPORT IN MICROSOFT WINDOWS