d8de31577ff590be545511f7f6c71276909a9d35
[migration-tools.git] / Equinox-Migration / t / 01-SimpleTagList.t
1 #!perl -T
2
3 use Test::More tests => 45;
4 #use Test::More qw(no_plan);
5
6 use Equinox::Migration::SimpleTagList;
7
8 # baseline object creation
9 eval { my $stl = Equinox::Migration::SimpleTagList->new( file => "thefileisalie.txt" ) };
10 is ($@ =~ /^Can't open tags file:/, 1, 'cannot open that');
11
12 my $stl = Equinox::Migration::SimpleTagList->new();
13 is(ref $stl, "Equinox::Migration::SimpleTagList", "self is self");
14
15 # manual adds and removes
16 $stl->add_tag(89);
17 is ($stl->has(89), 1, 'can has tag');
18 is ($stl->has(904), 0, 'can not has tag');
19 $stl->add_tag(904);
20 is ($stl->has(904), 1, 'can has tag');
21 $stl->remove_tag(904);
22 is ($stl->has(904), 0, 'can not has tag');
23
24 eval { $stl->add_tag('q') };
25 is ($@, "Values must be numeric\n");
26 eval { $stl->add_tag(-37) };
27 is ($@, "Values must be valid tags (0-999)\n");
28 eval { $stl->add_tag(1027) };
29 is ($@, "Values must be valid tags (0-999)\n");
30 eval { $stl->add_tag(89) };
31 is ($@, "Tag '89' specified twice\n");
32 eval { $stl->remove_tag(11) };
33 is ($@, "Tag '11' isn't in the list\n");
34
35 # range addition, as_hashref, as_listref
36 $stl->add_range("198..201");
37 is_deeply ($stl->as_hashref, { 89 => 1, 198 => 1, 199 => 1, 200 => 1, 201 => 1 });
38 is_deeply ($stl->as_listref, [ 89, 198, 199, 200, 201 ]);
39 $stl->add_range("008..011");
40 is_deeply ($stl->as_listref, [ 8, 9, 10, 11, 89, 198, 199, 200, 201 ]);
41
42 $stl->{conf}{except} = 1;
43 eval { $stl->add_range("300..311") };
44 is ($@, "Exception ranges must be within last addition range (300..311)\n");
45 eval { $stl->add_range("10..311") };
46 is ($@, "Exception ranges must be within last addition range (10..311)\n");
47 eval { $stl->add_range("6..11") };
48 is ($@, "Exception ranges must be within last addition range (6..11)\n");
49 eval { $stl->add_range("17..16") };
50 is ($@, "Ranges must be 'low..high' (17 is greater than 16)\n");
51
52
53
54 # creation with file
55 $stl = Equinox::Migration::SimpleTagList->new( file => "./t/corpus/stl-0.txt");
56 is ($stl->has(11), 1);
57 is ($stl->has('011'), 1);
58 is ($stl->has(12), 1);
59 is ($stl->has('012'), 1);
60 is ($stl->has(241), 1);
61 is ($stl->has(359), 1);
62 is ($stl->has(652), 1);
63 is ($stl->has(654), 1);
64 is ($stl->has(656), 1);
65 is ($stl->has(658), 1);
66 is ($stl->has(872), 1);
67 is ($stl->has(900), 1);
68 is ($stl->has(999), 1);
69 is ($stl->has(988), 1);
70 is ($stl->has(655), 0, 'exception');
71 is ($stl->has(987), 0, 'exception');
72 is ($stl->has(400), 0, 'not in input set');
73
74 $stl = Equinox::Migration::SimpleTagList->new( file => "./t/corpus/stl-1.txt");
75 is ($stl->has(258), 1);
76 is ($stl->has(259), 0, 'exception');
77 is ($stl->has(274), 1);
78 is ($stl->has(275), 0, 'exception');
79 is ($stl->has(286), 1);
80 is ($stl->has(285), 0, 'exception');
81 is ($stl->has(305), 1);
82 is ($stl->has(304), 0, 'exception');
83
84 # file with bad token
85 $. = 0;
86 $stl = Equinox::Migration::SimpleTagList->new;
87 $stl->{conf}{file} = "./t/corpus/stl-2.txt";
88 eval {$stl->generate};
89 is ($@, "Unknown chunk fnord in tags file (line 1)\n");
90
91 # file with except in wrong place
92 $. = 0;
93 $stl = Equinox::Migration::SimpleTagList->new;
94 $stl->{conf}{file} = "./t/corpus/stl-3.txt";
95 eval {$stl->generate};
96 is ($@, "Keyword 'except' can only follow a range (line 1)\n");