QuotedPrint.t
[p5sagit/p5-mst-13.2.git] / lib / PerlIO / via / t / QuotedPrint.t
1 my $file = 'test.qp';
2
3 BEGIN {
4     if ($ENV{PERL_CORE}) {      
5         chdir 't' if -d 't';
6         @INC = '../lib';
7     }
8     unless (find PerlIO::Layer 'perlio') {
9         print "1..0 # Skip: PerlIO not used\n";
10         exit 0;
11     }
12     if (ord("A") == 193) {
13         print "1..0 # Skip: EBCDIC\n";
14     }
15 }
16
17 use Test::More tests => 11;
18
19 BEGIN { use_ok('PerlIO::via::QuotedPrint') }
20
21 my $decoded = <<EOD;
22 This is a tést for quoted-printable text that has hàrdly any speçial characters
23 in it.
24 EOD
25
26 my $encoded = <<EOD;
27 This is a t=E9st for quoted-printable text that has h=E0rdly any spe=E7ial =
28 characters
29 in it.
30 EOD
31
32 # Create the encoded test-file
33
34 ok(
35  open( my $out,'>:via(PerlIO::via::QuotedPrint)', $file ),
36  "opening '$file' for writing"
37 );
38
39 ok( (print $out $decoded),              'print to file' );
40 ok( close( $out ),                      'closing encoding handle' );
41
42 # Check encoding without layers
43
44 {
45 local $/ = undef;
46 ok( open( my $test,$file ),             'opening without layer' );
47 is( $encoded,readline( $test ),         'check encoded content' );
48 ok( close( $test ),                     'close test handle' );
49 }
50
51 # Check decoding _with_ layers
52
53 ok(
54  open( my $in,'<:via(QuotedPrint)', $file ),
55  "opening '$file' for reading"
56 );
57 is( $decoded,join( '',<$in> ),          'check decoding' );
58 ok( close( $in ),                       'close decoding handle' );
59
60 # Remove whatever we created now
61
62 ok( unlink( $file ),                    "remove test file '$file'" );