diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-05-16 23:22:22 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-05-16 23:22:22 +0000 |
commit | a8b15f586f8f9e40e4941ac4148dca6705ce744c (patch) | |
tree | 72bd95436e617c48410725cec6fe5b314c2a1c93 | |
parent | 89172b074ef8db7fbf9121ff13136c74ec102f29 (diff) |
More test coverage of LedgerSMB.pm and re-expression of round_amount
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1201 4979c152-3d1c-0410-bac9-87ea11338e46
-rwxr-xr-x | LedgerSMB.pm | 17 | ||||
-rw-r--r-- | t/02-number-handling.t | 31 | ||||
-rw-r--r-- | t/11-ledgersmb.t | 25 |
3 files changed, 66 insertions, 7 deletions
diff --git a/LedgerSMB.pm b/LedgerSMB.pm index 3581dfe7..c07276bb 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -410,12 +410,19 @@ sub round_amount { # These rounding rules follow from the previous implementation. # They should be changed to allow different rules for different accounts. - Math::BigFloat->round_mode('+inf') if $amount >= 0; - Math::BigFloat->round_mode('-inf') if $amount < 0; + if ($amount >= 0) { + Math::BigFloat->round_mode('+inf'); + } + else { + Math::BigFloat->round_mode('-inf'); + } - $amount = Math::BigFloat->new($amount)->ffround( -$places ) if $places >= 0; - $amount = Math::BigFloat->new($amount)->ffround( -( $places - 1 ) ) - if $places < 0; + if ($places >= 0) { + $amount = Math::BigFloat->new($amount)->ffround( -$places ); + } + else { + $amount = Math::BigFloat->new($amount)->ffround( -( $places - 1 ) ); + } return $amount; } diff --git a/t/02-number-handling.t b/t/02-number-handling.t index 23eb7fee..b26ed7e4 100644 --- a/t/02-number-handling.t +++ b/t/02-number-handling.t @@ -156,11 +156,38 @@ 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'"); + +# Triggers the $amount .= "\.$dec" if ($dec ne ""); check to false is($form->format_amount({'numberformat' => '1000.00'} , '1.00'), '1', - "form: 1.00 with no precision or dash"); + "form: 1.00 with no precision or dash (1000.00)"); is($lsmb->format_amount('user' => {'numberformat' => '1000.00'}, 'amount' => '1.00'), '1', - "lsmb: 1.00 with no precision or dash"); + "lsmb: 1.00 with no precision or dash (1000.00)"); +is($form->format_amount({'numberformat' => '1,000.00'} , '1.00'), '1', + "form: 1.00 with no precision or dash (1,000.00)"); +is($lsmb->format_amount('user' => {'numberformat' => '1,000.00'}, + 'amount' => '1.00'), '1', + "lsmb: 1.00 with no precision or dash (1,000.00)"); +is($form->format_amount({'numberformat' => '1 000.00'} , '1.00'), '1', + "form: 1.00 with no precision or dash (1 000.00)"); +is($lsmb->format_amount('user' => {'numberformat' => '1 000.00'}, + 'amount' => '1.00'), '1', + "lsmb: 1.00 with no precision or dash (1 000.00)"); +is($form->format_amount({'numberformat' => '1\'000.00'} , '1.00'), '1', + "form: 1.00 with no precision or dash (1'000.00)"); +is($lsmb->format_amount('user' => {'numberformat' => '1\'000.00'}, + 'amount' => '1.00'), '1', + "lsmb: 1.00 with no precision or dash (1'000.00)"); +is($form->format_amount({'numberformat' => '1.000,00'} , '1,00'), '1', + "form: 1,00 with no precision or dash (1.000,00)"); +is($lsmb->format_amount('user' => {'numberformat' => '1.000,00'}, + 'amount' => '1,00'), '1', + "lsmb: 1,00 with no precision or dash (1.000,00)"); +is($form->format_amount({'numberformat' => '1000,00'} , '1,00'), '1', + "form: 1,00 with no precision or dash (1000,00)"); +is($lsmb->format_amount('user' => {'numberformat' => '1000,00'}, + 'amount' => '1,00'), '1', + "lsmb: 1,00 with no precision or dash (1000,00)"); 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'}, diff --git a/t/11-ledgersmb.t b/t/11-ledgersmb.t index 881ebc48..9ab8196f 100644 --- a/t/11-ledgersmb.t +++ b/t/11-ledgersmb.t @@ -249,3 +249,28 @@ is($lsmb->{apple}, 1, 'merge: No key, added apple'); is($lsmb->{pear}, 2, 'merge: No key, added pear'); is($lsmb->{peach}, 3, 'merge: No key, added peach'); like($lsmb->{path}, qr#bin/(lynx|mozilla)#, 'merge: No key, left existing key'); + +$lsmb = new LedgerSMB; +$lsmb->merge({'apple' => 1, 'pear' => 2, 'peach' => 3}, 'index' => 1); +is($lsmb->{apple_1}, 1, 'merge: Index 1, added apple as apple_1'); +is($lsmb->{pear_1}, 2, 'merge: Index 1, added pear as pear_1'); +is($lsmb->{peach_1}, 3, 'merge: Index 1, added peach as peach_1'); +like($lsmb->{path}, qr#bin/(lynx|mozilla)#, 'merge: Index 1, left existing key'); + +# $lsmb->is_allowed_role checks +$lsmb = new LedgerSMB; +$lsmb->{_roles} = ('apple', 'pear'); +is($lsmb->is_allowed_role('allowed_roles' => ['pear']), 1, + 'is_allowed_role: allowed role'); + +TODO: { + local $TODO = 'role system unimplemented'; + $lsmb->{_roles} = ['apple', 'pear']; + is($lsmb->is_allowed_role('allowed_roles' => ['peach']), 0, + 'is_allowed_role: disallowed role'); + is($lsmb->is_allowed_role('allowed_roles' => []), 0, + 'is_allowed_role: no allowable roles'); + delete $lsmb->{_roles}; + is($lsmb->is_allowed_role('allowed_roles' => ['apple']), 0, + 'is_allowed_role: no roles for user'); +} |