#!/usr/bin/perl -w # test the mark method use strict; use Carp; use File::Spec; use lib File::Spec->catdir(File::Spec->curdir,"t"); use tools; #$|=1; my $DEBUG=0; use XML::Twig; my $perl= $]; my @data= map { chomp; [split /\t+/] } ; my $TMAX= 2 * @data; print "1..$TMAX\n"; foreach my $test (@data) { my( $doc, $regexp, $elts, $hits, $result)= @$test; (my $quoted_elts= $elts)=~ s{(\w+)}{'$1'}g; my @elts= eval( "($quoted_elts)"); my $t= XML::Twig->new->parse( $doc); my $root= $t->root; my @hits= $root->mark( $regexp, @elts); is( $t->sprint, $result, "mark( /$regexp/, $quoted_elts) on $doc"); is( scalar @hits, $hits, 'nb hits'); } exit 0; # doc regexp elts hits result __DATA__ text X (X) s 1 text X text X X s 1 text text X s 0 text text (X) s 0 text text X X s 1 text text X (X) s 1 text X text X \s*X\s* s 1 text text X \s*(X)\s* s 1 textX text X (\s*X\s*) s 1 text X text X text X s 1 text text text X text (X) s 1 text X text text X text \s*X\s* s 1 texttext text X text \s*(X)\s* s 1 textXtext text X text (\s*X\s*) s 1 text X text text XX X s 2 text text XX (X) s 2 text XX text X X X s 2 text text X X (X) s 2 text X X text XX text X s 2 text text text XX text (X) s 2 text XX text text XY text Y text X ([XY]+) s 3 text XY text Y text X text X X s, {a => 1} 1 text text X (X) s, {a => 1, b => 2} 1 text X text X1Y2 text X0 Y0X3Y4 text X X(\d)Y(\d) s 4 text 12 text X0 Y034 text X