summaryrefslogtreecommitdiff
path: root/textproc/p5-XML-LibXML-Iterator/patches/patch-ab
blob: c431bb80d93eee6ea3e6cd9f08774fa2b848aa9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
$NetBSD: patch-ab,v 1.1 2007/08/06 15:28:04 seb Exp $

--- t/03list.t.orig	2007-06-23 13:33:50.000000000 +0000
+++ t/03list.t
@@ -1,7 +1,7 @@
 use Test;
 
 
-BEGIN { plan tests => 7; }
+BEGIN { plan tests => 8; }
 
 use XML::LibXML;
 use XML::LibXML::NodeList::Iterator;
@@ -257,3 +257,49 @@ sub t05_run_iterate {
     return 1;
 }
 ok(t05_run_iterate());
+
+package MyFilter;
+use base qw(XML::NodeFilter);
+use XML::NodeFilter qw(:results);
+use UNIVERSAL;
+
+sub accept_node {
+    my $self = shift;
+    my $node = shift;
+    if (!UNIVERSAL::isa($node, 'XML::LibXML::Element')) {
+        die "invalid node in MyFilter::accept_node()";
+    }
+    return FILTER_DECLINED;
+}
+
+package main;
+
+sub t08_last_with_filter {
+    my $doc = XML::LibXML->new->parse_string( $xmlstr );
+    
+    unless ( defined $doc ) {
+        print "# XML string was not parsed properly\n";
+        return 0;
+    }
+
+    my $nodelist = $doc->findnodes( '//*' );
+    my $iterator = XML::LibXML::NodeList::Iterator->new( $nodelist ); 
+    $iterator->add_filter( MyFilter->new() );
+
+    $iterator->last();
+
+    unless ( defined $iterator->current() ) {
+        print "# there is no last node\n";
+        return 0;
+    }
+    
+    unless ( $iterator->current()->nodeName() eq "D" ) {
+        print "# expected nodeName 'D' received '"
+            . $iterator->current()->nodeName()
+            . "'\n";
+        return 0;
+    }
+
+    return 1;
+}
+ok(t08_last_with_filter());