diff options
Diffstat (limited to 't')
-rw-r--r-- | t/02-number-handling.t | 19 | ||||
-rw-r--r-- | t/11-ledgersmb.t | 27 | ||||
-rw-r--r-- | t/99-versioning.t | 4 |
3 files changed, 48 insertions, 2 deletions
diff --git a/t/02-number-handling.t b/t/02-number-handling.t index 6d38de27..23eb7fee 100644 --- a/t/02-number-handling.t +++ b/t/02-number-handling.t @@ -156,6 +156,21 @@ is($form->format_amount({'numberformat' => '1000.00'} , '1.00', 2, 'x'), '1.00', is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, 'amount' => '1.00', 'precision' => 2, 'neg_format' => 'x'), '1.00', "lsmb: 1.00 with dash 'x'"); +is($form->format_amount({'numberformat' => '1000.00'} , '1.00'), '1', + "form: 1.00 with no precision or dash"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '1.00'), '1', + "lsmb: 1.00 with no precision or dash"); +is($form->format_amount({'numberformat' => '1000.00'} , '1.50'), '1.5', + "form: 1.50 with no precision or dash"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '1.50'), '1.5', + "lsmb: 1.50 with no precision or dash"); +is($form->format_amount({'numberformat' => '1000.00'} , '0.0', undef, '0'), '0', + "form: 0.0 with no precision, dash '0'"); +is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, + 'amount' => '0.0', 'neg_format' => '0'), '0', + "lsmb: 0.0 with no precision, dash '0'"); foreach my $format (0 .. $#formats) { %myconfig = (numberformat => $formats[$format][0]); @@ -287,8 +302,12 @@ foreach my $format (0 .. $#formats) { cmp_ok($form->parse_amount(\%myconfig, ''), '==', 0, "form: Empty string returns 0"); + cmp_ok($form->parse_amount(\%myconfig), '==', 0, + "form: undef string returns 0"); cmp_ok($form->parse_amount(\%myconfig, 'foo'), 'eq', Math::BigFloat->bnan(), "form: Invalid string returns NaN"); + cmp_ok($lsmb->parse_amount('user' => \%myconfig), '==', 0, + "lsmb: undef string returns 0"); cmp_ok($lsmb->parse_amount('user' => \%myconfig, 'amount' => ''), '==', 0, "lsmb: Empty string returns 0"); cmp_ok($lsmb->parse_amount('user' => \%myconfig, 'amount' => 'foo'), 'eq', diff --git a/t/11-ledgersmb.t b/t/11-ledgersmb.t index ff388742..b91ca3b8 100644 --- a/t/11-ledgersmb.t +++ b/t/11-ledgersmb.t @@ -12,6 +12,10 @@ use Math::BigFloat; use LedgerSMB; +sub redirect { + print "redirected\n"; +} + ##line subroutine ##108 new ##235 redirect @@ -133,6 +137,12 @@ SKIP: { ok(!-e "t/var/lsmb-11.$$", "debug: t/var/lsmb-11.$$ removed"); }; +$lsmb->{file} = 't/this is a bad directory, I do not exist/foo'; +@r = trap {$lsmb->debug('file' => $lsmb->{file}, $lsmb)}; +like($trap->die, qr/No such file or directory at LedgerSMB\.pm/, + "debug: open failure causes death"); +ok(!-e $lsmb->{file}, "debug: file creation failed"); + # $lsmb->new checks $lsmb = new LedgerSMB; ok(defined $lsmb, 'new: blank, defined'); @@ -170,3 +180,20 @@ TODO: { is($trap->die, "Error: Access Denied\n", 'new: directory traversal caught'); } + +# $lsmb->redirect checks +$lsmb = new LedgerSMB; +ok(!defined $lsmb->{callback}, 'redirect: No callback set'); +@r = trap{$lsmb->redirect}; +is($trap->stdout, "redirected\n", 'redirect: No message or callback redirect'); +TODO: { + local $TODO = '$lsmb->info for LedgerSMB'; + @r = trap{$lsmb->redirect('msg' => 'hello world')}; + is($trap->stdout, "hello world\n", + 'redirect: message, no callback redirect'); +} +$lsmb->{callback} = 1; +@r = trap{$lsmb->redirect}; +is($trap->stdout, "redirected\n", 'redirect: callback, no message redirect'); +@r = trap{$lsmb->redirect('msg' => "hello world\n")}; +is($trap->stdout, "redirected\n", 'redirect: callback and message redirect'); diff --git a/t/99-versioning.t b/t/99-versioning.t index e8e18469..d1b833c5 100644 --- a/t/99-versioning.t +++ b/t/99-versioning.t @@ -35,11 +35,11 @@ is($form->{version}, $ver, 'Form version matches VERSION'); SKIP: { skip 'LedgerSMB is trunk', 1 if $lsmb->{version} =~ /trunk$/i; - cmp_ok($lsmb->{version}, '>=', $lsmb->{dbversion}, + cmp_ok($lsmb->{version}, 'ge', $lsmb->{dbversion}, 'lsmb: version >= dbversion'); } SKIP: { skip 'Form is trunk', 1 if $form->{version} =~ /trunk$/i; - cmp_ok($form->{version}, '>=', $form->{dbversion}, + cmp_ok($form->{version}, 'ge', $form->{dbversion}, 'form: version >= dbversion'); } |