Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

case insensitive deep comparison

by KeighleHawk (Scribe)
on Jun 25, 2015 at 01:57 UTC ( #1131882=perlquestion: print w/replies, xml ) Need Help??

KeighleHawk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use Test::More and Test::Deep to compare two complex data structures (nested objects). Ideally, I would use cmp_deeply and pass it both data structures, but do a lower (or upper) case on all the values so the comparison would be case insensitive. Something like
return cmp_deeply( lc($Expected) , lc($AcTuaL) , "This is my case insensitive comparison" );
Am I missing something obvious here? I don't want to change the actual data in the structures. I also don't want to just stringify it because I want the diagnostics that come with Test::More to show what values actually fail. Ideas?

Replies are listed 'Best First'.
Re: case insensitive deep comparison
by robby_dobby (Hermit) on Jun 25, 2015 at 03:16 UTC
Re: case insensitive deep comparison
by davido (Cardinal) on Jun 25, 2015 at 02:46 UTC

    cmp_deeply may be recursive, but lc isn't. I haven't used Test::Deeply enough to know if cmp_deeply has the ability to accept a comparator callback. If it could, that would make the solution pretty straightforward, but if it can, the documentation doesn't make it apparent. ...something like this would be great:

    my $result = cmp_deeply( $expected, $actual, sub { lc shift eq lc shift }, "This is a test using a callback to compare. );


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1131882]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2023-03-31 13:04 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (75 votes). Check out past polls.