Thanks both for the testing & bugfixes. Here's the escaping portion of
changes from 0.2 to 0.3, does this seem better?
There's also a test script for the escaping now :). I'd love to test
characters for codepoints > 0xff, but they're borken / unsupported in
all released perls, I think. Other replies below.
-sub _decontrol {
- $_ =~ s/\n/\\n/g;
- $_ =~ s/\r/\\r/g;
- $_ =~ s/\t/\\t/g;
- $_ =~ s{
- ([^[:print:]])
- }{
- my $codepoint = ord $1;
- $codepoint <= 0xFF
- ? sprintf "\0x%02x", $codepoint
- : sprintf "\0x{%04x}", $codepoint
-
+my %escapes = map {
+ ( eval qq{"$_"} => $_ )
+} (
+ map( sprintf( "\\x%02x", $_ ), ( 0, 27..31, 128..255 ) ),
+ ("\\cA".."\\cZ"),
+ "\\t", "\\n", "\\r", "\\f", "\\b", "\\a", "\\e"
+) ;
+
+sub _escape($) {
+ my $s = shift ;
+ $s =~ s{([^\040-\177])}{
+ exists $escapes{$1}
+ ? $escapes{$1}
+ : sprintf( "\\x{%04x}", ord $1 ) ;
}ge;
- $_;
+ $s;
}
v0.3 is headed to CPAN. Ask your local grocer for it today!
On Fri, Dec 14, 2001 at 02:45:47PM +0900, Tatsuhiko Miyagawa wrote:
> On Fri, 14 Dec 2001 00:35:35 -0500
> Michael G Schwern <[EMAIL PROTECTED]> wrote:
>
> > > Well, why not globally overrides Test::More's is, is_deeply etc?
> >
> > You change the semantics of is() by doing that, potentially causing
> > confusion.
>
> Changing the semantics is your responsibility. So it should be
> safe when forced via optional arguments of use().
The possible confusion that could result from changing the behavior of
is() in a subtle way is bad.
I don't see much advantage to changing the behavior of is_deeply, and
eq_or_diff is nit much more typing.
You are quite free to do either in your own scripts, I think. Something
like:
use Test::More qw( plan );
use Test::Differences;
sub is { goto &eq_or_diff }
sub is_deeply { goto &eq_or_diff_data }
should do it (untested :), and is sufficiently big and unusual that it
serves as an eye catching warning to the reader that something odd is
happening here.
> > $a = [qw(a b c)];
> > $b = [qw(a b c)];
> > is( $a, $b );
> >
> > In Test::More, that test fails. If you replace it eq_or_diff() it
> > passes.
>
> Maybe eq_or_diff_text().
The only difference between the three functions is whether they count
lines / records / elements from 0 (eq_diff_data) or 1 (eq_diff_text).
eq_or_diff_text will treat the "a"s as being line 1 instead of record /
element 0. eq_or_diff_data treats the "a"s as being in record / elt 0.
eq_or_diff tries to DWIM it.
All three eq_or_diff... functions compare the topology of nested
structures using shallow equality like is_deeply(). None use deep
equality like is() does.
I'm probably being confusing with all these "deep"s. I'm using the term
deep/shallow equality in the CS sense here: deep equality means that two
objects are actually the same object; shallow equality means that two
objects have equal "value" but may be two different ones.
> > is_deeply() could probably be replaced, though. However, I
> > don't see much benefit.
>
> IMHO Test::Differences' benefit is its mix-in nature. Changing
> each is_deeply() to eq_or_diff_data() hand by hand "if not ok"
> seems a little hassle to me.
Why is it more effort than doing something like:
perl -ipe 's/is_deeply/eq_or_diff' t/*.t
?
- Barrie