From 43c31cb5209a8f6bb2702057b7c51734d7c87af4 Mon Sep 17 00:00:00 2001 From: tetragon Date: Fri, 27 Oct 2006 17:49:12 +0000 Subject: Update tests for parsing new format: (n) is negative git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@336 4979c152-3d1c-0410-bac9-87ea11338e46 --- t/02-number-handling.t | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 't/02-number-handling.t') diff --git a/t/02-number-handling.t b/t/02-number-handling.t index 0bc786da..d75fda3d 100644 --- a/t/02-number-handling.t +++ b/t/02-number-handling.t @@ -45,7 +45,7 @@ my @formats = (['1,000.00', ',', '.'], ["1'000.00", "'", '.'], ['1.000,00', '.', ','], ['1000,00', '', ','], ['1000.00', '', '.'], ['1 000.00', ' ', '.']); my %myfooconfig = (numberformat => '1000.00'); -foreach my $format (0 .. 5) { +foreach my $format (0 .. $#formats) { %myconfig = (numberformat => $formats[$format][0]); my $thou = $formats[$format][1]; my $dec = $formats[$format][2]; @@ -64,7 +64,7 @@ foreach my $format (0 .. 5) { } } -foreach my $format (0 .. 5) { +foreach my $format (0 .. $#formats) { %myconfig = (numberformat => $formats[$format][0]); my $thou = $formats[$format][1]; my $dec = $formats[$format][2]; @@ -86,37 +86,45 @@ foreach my $format (0 .. 5) { } } -foreach my $format (0 .. 5) { +foreach my $format (0 .. $#formats) { %myconfig = ('numberformat' => $formats[$format][0]); my $thou = $formats[$format][1]; my $dec = $formats[$format][2]; foreach my $rawValue ('10t000d00', '9t999d99', '333d33', - '7t777t777d77', '-12d34') { + '7t777t777d77', '-12d34', '(76t543d21)') { $expected = $rawValue; $expected =~ s/t/$thou/gx; $expected =~ s/d/$dec/gx; my $value = $rawValue; $value =~ s/t//gx; $value =~ s/d/\./gx; - $value = sprintf("%.2f", $value); + if ($value =~ m/^\(/gx) { + $value = Math::BigFloat->new('-'.substr($value, 1, -1)); + } else { + $value = Math::BigFloat->new($value); + } cmp_ok($form->parse_amount(\%myconfig, $expected), '==', $value, "$expected parsed as $formats[$format][0] - $value"); } } -foreach my $format (0 .. 5) { +foreach my $format (0 .. $#formats) { %myconfig = ('numberformat' => $formats[$format][0]); my $thou = $formats[$format][1]; my $dec = $formats[$format][2]; foreach my $rawValue ('10t000d00', '9t999d99', '333d33', - '7t777t777d77', '-12d34') { + '7t777t777d77', '-12d34', '(76t543d21)') { $expected = $rawValue; $expected =~ s/t/$thou/gx; $expected =~ s/d/$dec/gx; my $value = $rawValue; $value =~ s/t//gx; $value =~ s/d/\./gx; - $value = sprintf("%.2f", $value); + if ($value =~ m/^\(/gx) { + $value = Math::BigFloat->new('-'.substr($value, 1, -1)); + } else { + $value = Math::BigFloat->new($value); + } cmp_ok($form->parse_amount(\%myconfig, $form->parse_amount(\%myconfig, $expected)), '==', $value, -- cgit v1.2.3