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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
#-- test suite
use strict;
use warnings;
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More qw(no_plan);
use Test::Deep;
use Data::Dumper;
$Data::Dumper::Indent = 1;
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::DM');
use TM::Materialized::AsTMa;
my $atm = new TM::Materialized::AsTMa (baseuri => 'tm:rumsti',
inline => '
adam
bn: Adam Adamovich
bn @ en: Adam Adamovichev
oc: http://adam.akest.hewor.ldgorou.nd/
sin: tm:ramsti/
sin: tm:romsti/
in: the first will be the last
in @ en (opinion): he is highly overrated
oc (homepage): http://oldtesta.ment/~adam/
eve
bn: Eve
bn @ en: Eva
in: the first lady
oc: urn:x-biblical:hell
(begets)
parent: adam eve
child: cain
(begets)
parent: adam eve
child: abel
(begets)
parent: adam eve
child: seth
(begets)
parent: adam eve
child: azura
#--
(begets)
parent: cain
child: enoch
#--
(begets)
parent: enoch
child: irad
#--
(begets)
parent: irad
child: mehajael
#--
(begets)
parent: seth
child: enosh
(begets) @ old_testament
parent: seth
child: noam
');
$atm->sync_in;
eval {
my $tmdm = new TM::DM (map => 12);
}; like ($@, qr/not really/i, _chomp($@));
{ # test TopicMap
my $tmdm = new TM::DM (map => $atm);
my $tm = $tmdm->topicmap;
is (scalar $tm->topics, scalar $atm->toplets, 'all topics there');
is (scalar $tm->associations, scalar $atm->match (TM->FORALL, nochar => 1), 'all assocs there');
is ($tm->reifier, undef, 'no reifier');
$atm->internalize ('rumsti' => 'tm:rumsti#');
is ($tm->reifier->id, 'tm:rumsti#rumsti', 'reifier');
}
{ # test Topic
my $tmdm = new TM::DM (map => $atm);
my $tm = $tmdm->topicmap;
$atm->internalize ('adam' => 'tm:rumsti#rimsti');
# $atm->internalize ('remsti' => \ 'tm:ramsti/');
# $atm->internalize ('remsti' => \ 'tm:romsti/');
my $to = $tm->topic ('adam');
# warn Dumper $to;
is ($to->id, 'tm:rumsti#adam', 'id');
is ($to->subjectLocators, 'tm:rumsti#rimsti', 'subject locator');
ok (eq_set ([
$to->subjectIdentifiers
],
[
'tm:ramsti/',
'tm:romsti/'
]), 'subject indicators');
is ($to->parent->id, $tmdm->topicmap->id, 'parent');
ok (eq_set ( [ map { $_->value } $to->names ],
[
'Adam Adamovich',
'Adam Adamovichev'
]), 'names');
is (scalar $to->occurrences, 4, 'occurrences');
ok (! grep ($_ ne 'tm:rumsti#parent', map {$_->type->id} $to->roles), 'adam is only parent');
ok (! grep ($_ ne 'tm:rumsti#adam', map {$_->player->id} $to->roles), 'adam is only parent');
}
{ # assoc
my $tmdm = new TM::DM (map => $atm);
my $tm = $tmdm->topicmap;
my @as = $tm->associations (iplayer => 'adam');
#warn Dumper \@as;
is (scalar @as, 4, 'all adam involvements');
ok (! grep ($_ ne 'tm:rumsti#', map { $_->parent->id } @as ), 'assocs parent');
ok (! grep ($_ ne 'tm:rumsti#begets', map { $_->type->id } @as ), 'assocs types');
foreach my $a (@as) {
foreach my $r ($a->roles) {
# warn Dumper $r;
next if $r->type->id eq 'tm:rumsti#child' or $r->type->id eq 'tm:rumsti#parent';
next if $r->type->id eq 'tm:rumsti#parent' &&
($r->player->id eq 'tm:rumsti#adam' or $r->type->id eq 'tm:rumsti#eve');
die;
}
ok (1, 'adam and eve play parents, makes creepy sense');
}
is (scalar grep ($_ ne 'us', map { $_->scope->id }
$tm->associations ), 1, 'others are us scoped assocs');
@as = grep ($_->scope->id ne 'us',
$tm->associations (anyid => 'tm:rumsti#old_testament'));
is (scalar @as, 1, 'one scoped assoc');
$atm->internalize ('sethnoam' => $as[0]->id);
is ($as[0]->reifier->id, 'tm:rumsti#sethnoam', 'reified assoc');
}
{ # name
my $tmdm = new TM::DM (map => $atm);
my $tm = $tmdm->topicmap;
my $to = $tm->topic ('adam');
my @ns = $to->names;
ok (eq_set ( [ map { $_->value } @ns ],
[
'Adam Adamovich',
'Adam Adamovichev'
]), 'names (again)');
ok (! grep ($_ ne 'name', map { $_->type->id } @ns ), 'name type');
@ns = grep ($_->scope->id ne 'us', $to->names);
is (scalar @ns, 1, 'one scoped name');
is ($ns[0]->scope->id, 'tm:rumsti#en', 'name scope');
$atm->internalize ('adamnamer' => $atm->retrieve ($ns[0]->id));
is ($ns[0]->reifier->id, 'tm:rumsti#adamnamer', 'reified name');
is ($ns[0]->parent->id, $to->id, 'name parent')
}
{ # occurrence
my $tmdm = new TM::DM (map => $atm);
my $tm = $tmdm->topicmap;
my $to = $tm->topic ('adam');
my @oc = $to->occurrences;
cmp_set ([
map { [ $_->value->[0], $_->value->[1], $_->type->id, $_->scope->id ] } @oc
],
[
[
'http://adam.akest.hewor.ldgorou.nd/',
'http://www.w3.org/2001/XMLSchema#anyURI',
'occurrence',
'us'
],
[
'http://oldtesta.ment/~adam/',
'http://www.w3.org/2001/XMLSchema#anyURI',
'tm:rumsti#homepage',
'us'
],
[
'the first will be the last',
'http://www.w3.org/2001/XMLSchema#string',
'occurrence',
'us'
],
[
'he is highly overrated',
'http://www.w3.org/2001/XMLSchema#string',
'tm:rumsti#opinion',
'tm:rumsti#en'
],
], 'occurrences (again)');
$atm->internalize ('adamnamer2' => $atm->retrieve ($oc[0]->id));
is ($oc[0]->reifier->id, 'tm:rumsti#adamnamer2', 'reified occur');
ok (! grep ($_ ne 'tm:rumsti#adam', map { $_->parent->id } @oc ), 'occur parent');
}
{ # roles
my $tmdm = new TM::DM (map => $atm);
my $tm = $tmdm->topicmap;
my ($a) = grep ($_->scope->id ne 'tm:rumsti#us' && $_->type->id ne "isa",
$tm->associations (anyid => 'tm:rumsti#old_testament'));
cmp_set ([ map { [ $_->type->id, $_->player->id ] } $a->roles ],
[
[
'tm:rumsti#child',
'tm:rumsti#noam'
],
[
'tm:rumsti#parent',
'tm:rumsti#seth'
]
], 'roles all there');
ok (! grep ($_ ne $a->id, map { $_->parent->id } $a->roles ), 'roles parent');
eval {
map { $_->id } $a->roles;
}; like ($@, qr/object method/i, _chomp($@));
}
{ # topic search spec
my $tmdm = new TM::DM (map => $atm);
my $tm = $tmdm->topicmap;
is (scalar $tm->topics, scalar $atm->toplets, 'spec: empty, all topics there');
is (scalar $tm->topics (\ '+all'), scalar $atm->toplets, 'spec: expl, all topics there');
ok (eq_set ([ map { $_->id } $tm->topics],
[ map { $_->[TM->LID] } $atm->toplets]), 'same identifiers');
}
__END__
|