/[webpac2]/trunk/t/3-normalize-set.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

Diff of /trunk/t/3-normalize-set.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 471 by dpavlin, Sat May 13 12:07:37 2006 UTC revision 485 by dpavlin, Sun May 14 11:06:42 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 25;  use Test::More tests => 56;
6  use Test::Exception;  use Test::Exception;
7  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
8  use blib;  use blib;
9  use File::Slurp;  use File::Slurp;
10    
11  use Data::Dumper;  use Data::Dumper;
12  my $debug = 0;  my $debug = shift @ARGV;
13    
14  BEGIN {  BEGIN {
15          use_ok( 'WebPAC::Normalize::Set' );          use_ok( 'WebPAC::Normalize::Set' );
# Line 144  sub test_s { Line 144  sub test_s {
144          no strict 'subs';          no strict 'subs';
145          use WebPAC::Normalize::Set;          use WebPAC::Normalize::Set;
146    
147            ok(! set_lookup( undef ), "set_lookup(undef)");
148    
149          set_rec( $rec1 );          set_rec( $rec1 );
150    
151          cmp_ok( join(",", rec2('200','a') ), 'eq', '200a,200a*2', 'join rec2' );          cmp_ok( join(",", rec2('200','a') ), 'eq', '200a,200a*2', 'join rec2' );
# Line 169  sub test_s { Line 171  sub test_s {
171                  ),                  ),
172          'eq', 'lookup 1 i lookup 2', 'join lookup regex rec2');          'eq', 'lookup 1 i lookup 2', 'join lookup regex rec2');
173    
174            # check join_with operations
175    
176            sub test_join_with_2 {
177                    my ($a,$b,$e) = @_;
178    
179                    cmp_ok(
180                            join_with(" <1> ",
181                                    rec('201',$a),
182                                    rec('201',$b),
183                            ),
184                    'eq', $e, "join_with $a <1> $b = $e");
185            }
186    
187            test_join_with_2('_','_','');
188            test_join_with_2('x','_','201x');
189            test_join_with_2('_','x','201x');
190            test_join_with_2('x','y','201x <1> 201y');
191    
192            sub test_join_with_3 {
193                    my ($a,$b,$c,$e) = @_;
194    
195                    cmp_ok(
196                            join_with(" <1> ", rec('201',$a),
197                                    join_with(" <2> ", rec('201',$b),
198                                            rec('201',$c),
199                                    )
200                            ),
201                    'eq', $e, "join_with $a <1> $b <2> $c = $e");
202            };
203    
204            test_join_with_3('_','_','_','');
205            test_join_with_3('x','_','_','201x');
206            test_join_with_3('_','x','_','201x');
207            test_join_with_3('_','_','x','201x');
208            test_join_with_3('x','y','_','201x <1> 201y');
209            test_join_with_3('x','_','y','201x <1> 201y');
210            test_join_with_3('_','x','y','201x <2> 201y');
211            test_join_with_3('x','_','y','201x <1> 201y');
212            test_join_with_3('x','y','x','201x <1> 201y <2> 201x');
213    
214            # test lookups
215    
216          set_lookup( $lookup2 );          set_lookup( $lookup2 );
217    
218          is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ], 'lookup prefix' );          is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ], 'lookup prefix' );
# Line 208  sub test_s { Line 252  sub test_s {
252          ok(my $ds = get_ds(), "get_ds");          ok(my $ds = get_ds(), "get_ds");
253          diag "ds = ", Dumper($ds) if ($debug);          diag "ds = ", Dumper($ds) if ($debug);
254    
         clean_ds();  
255    
256            sub test_check_ds {
257    
258                    my $t = shift;
259    
260                    ok($ds = get_ds(), 'get_ds');
261                    diag Dumper( $ds ) if ($debug);
262    
263                    ok( $ds && $ds->{something}, 'get_ds->something exists' );
264                    ok( $ds && $ds->{something}->{$t}, 'get_ds->something->'.$t.' exists') if ($t);
265                    ok( $ds && !$ds->{empty}, 'get_ds->empty doesn\'t' );
266    
267                    return $ds;
268            }
269    
270            clean_ds();
271          test_s(qq{ search('something', '42'); });          test_s(qq{ search('something', '42'); });
272          test_s(qq{ search('empty', ''); });          test_s(qq{ search('empty', ''); });
273            test_check_ds('search');
274    
275          ok($ds = get_ds(), 'get_ds');          clean_ds();
276          diag Dumper( $ds ) if ($debug);          test_s(qq{ display('something', '42'); });
277            test_s(qq{ display('empty', ''); });
278          ok( $ds && $ds->{something}, 'get_ds->something' );          test_check_ds('display');
         ok( $ds && !$ds->{empty}, 'get_ds->empty' );  
279    
280          clean_ds();          clean_ds();
281            test_s(qq{ tag('something', '42'); });
282            test_s(qq{ tag('empty', ''); });
283            test_check_ds('search');
284            test_check_ds('display');
285    
286            clean_ds();
287          my $n = read_file( "$abs_path/data/normalize.pl" );          my $n = read_file( "$abs_path/data/normalize.pl" );
288          $n .= "\n1;\n";          $n .= "\n1;\n";
289          #diag "normalize code:\n$n\n";          #diag "normalize code:\n$n\n";

Legend:
Removed from v.471  
changed lines
  Added in v.485

  ViewVC Help
Powered by ViewVC 1.1.26