[gnumeric] Tests: csv number format tests
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Tests: csv number format tests
- Date: Fri, 20 May 2016 02:44:48 +0000 (UTC)
commit 6a8ec4b11d383feb5c0158fe20a644fdae2bd3ec
Author: Morten Welinder <terra gnome org>
Date: Thu May 19 22:44:30 2016 -0400
Tests: csv number format tests
test/GnumericTest.pm | 39 +++++++++++++++++++++++++++++---
test/Makefile.am | 1 +
test/t5801-cvs-number.pl | 55 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 91 insertions(+), 4 deletions(-)
---
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index b138f72..ff927ea 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -521,12 +521,43 @@ sub test_csv_format_guessing {
}
my $guessed = $1;
- local $_ = $guessed;
- if (!&{$args{'format'}} ($_)) {
+ my $ok;
+ {
+ local $_ = $guessed;
+ $ok = &{$args{'format'}} ($_);
+ }
+
+ if ($verbose || !$ok) {
+ print STDERR "Data:\n";
foreach (split ("\n", $data)) {
- print "| $_\n";
+ print STDERR "| $_\n";
+ }
+ print STDERR "Result:\n";
+ foreach (split ("\n", $out)) {
+ print STDERR "| $_\n";
+ }
+ }
+
+ die "Guessed wrong format: $guessed\n" unless $ok;
+
+ if (exists $args{'decimal'}) {
+ if ($out !~ m/^\s*fmt\.0\.dec\s*=\s*(\S+)\s*$/m) {
+ die "Failed to guess any decimal separator\n";
}
- die "Guessed wrong format: $guessed\n";
+ my $guessed = $1;
+ my $ok = ($1 eq $args{'decimal'});
+
+ die "Guessed wrong decimal separator: $guessed\n" unless $ok;
+ }
+
+ if (exists $args{'thousand'}) {
+ if ($out !~ m/^\s*fmt\.0\.thou\s*=\s*(\S+)\s*$/m) {
+ die "Failed to guess any thousands separator\n";
+ }
+ my $guessed = $1;
+ my $ok = ($1 eq $args{'thousand'});
+
+ die "Guessed wrong thousands separator: $guessed\n" unless $ok;
}
&removejunk ($outfn) unless $keep;
diff --git a/test/Makefile.am b/test/Makefile.am
index 15ed3b9..e391fb0 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -60,6 +60,7 @@ TESTS = t1000-statfuns.pl \
t2004-insdel-colrow.pl \
t2800-style-optimizer.pl \
t5800-csv-date.pl \
+ t5801-csv-number.pl \
t5900-sc.pl \
t5901-qpro.pl \
t5902-applix.pl \
diff --git a/test/t5801-cvs-number.pl b/test/t5801-cvs-number.pl
new file mode 100755
index 0000000..7edc759
--- /dev/null
+++ b/test/t5801-cvs-number.pl
@@ -0,0 +1,55 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+&message ("Check the csv importer.");
+
+&test_csv_format_guessing
+ (data => <<DATA, format => sub { return $_ eq '0.00'; }, decimal => '.' );
+"Values"
+"123.45"
+"1.45"
+DATA
+
+&test_csv_format_guessing
+ (data => <<DATA, format => sub { return $_ eq 'General'; }, decimal => '.' );
+"Values"
+"123.456"
+"1.45"
+DATA
+
+&test_csv_format_guessing
+ (data => <<DATA, format => sub { return $_ eq 'General'; } );
+"Values"
+"123.456"
+"234,567"
+DATA
+
+&test_csv_format_guessing
+ (data => <<DATA, format => sub { return $_ eq '0.000'; }, decimal => ',' );
+"Values"
+"0,456"
+DATA
+
+&test_csv_format_guessing
+ (data => <<DATA, format => sub { return $_ eq '0.000'; }, decimal => ',' );
+"Values"
+"-,456"
+DATA
+
+&test_csv_format_guessing
+ (data => <<DATA, format => sub { return $_ eq '#,##0.00'; }, decimal => '.', thousand => ',' );
+"Values"
+"100,456.22"
+DATA
+
+&test_csv_format_guessing
+ (data => <<DATA, format => sub { return $_ eq '#,##0.000'; }, decimal => '.', thousand => ',' );
+"Values"
+"100,456.222"
+DATA
+
+print STDERR "Pass\n";
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]