summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2006-10-27 17:49:12 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2006-10-27 17:49:12 +0000
commit43c31cb5209a8f6bb2702057b7c51734d7c87af4 (patch)
tree678674888a4a351f677684ab7893cb21e2befe26
parent934b46358fb4ee2d001d725215c5fb0d0f8943ac (diff)
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
-rw-r--r--t/02-number-handling.t24
1 files changed, 16 insertions, 8 deletions
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,