[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [1196] trunk
- Subject: SF.net SVN: ledger-smb: [1196] trunk
- From: ..hidden..
- Date: Mon, 14 May 2007 22:28:26 -0700
Revision: 1196
http://svn.sourceforge.net/ledger-smb/?rev=1196&view=rev
Author: tetragon
Date: 2007-05-14 22:28:25 -0700 (Mon, 14 May 2007)
Log Message:
-----------
More tests, including some version consistency ones
Modified Paths:
--------------
trunk/LedgerSMB.pm
trunk/t/02-number-handling.t
trunk/t/11-ledgersmb.t
Added Paths:
-----------
trunk/t/99-versioning.t
Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm 2007-05-15 01:39:48 UTC (rev 1195)
+++ trunk/LedgerSMB.pm 2007-05-15 05:28:25 UTC (rev 1196)
@@ -1,4 +1,3 @@
-
=head1 NAME
LedgerSMB The Base class for many LedgerSMB objects, including DBObject.
@@ -351,7 +350,6 @@
if ( $dash eq "0" && $places ) {
- #if ( $myconfig->{numberformat} eq '1.000,00' ) {
if ( $myconfig->{numberformat} =~ /0,00$/ ) {
$amount = "0" . "," . "0" x $places;
}
Modified: trunk/t/02-number-handling.t
===================================================================
--- trunk/t/02-number-handling.t 2007-05-15 01:39:48 UTC (rev 1195)
+++ trunk/t/02-number-handling.t 2007-05-15 05:28:25 UTC (rev 1196)
@@ -82,6 +82,22 @@
}
}
+foreach my $format (0 .. $#formats) {
+ %myconfig = (numberformat => $formats[$format][0]);
+ my $thou = $formats[$format][1];
+ my $dec = $formats[$format][2];
+ my $rawValue = '6d00';
+ $expected = $rawValue;
+ $expected =~ s/d/$dec/gx;
+ my $value = $form->parse_amount(\%myfooconfig, '6');
+ is($form->format_amount(\%myconfig, $value, 2, '0'), $expected,
+ "form: $value formatted as $formats[$format][0] - $expected");
+ is($lsmb->format_amount('user' => \%myconfig,
+ 'amount' => $value, 'precision' => 2,
+ 'neg_format' => '0'), $expected,
+ "lsmb: $value formatted as $formats[$format][0] - $expected");
+}
+
$expected = $form->parse_amount({'numberformat' => '1000.00'}, '0.00');
is($form->format_amount({'numberformat' => '1000.00'} , $expected, 2, 'x'), 'x',
"form: 0.00 with dash x");
@@ -89,6 +105,57 @@
'amount' => $expected, 'precision' => 2,
'neg_format' => 'x'), 'x',
"lsmb: 0.00 with dash x");
+is($form->format_amount({'numberformat' => '1000.00'} , $expected, 2, ''), '',
+ "form: 0.00 with dash ''");
+is($lsmb->format_amount('user' => {'numberformat' => '1000.00'},
+ 'amount' => $expected, 'precision' => 2,
+ 'neg_format' => ''), '',
+ "lsmb: 0.00 with dash ''");
+is($form->format_amount({'numberformat' => '1000.00'} , $expected, 2), '',
+ "form: 0.00 with undef dash");
+is($lsmb->format_amount('user' => {'numberformat' => '1000.00'},
+ 'amount' => $expected, 'precision' => 2), '',
+ "lsmb: 0.00 with undef dash");
+is($form->format_amount({'apples' => '1000.00'} , 'foo', 2), 'NaN',
+ "form: No numberformat set, invalid amount");
+is($lsmb->format_amount('user' => {'apples' => '1000.00'},
+ 'amount' => 'foo', 'precision' => 2), 'NaN',
+ "lsmb: No numberformat set, invalid amount");
+cmp_ok($form->format_amount({'apples' => '1000.00'} , '1.00', 2), '==', 1,
+ "form: No numberformat set, valid amount");
+cmp_ok($lsmb->format_amount('user' => {'apples' => '1000.00'},
+ 'amount' => '1.00', 'precision' => 2), '==', 1,
+ "lsmb: No numberformat set, valid amount");
+is($form->format_amount({'numberformat' => '1000.00'} , '-1.00', 2, '-'), '(1.00)',
+ "form: -1.00 with dash '-'");
+is($lsmb->format_amount('user' => {'numberformat' => '1000.00'},
+ 'amount' => '-1.00', 'precision' => 2, 'neg_format' => '-'), '(1.00)',
+ "lsmb: -1.00 with dash '-'");
+is($form->format_amount({'numberformat' => '1000.00'} , '1.00', 2, '-'), '1.00',
+ "form: 1.00 with dash '-'");
+is($lsmb->format_amount('user' => {'numberformat' => '1000.00'},
+ 'amount' => '1.00', 'precision' => 2, 'neg_format' => '-'), '1.00',
+ "lsmb: 1.00 with dash '-'");
+is($form->format_amount({'numberformat' => '1000.00'} , '-1.00', 2, 'DRCR'),
+ '1.00 DR', "form: -1.00 with dash DRCR");
+is($lsmb->format_amount('user' => {'numberformat' => '1000.00'},
+ 'amount' => '-1.00', 'precision' => 2, 'neg_format' => 'DRCR'),
+ '1.00 DR', "lsmb: -1.00 with dash DRCR");
+is($form->format_amount({'numberformat' => '1000.00'} , '1.00', 2, 'DRCR'),
+ '1.00 CR', "form: 1.00 with dash DRCR");
+is($lsmb->format_amount('user' => {'numberformat' => '1000.00'},
+ 'amount' => '1.00', 'precision' => 2, 'neg_format' => 'DRCR'),
+ '1.00 CR', "lsmb: 1.00 with dash DRCR");
+is($form->format_amount({'numberformat' => '1000.00'} , '-1.00', 2, 'x'), '-1.00',
+ "form: -1.00 with dash 'x'");
+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', 2, 'x'), '1.00',
+ "form: 1.00 with dash 'x'");
+is($lsmb->format_amount('user' => {'numberformat' => '1000.00'},
+ 'amount' => '1.00', 'precision' => 2, 'neg_format' => 'x'), '1.00',
+ "lsmb: 1.00 with dash 'x'");
foreach my $format (0 .. $#formats) {
%myconfig = (numberformat => $formats[$format][0]);
Modified: trunk/t/11-ledgersmb.t
===================================================================
--- trunk/t/11-ledgersmb.t 2007-05-15 01:39:48 UTC (rev 1195)
+++ trunk/t/11-ledgersmb.t 2007-05-15 05:28:25 UTC (rev 1196)
@@ -2,6 +2,9 @@
use strict;
use warnings;
+
+$ENV{TMPDIR} = 't/var';
+
use Test::More 'no_plan';
use Test::Exception;
use Test::Trap qw(trap $trap);
@@ -129,3 +132,41 @@
is(unlink("t/var/lsmb-11.$$"), 1, "debug: removing t/var/lsmb-11.$$");
ok(!-e "t/var/lsmb-11.$$", "debug: t/var/lsmb-11.$$ removed");
};
+
+# $lsmb->new checks
+$lsmb = new LedgerSMB;
+ok(defined $lsmb, 'new: blank, defined');
+isa_ok($lsmb, 'LedgerSMB', 'new: blank, correct type');
+ok(defined $lsmb->{action}, 'new: blank, action defined');
+ok(defined $lsmb->{dbversion}, 'new: blank, dbversion defined');
+ok(defined $lsmb->{path}, 'new: blank, path defined');
+ok(defined $lsmb->{version}, 'new: blank, version defined');
+
+$lsmb = new LedgerSMB('action=Apple%20sauce');
+ok(defined $lsmb, 'new: action set, defined');
+isa_ok($lsmb, 'LedgerSMB', 'new: action set, correct type');
+ok(defined $lsmb->{action}, 'new: action set, action defined');
+is($lsmb->{action}, 'apple_sauce', 'new: action set, action processed');
+ok(defined $lsmb->{dbversion}, 'new: action set, dbversion defined');
+ok(defined $lsmb->{path}, 'new: action set, path defined');
+ok(defined $lsmb->{version}, 'new: action set, version defined');
+
+$lsmb = new LedgerSMB('path=bin/lynx');
+ok(defined $lsmb, 'new: lynx, defined');
+isa_ok($lsmb, 'LedgerSMB', 'new: lynx, correct type');
+ok(defined $lsmb->{action}, 'new: lynx, action defined');
+ok(defined $lsmb->{dbversion}, 'new: lynx, dbversion defined');
+ok(defined $lsmb->{path}, 'new: lynx, path defined');
+is($lsmb->{path}, 'bin/lynx', 'new: lynx, path carried through');
+ok(defined $lsmb->{lynx}, 'new: lynx, lynx defined');
+is($lsmb->{lynx}, 1, 'new: lynx, lynx enabled');
+ok(defined $lsmb->{menubar}, 'new: lynx, menubar defined (deprecated)');
+is($lsmb->{menubar}, 1, 'new: lynx, menubar enabled (deprecated)');
+ok(defined $lsmb->{version}, 'new: lynx, version defined');
+
+TODO: {
+ local $TODO = 'Error handling for LedgerSMB';
+ @r = trap{new LedgerSMB('script=foo/bar.pl')};
+ is($trap->die, "Error: Access Denied\n",
+ 'new: directory traversal caught');
+}
Added: trunk/t/99-versioning.t
===================================================================
--- trunk/t/99-versioning.t (rev 0)
+++ trunk/t/99-versioning.t 2007-05-15 05:28:25 UTC (rev 1196)
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 17;
+
+use LedgerSMB;
+use LedgerSMB::Form;
+
+my $lsmb = new LedgerSMB;
+ok(defined $lsmb, 'lsmb: defined');
+isa_ok($lsmb, 'LedgerSMB', 'lsmb: correct type');
+ok(defined $lsmb->{version}, 'lsmb: version set');
+ok(defined $lsmb->{dbversion}, 'lsmb: dbversion set');
+
+my $form = new Form;
+ok(defined $form, 'form: defined');
+isa_ok($form, 'Form', 'form: correct type');
+ok(defined $form->{version}, 'form: version set');
+ok(defined $form->{dbversion}, 'form: dbversion set');
+
+is($lsmb->{version}, $form->{version}, 'LedgerSMB and Form versions match');
+is($lsmb->{dbversion}, $form->{dbversion}, 'LedgerSMB and Form dbversions match');
+
+ok(-e 'VERSION', 'VERSION exists');
+ok(-s 'VERSION', 'VERSION non-empty');
+ok(-r 'VERSION', 'VERSION readable');
+open(my $FH, '<', 'VERSION');
+my $ver = readline $FH;
+close $FH;
+chomp $ver;
+is($lsmb->{version}, $ver, 'LedgerSMB version matches VERSION');
+is($form->{version}, $ver, 'Form version matches VERSION');
+
+SKIP: {
+ skip 'LedgerSMB is trunk', 1 if $lsmb->{version} =~ /trunk$/i;
+ cmp_ok($lsmb->{version}, '>=', $lsmb->{dbversion},
+ 'lsmb: version >= dbversion');
+}
+SKIP: {
+ skip 'Form is trunk', 1 if $form->{version} =~ /trunk$/i;
+ cmp_ok($form->{version}, '>=', $form->{dbversion},
+ 'form: version >= dbversion');
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.