Commit | Line | Data |
e9acc69d |
1 | BEGIN { # 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 |
16 | use strict; |
17 | use warnings; |
b31b80f9 |
18 | use Test::More tests => 11; |
19 | |
e934609f |
20 | BEGIN { use_ok('PerlIO::via::QuotedPrint') } |
b31b80f9 |
21 | |
e9acc69d |
22 | my $file = 'test.qp'; |
23 | |
b31b80f9 |
24 | my $decoded = <<EOD; |
25 | This is a tést for quoted-printable text that has hàrdly any speçial characters |
26 | in it. |
27 | EOD |
28 | |
2f3efc97 |
29 | my $encoded; |
30 | |
31 | if (ord('A') == 193) { # EBCDIC. |
32 | $encoded = <<EOD; |
33 | This is a t=51st for quoted-printable text that has h=44rdly any spe=48ial = |
34 | characters |
35 | in it. |
36 | EOD |
37 | } else { |
38 | $encoded = <<EOD; |
b31b80f9 |
39 | This is a t=E9st for quoted-printable text that has h=E0rdly any spe=E7ial = |
40 | characters |
41 | in it. |
42 | EOD |
2f3efc97 |
43 | } |
b31b80f9 |
44 | |
45 | # Create the encoded test-file |
46 | |
47 | ok( |
e934609f |
48 | open( my $out,'>:via(PerlIO::via::QuotedPrint)', $file ), |
b31b80f9 |
49 | "opening '$file' for writing" |
50 | ); |
51 | |
52 | ok( (print $out $decoded), 'print to file' ); |
53 | ok( close( $out ), 'closing encoding handle' ); |
54 | |
55 | # Check encoding without layers |
56 | |
57 | { |
58 | local $/ = undef; |
59 | ok( open( my $test,$file ), 'opening without layer' ); |
60 | is( $encoded,readline( $test ), 'check encoded content' ); |
61 | ok( close( $test ), 'close test handle' ); |
62 | } |
63 | |
64 | # Check decoding _with_ layers |
65 | |
66 | ok( |
9445987a |
67 | open( my $in,'<:via(QuotedPrint)', $file ), |
b31b80f9 |
68 | "opening '$file' for reading" |
69 | ); |
70 | is( $decoded,join( '',<$in> ), 'check decoding' ); |
71 | ok( close( $in ), 'close decoding handle' ); |
72 | |
73 | # Remove whatever we created now |
74 | |
75 | ok( unlink( $file ), "remove test file '$file'" ); |