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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
use strict;
use warnings;
use Test::More qw(no_plan);
use Data::Dumper;
$Data::Dumper::Indent = 1;
use TM::Materialized::AsTMa;
sub _chomp {
my $s = shift;
chomp $s;
return $s;
}
my $warn = shift @ARGV;
unless ($warn) {
close STDERR;
open (STDERR, ">/dev/null");
select (STDERR); $| = 1;
}
#== TESTS ===========================================================================
require_ok ('TM::Materialized::XTM');
{
my $tm = new TM::Materialized::XTM;
ok ($tm->isa('TM::Materialized::XTM'), 'correct class 1');
ok ($tm->isa('TM::Materialized::Stream'), 'correct class 2');
ok ($tm->isa('TM'), 'correct class 3');
}
my $tm = new TM::Materialized::AsTMa (baseuri=>"tm://", inline=> '
nackertes_topic
atop
bn: just a topic
btop (ctop)
bn: something
bn@ascope: some other thing
ctop
bn: over the top!
in: something
in: somemore
oc: http://somewhere
in@ascope: scoped
in@ascope (sometype): also typed
oc (sometype): http://typedoc
oc @ascope (sometype): http://typedandscopedoc
(sucks-more-than)
sucker: ctop
winner: atop
winner: others
(sucks-more-than) @ascope
sucker: nobody
winner: nobody
thistop reifies http://rumsti
bn: reification
in: reification
sin: http://nowhere.ever.never
sin: http://nowhere.never.ever
(sucks-more-than) is-reified-by atop
winner: nobody
sucker: nobody
')->sync_in;
Class::Trait->apply ($tm, "TM::Serializable::XTM");
{
my $tm2 = new TM::Materialized::XTM (baseuri=>"tm://", inline => $tm->serialize)->sync_in;
is_deeply( $tm->{mid2iid}, $tm2->{mid2iid}, 'toplet structure identical' );
is_deeply( $tm->{assertions}, $tm2->{assertions}, 'asserts structure identical' );
}
eval {
my $tm2 = new TM::Materialized::XTM (url => 'file:xxx');
$tm2->sync_in;
}; like ($@, qr/unable to load/, _chomp ($@));
eval {
my $tm2 = new TM::Materialized::XTM (file => 'xxx.xxx');
is ($tm2->url, 'file:xxx.xxx', 'url ok');
};
eval {
my $tm2 = new TM::Materialized::XTM (inline => q|<topicMap version="2.1">
</topicMap>
|)->sync_in;
}; like ($@, qr/unsupported/, 'version unsupported');
__END__
{
my $tm2 = new TM::Materialized::XTM (inline => q|<?xml version="1.0"?>
<topicMap xmlns='http://www.topicmaps.org/xtm/1.0/' xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<topic id="aaa">
<baseName>
<instanceOf><topicRef xlink:href="#bbb"/></instanceOf>
<baseNameString>AAA</baseNameString>
</baseName>
<occurrence>
<instanceOf><topicRef xlink:href="#bbb"/></instanceOf>
<scope><topicRef xlink:href="#sss"/></scope>
<resourceData>sldfsdlf</resourceData>
</occurrence>
</topic>
<topic id="bbb"/>
<association>
<instanceOf><topicRef xlink:href="#atype"/></instanceOf>
<member>
<roleSpec><topicRef xlink:href="#role2"/></roleSpec>
<topicRef xlink:href="#player1"/>
</member>
<member>
<roleSpec><topicRef xlink:href="#role1"/></roleSpec>
<topicRef xlink:href="#player2"/>
<resourceRef xlink:href="http://player3/"/>
</member>
</association>
</topicMap>
|)->sync_in;
warn Dumper $tm2;
warn $tm2->serialize (version => '2.0');
}
__END__
|