File: 06pass_to_handler.t

package info (click to toggle)
libxml-semanticdiff-perl 1.0007-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 340 kB
  • sloc: perl: 703; xml: 532; sh: 4; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 1,688 bytes parent folder | download | duplicates (2)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use Test;
BEGIN { plan tests => 1 }

use XML::SemanticDiff;

$xml1 = <<'EOX';
<?xml version="1.0"?>
<root>
<el1 el1attr="good"/>
<el2 el2attr="good">Some Text</el2>
<el3/>
</root>
EOX

$xml2 = <<'EOX';
<?xml version="1.0"?>
<root>
<el1 el1attr="bad"/>
<el2 bogus="true"/>
<el4>Rogue</el4>
</root>
EOX

my $handler = BetterDiff->new();

my $diff = XML::SemanticDiff->new(diffhandler => $handler);

my @results = $diff->compare($xml1, $xml2);

ok(@results == 6);

package BetterDiff;

use strict;

sub new {
    my ($proto, %args) = @_;
    my $class = ref($proto) || $proto;
    my $self  = \%args;
    bless ($self, $class);
    return $self;
}

sub rogue_element {
    my $self = shift;
    my ($element_path, $new_element) = @_;
    return 1 if $element_path and $new_element;
}

sub rogue_attribute {
    my $self = shift;
    my ($attr, $element_path, $new_element, $old_element) = @_;
    return 1 if $attr and $element_path and $new_element and $old_element;
}

sub missing_element {
    my $self = shift;
    my ($element_path, $old_element) = @_;
    return 1 if $element_path and $old_element;
}

sub missing_attribute {
    my $self = shift;
    my ($attr, $element_path, $new_element, $old_element) = @_;
    return 1 if $attr and $element_path and $new_element and $old_element;
}

sub attribute_value {
    my $self = shift;
    my ($attr, $element_path, $new_element, $old_element) = @_;
    return 1 if $attr and $element_path and $new_element and $old_element;
}

sub element_value {
    my $self = shift;
    my ($element_path, $new_element, $old_element) = @_;
    return 1 if $element_path and $new_element and $old_element;
}

sub namespace_uri {
    return 1;
}

1;