[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1198] trunk



Revision: 1198
          http://svn.sourceforge.net/ledger-smb/?rev=1198&view=rev
Author:   tetragon
Date:     2007-05-15 14:41:26 -0700 (Tue, 15 May 2007)

Log Message:
-----------
Number parsing fix for LedgerSMB.pm and more test cases

Modified Paths:
--------------
    trunk/LedgerSMB.pm
    trunk/t/02-number-handling.t
    trunk/t/11-ledgersmb.t
    trunk/t/99-versioning.t

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2007-05-15 18:33:12 UTC (rev 1197)
+++ trunk/LedgerSMB.pm	2007-05-15 21:41:26 UTC (rev 1198)
@@ -373,7 +373,7 @@
     my $myconfig = $args{user};
     my $amount   = $args{amount};
 
-    if ( $amount eq '' or $amount == undef ) {
+    if ( $amount eq '' or ! defined $amount) {
         return 0;
     }
 

Modified: trunk/t/02-number-handling.t
===================================================================
--- trunk/t/02-number-handling.t	2007-05-15 18:33:12 UTC (rev 1197)
+++ trunk/t/02-number-handling.t	2007-05-15 21:41:26 UTC (rev 1198)
@@ -156,6 +156,21 @@
 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 @@
 
 	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',

Modified: trunk/t/11-ledgersmb.t
===================================================================
--- trunk/t/11-ledgersmb.t	2007-05-15 18:33:12 UTC (rev 1197)
+++ trunk/t/11-ledgersmb.t	2007-05-15 21:41:26 UTC (rev 1198)
@@ -12,6 +12,10 @@
 
 use LedgerSMB;
 
+sub redirect {
+	print "redirected\n";
+}
+
 ##line	subroutine
 ##108	new
 ##235	redirect
@@ -133,6 +137,12 @@
 	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';
..hidden.. = 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 @@
 	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');
..hidden.. = 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;
..hidden.. = trap{$lsmb->redirect};
+is($trap->stdout, "redirected\n", 'redirect: callback, no message redirect');
..hidden.. = trap{$lsmb->redirect('msg' => "hello world\n")};
+is($trap->stdout, "redirected\n", 'redirect: callback and message redirect');

Modified: trunk/t/99-versioning.t
===================================================================
--- trunk/t/99-versioning.t	2007-05-15 18:33:12 UTC (rev 1197)
+++ trunk/t/99-versioning.t	2007-05-15 21:41:26 UTC (rev 1198)
@@ -35,11 +35,11 @@
 
 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');
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.