Move PerlIO::via::QuotedPrint from lib to ext.
[p5sagit/p5-mst-13.2.git] / ext / PerlIO-via-QuotedPrint / t / QuotedPrint.t
CommitLineData
e9acc69d 1BEGIN { # Magic Perl CORE pragma
317cb137 2 unless (find PerlIO::Layer 'perlio') {
3 print "1..0 # Skip: PerlIO not used\n";
e9acc69d 4 exit 0;
317cb137 5 }
c29a2e1a 6 require Config;
98641f60 7 if (($Config::Config{'extensions'} !~ m!\bPerlIO/via\b!) ){
c29a2e1a 8 print "1..0 # Skip -- Perl configured without PerlIO::via module\n";
9 exit 0;
10 }
b13c4942 11 if (ord("A") == 193) {
e9acc69d 12 print "1..0 # Skip: EBCDIC\n";
b13c4942 13 }
b31b80f9 14}
15
e9acc69d 16use strict;
17use warnings;
b31b80f9 18use Test::More tests => 11;
19
e934609f 20BEGIN { use_ok('PerlIO::via::QuotedPrint') }
b31b80f9 21
e9acc69d 22my $file = 'test.qp';
23
b31b80f9 24my $decoded = <<EOD;
25This is a tést for quoted-printable text that has hàrdly any speçial characters
26in it.
27EOD
28
2f3efc97 29my $encoded;
30
31if (ord('A') == 193) { # EBCDIC.
32 $encoded = <<EOD;
33This is a t=51st for quoted-printable text that has h=44rdly any spe=48ial =
34characters
35in it.
36EOD
37} else {
38 $encoded = <<EOD;
b31b80f9 39This is a t=E9st for quoted-printable text that has h=E0rdly any spe=E7ial =
40characters
41in it.
42EOD
2f3efc97 43}
b31b80f9 44
45# Create the encoded test-file
46
47ok(
e934609f 48 open( my $out,'>:via(PerlIO::via::QuotedPrint)', $file ),
b31b80f9 49 "opening '$file' for writing"
50);
51
52ok( (print $out $decoded), 'print to file' );
53ok( close( $out ), 'closing encoding handle' );
54
55# Check encoding without layers
56
57{
58local $/ = undef;
59ok( open( my $test,$file ), 'opening without layer' );
60is( $encoded,readline( $test ), 'check encoded content' );
61ok( close( $test ), 'close test handle' );
62}
63
64# Check decoding _with_ layers
65
66ok(
9445987a 67 open( my $in,'<:via(QuotedPrint)', $file ),
b31b80f9 68 "opening '$file' for reading"
69);
70is( $decoded,join( '',<$in> ), 'check decoding' );
71ok( close( $in ), 'close decoding handle' );
72
73# Remove whatever we created now
74
75ok( unlink( $file ), "remove test file '$file'" );