/[webpac2]/trunk/t/2-parse.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/t/2-parse.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 704 - (show annotations)
Mon Sep 25 13:24:25 2006 UTC (17 years, 7 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2775 byte(s)
 r1001@llin:  dpavlin | 2006-09-25 15:21:57 +0200
 and test it

1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More tests => 26;
5 use Test::Exception;
6 use blib;
7
8 use Data::Dump qw/dump/;
9 use Cwd qw/abs_path/;
10 use YAML qw/LoadFile/;
11
12 BEGIN {
13 use_ok( 'WebPAC::Parser' );
14 use_ok( 'WebPAC::Config' );
15 }
16
17 my $debug = shift @ARGV;
18
19 ok(my $abs_path = abs_path($0), "abs_path");
20 $abs_path =~ s#/[^/]*$#/#;
21
22 my $config_path = "$abs_path/conf/test.yml";
23
24 ok(-e $config_path, "$config_path exists");
25
26 throws_ok { new WebPAC::Parser( no_log => 1 ) } qr/WebPAC::Config/, "new without config";
27
28 ok(
29 my $parser = new WebPAC::Parser(
30 config => new WebPAC::Config( path => $config_path ),
31 base_path => $abs_path,
32 debug => $debug,
33 ), "new");
34
35 my $inputs = {
36 foo => [ qw/foo-input1 foo-input2/ ],
37 bar => [ qw/bar-input/ ],
38 baz => [ qw/baz-input/ ],
39 };
40
41 foreach my $db (keys %$inputs) {
42 ok($parser->valid_database($db), "database $db");
43 ok($inputs->{$db}, "has known inputs");
44 diag "valid inputs = ", dump($inputs->{$db});
45 foreach my $i (@{ $inputs->{$db} }) {
46 ok($parser->valid_database_input($db,$i), "input $i");
47 }
48 }
49 ok(! $parser->valid_database('non-existant'), "no database");
50 ok(! $parser->valid_database_input('foo','non-existant'), "no database input");
51
52 ok(my $l = $parser->{_lookup_create}, "_lookup_create");
53 diag "_lookup_create = ",dump($l);
54
55 ok(my $n = $parser->{_normalize_source}, "_normalize_source");
56 diag "_normalize_source = ",dump($n);
57
58 ok(my $d = $parser->{depends}, "depends");
59 diag "depends = ",dump($d);
60
61 my $expected_depend = {
62 foo => {
63 "foo-input1" => {
64 bar => { "bar-input" => { "210-a-210-e" => 1, "220-a-220-e" => 1, "230-a-230-e" => 1 } },
65 baz => { "baz-input" => { "200-a" => 1 } },
66 foo => { "foo-input1" => { 11 => 1 }, "foo-input2" => { 11 => 1 } },
67 },
68 "foo-input2" => {
69 bar => { "bar-input" => { "900-x" => 1 } },
70 baz => { "baz-input" => { "900-x" => 1 } },
71 foo => { "foo-input1" => { "245-a" => 1 }, "foo-input2" => { "245-a" => 1 } },
72 },
73 },
74 bar => {
75 "bar-input" => {
76 baz => { "baz-input" => { "900-x" => 1 } },
77 foo => { "foo-input1" => { "245-a" => 1 } },
78 },
79 },
80 baz => {
81 "baz-input" => {
82 bar => { "bar-input" => { "900-x" => 1 } },
83 foo => { "foo-input2" => { "245-a" => 1 } },
84 },
85 },
86 };
87
88
89 is_deeply($d, $expected_depend, "depends correct");
90
91 foreach my $db (keys %$d) {
92 foreach my $i (keys %{$d->{$db}}) {
93 is_deeply($d->{$db}->{$i}, $parser->depends($db,$i), "depend $db/$i");
94 }
95 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26