1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use Test::More tests => 16; |
4 |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
6 |
use Data::Dump qw/dump/; |
7 |
use blib; |
8 |
use strict; |
9 |
|
10 |
BEGIN { |
11 |
use_ok( 'WebPAC::Output::Sorted' ); |
12 |
} |
13 |
|
14 |
my $debug = shift @ARGV; |
15 |
|
16 |
ok(my $abs_path = abs_path($0), "abs_path"); |
17 |
$abs_path =~ s#/[^/]*$#/#; # |
18 |
diag "abs_path: $abs_path"; |
19 |
my $path = "$abs_path/sorted/"; |
20 |
|
21 |
ok(my $out = new WebPAC::Output::Sorted({ |
22 |
path => $path, |
23 |
database => 'test', |
24 |
clean => 1, |
25 |
debug => $debug, |
26 |
}), "new"); |
27 |
|
28 |
ok( $out->init, 'init' ); |
29 |
|
30 |
my $ds = { |
31 |
'Source' => { |
32 |
'name' => 'Izvor: ', |
33 |
'sorted' => [ 'foo' ] |
34 |
}, |
35 |
'ID' => { |
36 |
'sorted' => 'id', |
37 |
}, |
38 |
'Array' => { |
39 |
'sorted' => [ qw/a1 a2 s3 a4 a5/ ], |
40 |
}, |
41 |
}; |
42 |
|
43 |
throws_ok { $out->add( ) } qr/need id/, 'add without params'; |
44 |
throws_ok { $out->add( 42 ) } qr/need ds/, 'add without ds'; |
45 |
|
46 |
ok( $out->add( 42, $ds ), 'add 42' ); |
47 |
|
48 |
ok( $out->add( 99, { foo => { sorted => 'bar' } } ), 'add 99' ); |
49 |
|
50 |
ok( $out->add( 100, { foo => { sorted => [ qw/foo bar baz/ ] } } ), 'add 100' ); |
51 |
|
52 |
ok( -e $out->path, "created $path" ); |
53 |
|
54 |
diag $out->path," eq ",$path; |
55 |
cmp_ok( $out->path, 'eq', $path, 'path' ); |
56 |
|
57 |
ok( $out->finish, 'finish' ); |
58 |
|
59 |
foreach my $l ( qw/source id array foo/ ) { |
60 |
ok( -e "$path/$l.txt", "list $l exists" ); |
61 |
} |