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

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



Revision: 4755
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4755&view=rev
Author:   einhverfr
Date:     2012-05-23 01:00:36 +0000 (Wed, 23 May 2012)
Log Message:
-----------
All number tests passing again

Modified Paths:
--------------
    trunk/LedgerSMB/PGNumber.pm
    trunk/t/02-number-handling.t

Modified: trunk/LedgerSMB/PGNumber.pm
===================================================================
--- trunk/LedgerSMB/PGNumber.pm	2012-05-22 14:51:22 UTC (rev 4754)
+++ trunk/LedgerSMB/PGNumber.pm	2012-05-23 01:00:36 UTC (rev 4755)
@@ -62,71 +62,16 @@
 =cut
 
 our $lsmb_formats = {
-      "1000.00" => { thousands_sep => '',  decimal_sep => '.', 
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => '',
-                                                     -decimal_point => '.',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
+      "1000.00" => { thousands_sep => '',  decimal_sep => '.' },
 
-      "1000,00" => { thousands_sep => '',  decimal_sep => ',' ,
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => '',
-                                                     -decimal_point => ',',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
+      "1000,00" => { thousands_sep => '',  decimal_sep => ',' },
+     "1 000.00" => { thousands_sep => ' ', decimal_sep => '.' },
+     "1 000,00" => { thousands_sep => ' ', decimal_sep => ',' },
+     "1,000.00" => { thousands_sep => ',', decimal_sep => '.' },
+     "1.000,00" => { thousands_sep => '.', decimal_sep => ',' },
+     "1'000,00" => { thousands_sep => "'", decimal_sep => ',' },
+     "1'000.00" => { thousands_sep => "'", decimal_sep => '.' },
 
-     "1 000.00" => { thousands_sep => ' ', decimal_sep => '.' ,
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => ' ',
-                                                     -decimal_point => '.',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
-
-     "1 000,00" => { thousands_sep => ' ', decimal_sep => ',' ,
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => ' ',
-                                                     -decimal_point => ',',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
-
-     "1,000.00" => { thousands_sep => ',', decimal_sep => '.' ,
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => ',',
-                                                     -decimal_point => '.',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
-
-     "1.000,00" => { thousands_sep => '.', decimal_sep => ',' ,
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => '.',
-                                                     -decimal_point => ',',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
-
-     "1'000,00" => { thousands_sep => "'", decimal_sep => ',' ,
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => "'",
-                                                     -decimal_point => ',',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
-
-     "1'000.00" => { thousands_sep => "'", decimal_sep => '.' ,
-                         formatter => sub { return Number::Format::new(
-                                                     -thousands_sep => "'",
-                                                     -decimal_point => '.',
-                                                        -neg_format => 'x'
-                                                    ); }
-                    },
-
-
 };
 
 =back
@@ -175,6 +120,10 @@
 sub from_input {
     my $self   = shift @_;
     my $string = shift @_;
+    my %args   = (ref($_[0]) eq 'HASH')? %{$_[0]}: @_;  
+    my $format = ($args{format}) ? $args{format}
+                              : $LedgerSMB::App_State::User->{numberformat};
+    die 'LedgerSMB::PGNumber No Format Set' if !$format;
     return undef if !defined $string;
     my $negate;
     my $pgnum;
@@ -187,12 +136,10 @@
     if (UNIVERSAL::isa( $string, 'Math::BigFloat' ) ) {
         $pgnum = $string; 
     } else {
-        my %args   = (ref($_[0]) eq 'HASH')? %{$_[0]}: @_;  
-        my $format = ($args{format}) ? $args{format}
-                              : $LedgerSMB::App_State::User->{numberformat};
-        die 'LedgerSMB::PGNumber No Format Set' if !$format;
-        die "bad format: $format" if !$lsmb_formats->{$format};
-        my $formatter = &$lsmb_formats->{$format}->{formatter};
+        my $formatter = new Number::Format(
+                    -thousands_sep => $lsmb_formats->{$format}->{thousands_sep},
+                    -decimal_point => $lsmb_formats->{$format}->{decimal_sep},
+        );
         $newval = $formatter->unformat_number($string);
         $pgnum = Math::BigFloat->new($newval);
         $self->round_mode('+inf');
@@ -247,16 +194,14 @@
     $places = 0 unless defined $places and ($places > 0);
     my $zfill = ($places > 0) ? 1 : 0;
     $dplaces = 10 unless defined $dplaces;
-    my $ts = $lsmb_formats->{$format}->{thousands_sep};
-    
-    die "bad format: $format" if !$lsmb_formats->{$format};
-    warn $format;
-    warn &{$lsmb_formats->{$format}->{formatter}};
-    my $formatter = &$lsmb_formats->{$format}->{formatter};
+    my $formatter = new Number::Format(
+                    -thousands_sep => $lsmb_formats->{$format}->{thousands_sep},
+                    -decimal_point => $lsmb_formats->{$format}->{decimal_sep},
+                     -decimal_fill => $zfill,
+                       -neg_format => 'x');   
     $str = $formatter->format_number($str, $dplaces);
 
-    my $neg_format = (defined $args{neg_format}) ? $args{neg_format} : 'def';
-    $neg_format = 'def' unless $neg_format eq 'paren' or $neg_format eq 'DRCR';
+    my $neg_format = ($args{neg_format}) ? $args{neg_format} : 'def';
     my $fmt = ($is_neg) ? $lsmb_neg_formats->{$neg_format}->{neg}
                         : $lsmb_neg_formats->{$neg_format}->{pos};
    

Modified: trunk/t/02-number-handling.t
===================================================================
--- trunk/t/02-number-handling.t	2012-05-22 14:51:22 UTC (rev 4754)
+++ trunk/t/02-number-handling.t	2012-05-23 01:00:36 UTC (rev 4755)
@@ -25,6 +25,17 @@
 ok(defined $lsmb);
 isa_ok($lsmb, 'LedgerSMB');
 
..hidden.. = trap{$form->format_amount({'apples' => '1000.00'}, 'foo', 2)};
+is($trap->exit, undef,
+	'form: No numberformat set, invalid amount (NaN check)');
+cmp_ok($trap->die, '=~', $no_format_message,
+	'form: No numberformat set, invalid amount message (NaN check)');
..hidden.. = trap{$lsmb->format_amount('user' => {'apples' => '1000.00'},
+	'amount' => 'foo', 'precision' => 2)};
+is($trap->exit, undef,
+	'lsmb: No numberformat set, invalid amount (NaN check)');
+cmp_ok($trap->die, , '=~', $no_format_message,
+	'lsmb: No numberformat set, invalid amount message (NaN check)');
 my $expected;
 foreach my $value ('0.01', '0.05', '0.015', '0.025', '1.1', '1.5', '1.9', 
 		'10.01', '4', '5', '5.1', '5.4', '5.5', '5.6', '6', '0', 
@@ -186,17 +197,6 @@
 $ENV{GATEWAY_INTERFACE} = 'yes';
 $form->{pre} = 'Blah';
 $form->{header} = 'Blah';
..hidden.. = trap{$form->format_amount({'apples' => '1000.00'}, 'foo', 2)};
-is($trap->exit, undef,
-	'form: No numberformat set, invalid amount (NaN check)');
-cmp_ok($trap->die, '=~', $no_format_message,
-	'form: No numberformat set, invalid amount message (NaN check)');
..hidden.. = trap{$lsmb->format_amount('user' => {'apples' => '1000.00'},
-	'amount' => 'foo', 'precision' => 2)};
-is($trap->exit, undef,
-	'lsmb: No numberformat set, invalid amount (NaN check)');
-cmp_ok($trap->die, , '=~', $no_format_message,
-	'lsmb: No numberformat set, invalid amount message (NaN check)');
 is($form->format_amount({'numberformat' => '1000.00'} , '-1.00', 2, 'paren'), '(1.00)',
 	"form: -1.00 with dash '-'");
 is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, 

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