[guest - Thu Jul 24 10:01:08 2003]:
Show quoted text> This bug report centers around this test output I received:
>
> # * 5| order_id => 127 | order_id => '127'
> *
>
> These two values should compare to the be same, not different. In
> fact, I don't think I stick '127' in a Perl hash and have it come out
> '127', it will always come out without the quotes, as just 127.
>
> I also testing the same stuctures with Test::More::is_deeply. With
> that test, the values were found to be equal.
>
> Perhaps you could see what is_deeply() is doing differently here.
>
I have a patch and test case which fixes this for simple hashref
comparisons. These are now done inside of Test::Differences.
I think, but did not verify, that more complex cases will still have
this problem, because they are handled by Data::Dumper.
There is probably an easy workaround there to look for strings that look
like numbers and strip off quotes around them if there are any.
If you give me some feedback on this patch, maybe I'll be motivated to
work on that as well. :)
Mark
diff -rbNu Test-Differences-0.47/Differences.pm Test-Differences-0.47-modified/Differences.pm
--- Test-Differences-0.47/Differences.pm Mon Jun 16 12:26:37 2003
+++ Test-Differences-0.47-modified/Differences.pm Mon Dec 20 21:57:03 2004
@@ -200,7 +200,7 @@
=cut
-$VERSION = 0.47;
+$VERSION = 0.48;
use Exporter;
@@ -226,6 +226,7 @@
use constant ARRAY_of_scalars => "ARRAY of scalars";
use constant ARRAY_of_ARRAYs_of_scalars => "ARRAY of ARRAYs of scalars";
use constant ARRAY_of_HASHes_of_scalars => "ARRAY of HASHes of scalars";
+use constant HASH_of_scalars => "HASH of scalars";
sub _grok_type {
@@ -241,6 +242,11 @@
unless grep _isnt_HASH_of_scalars, @$_;
return 0;
}
+ elsif (ref eq 'HASH') {
+ return HASH_of_scalars
+ unless _isnt_HASH_of_scalars($_);
+ return 0;
+ }
}
@@ -254,15 +260,22 @@
croak "Can't flatten $_" unless $type ;
## Copy the top level array so we don't trash the originals
- my @recs = @$_;
+ my (@recs, %hash_copy);
+ if (ref $_ eq 'ARRAY') {
+ @recs = @$_;
+ }
+ elsif (ref $_ eq 'HASH') {
+ %hash_copy = %$_;
+ }
+ else {
+ die "unsupported ref type";
+ }
if ( $type eq ARRAY_of_ARRAYs_of_scalars ) {
## Also copy the inner arrays if need be
$_ = [ @$_ ] for @recs;
}
-
-
- if ( $type eq ARRAY_of_HASHes_of_scalars ) {
+ elsif ( $type eq ARRAY_of_HASHes_of_scalars ) {
my %headings;
for my $rec ( @recs ) {
$headings{$_} = 1 for keys %$rec;
@@ -278,6 +291,11 @@
$type = ARRAY_of_ARRAYs_of_scalars;
}
+ elsif ($type eq HASH_of_scalars) {
+ my @headings = sort keys %hash_copy;
+ @recs = (\@headings, [map $hash_copy{$_}, @headings ]);
+ $type = ARRAY_of_ARRAYs_of_scalars;
+ }
if ( $type eq ARRAY_of_ARRAYs_of_scalars ) {
## Convert undefs
@@ -290,6 +308,7 @@
}
return \@recs;
+
}
@@ -339,6 +358,7 @@
my $dump_it = !$types[0] || !$types[1];
+ my ($got,$expected);
if ( $dump_it ) {
require Data::Dumper;
local $Data::Dumper::Indent = 1;
@@ -347,12 +367,12 @@
local $Data::Dumper::Terse = 1;
local $Data::Dumper::Deepcopy = 1;
local $Data::Dumper::Quotekeys = 0;
- @vals = map
+ ($got,$expected) = map
[ split /^/, Data::Dumper::Dumper( $_ ) ],
@vals;
}
else {
- @vals = (
+ ($got,$expected)= (
_flatten( $types[0], $vals[0] ),
_flatten( $types[1], $vals[1] )
);
@@ -360,8 +380,8 @@
my $caller = caller;
- my $passed = join( $joint, @{$vals[0]} ) eq
- join( $joint, @{$vals[1]} );
+ my $passed = join( $joint, @{$got} ) eq
+ join( $joint, @{$expected} );
my $diff;
unless ( $passed ) {
@@ -370,13 +390,13 @@
$context = $options->{context}
if exists $options->{context};
- $context = $dump_it ? 2**31 : grep( @$_ > 25, @vals ) ? 3 : 25
+ $context = $dump_it ? 2**31 : grep( @$_ > 25, $got,$expected ) ? 3 : 25
unless defined $context;
confess "context must be an integer: '$context'\n"
unless $context =~ /\A\d+\z/;
- $diff = diff @vals, {
+ $diff = diff $got,$expected, {
CONTEXT => $context,
STYLE => "Table",
FILENAME_A => "Got",
diff -rbNu Test-Differences-0.47/MANIFEST Test-Differences-0.47-modified/MANIFEST
--- Test-Differences-0.47/MANIFEST Mon May 13 08:49:12 2002
+++ Test-Differences-0.47-modified/MANIFEST Mon Dec 20 20:57:30 2004
@@ -11,3 +11,4 @@
t/10test.t
t/20test_more.t
t/99example.t
+t/quoted_numbers_bug.t
diff -rbNu Test-Differences-0.47/t/quoted_numbers_bug.t Test-Differences-0.47-modified/t/quoted_numbers_bug.t
--- Test-Differences-0.47/t/quoted_numbers_bug.t Wed Dec 31 19:00:00 1969
+++ Test-Differences-0.47-modified/t/quoted_numbers_bug.t Mon Dec 20 20:59:21 2004
@@ -0,0 +1,8 @@
+
+use Test::More tests => 2;
+
+BEGIN {
+ use_ok('Test::Differences');
+}
+
+eq_or_diff({a => 1},{a => '1'}, "quoted and non-quoted numbers should be treated the same");