1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#!/usr/bin/perl
use strict;
use Test::More( tests => 10 );
BEGIN {
use_ok( 'String::Escape', qw( printable unprintable qprintable unqprintable ) )
}
{
# Backslash escapes for newline and tab characters
my $original = "\tNow is the time\nfor all good folk\nto party.\n";
my $expected = '\\tNow is the time\\nfor all good folk\\nto party.\\n';
is( printable( $original ) => $expected );
is( unprintable( $expected ) => $original );
}
{
# Backslash escapes for newline and tab characters
my $original = "\tNow is the time\nfor all good folk\nto party.\n";
my $expected = '"\\tNow is the time\\nfor all good folk\\nto party.\\n"';
is( qprintable( $original ) => $expected );
is( unqprintable( $expected ) => $original );
}
{
# Handles empty strings
my $original = "";
is( printable( $original ) => $original );
is( unprintable( $original ) => $original );
}
{
# Handles undef
my $original = undef;
my $expected = "";
is( printable( $original ) => $expected );
is( unprintable( $original ) => $expected );
}
{
# Should work for high-bit characters as well
my $original = " this\nis a test. \\quote\\ endquote.";
is( unprintable( printable( $original ) ) => $original );
}
|