--- trunk/t/3-normalize-set.t 2006/05/13 09:48:15 468 +++ trunk/t/3-normalize-set.t 2006/05/13 12:07:37 471 @@ -113,11 +113,31 @@ ok( defined(@_) ); } +# how much of string evaled to display? +my $max_eval_output = 170; + +sub dump_error { + my ($msg,$code) = @_; + + my @l = split(/[\n\r]/, $code); + my $out = "$msg\n"; + + foreach my $i ( 0 .. $#l ) { + $out .= sprintf("%2d: %s\n", $i, $l[$i]); + } + + return $out; +} + sub test_s { my $t = shift || die; - $t =~ s/[\n\r\s]+/ /gs; - ok(my $v = eval "$t", "eval: $t"); - ok(! $@, $@ ? "error: $@" : "no error"); + + my $eval_t = $t; + $eval_t =~ s/[\n\r\s]+/ /gs; + $eval_t = substr($eval_t,0,$max_eval_output) . '...' if (length($eval_t) > $max_eval_output); + + eval "$t"; + ok(! $@, $@ ? dump_error($@, $t) : "eval: $eval_t"); } { @@ -126,14 +146,16 @@ set_rec( $rec1 ); - cmp_ok( join(",", rec2('200','a') ), 'eq', '200a,200a*2' ); - cmp_ok( join(",", rec2('200','a'), rec2('200','b') ), 'eq', '200a,200a*2,200b' ); - cmp_ok( join(" * ", sort(rec1('200'), rec1('201') )), 'eq', '200a * 200a*2 * 200b * 200c * 200d * 200d*2 * 201x * 201y' ); + cmp_ok( join(",", rec2('200','a') ), 'eq', '200a,200a*2', 'join rec2' ); + cmp_ok( join(",", rec2('200','a'), rec2('200','b') ), 'eq', '200a,200a*2,200b', 'join rec2 rec2' ); + cmp_ok( join(" * ", sort(rec1('200'), rec1('201') )), 'eq', '200a * 200a*2 * 200b * 200c * 200d * 200d*2 * 201x * 201y', 'join sort rec1 rec1' ); + diag "is_deeply checks\n"; is_deeply( \[ rec1('200') ], \[ qw/200a 200b 200c 200d 200a*2 200d*2/ ] ); is_deeply( \[ regex( 's/0/o/g', rec1('200') ) ], \[ qw/2ooa 2oob 2ooc 2ood 2ooa*2 2ood*2/ ]); is_deeply( \[ grep { /\*/ } regex( 's/0/o/g', rec1('200') ) ], \[ qw/2ooa*2 2ood*2/ ]); is_deeply( \[ rec('902') ], \[ '900' ] ); - cmp_ok( rec('902'), 'eq', rec('902','z') ); + + cmp_ok( rec('902'), 'eq', rec('902','z'), 'rec sf' ); set_lookup( $lookup1 ); @@ -145,13 +167,13 @@ ) ) ), - 'eq', 'lookup 1 i lookup 2'); + 'eq', 'lookup 1 i lookup 2', 'join lookup regex rec2'); set_lookup( $lookup2 ); - is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ] ); + is_deeply( \[ lookup( prefix( '00', rec('902') ) ) ], \[ 'lookup' ], 'lookup prefix' ); - ok(! lookup('non-existent') ); + ok(! lookup('non-existent'), 'lookup non-existant' ); set_rec( $rec2 ); @@ -188,6 +210,17 @@ clean_ds(); + test_s(qq{ search('something', '42'); }); + test_s(qq{ search('empty', ''); }); + + ok($ds = get_ds(), 'get_ds'); + diag Dumper( $ds ) if ($debug); + + ok( $ds && $ds->{something}, 'get_ds->something' ); + ok( $ds && !$ds->{empty}, 'get_ds->empty' ); + + clean_ds(); + my $n = read_file( "$abs_path/data/normalize.pl" ); $n .= "\n1;\n"; #diag "normalize code:\n$n\n";