File: 11-printable.t

package info (click to toggle)
libstring-escape-perl 2010.002-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 164 kB
  • sloc: perl: 362; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,218 bytes parent folder | download | duplicates (3)
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 );
}