xref: /openbsd-src/gnu/usr.bin/perl/cpan/PerlIO-via-QuotedPrint/t/QuotedPrint.t (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1BEGIN {				# Magic Perl CORE pragma
2    unless (find PerlIO::Layer 'perlio') {
3        print "1..0 # Skip: PerlIO not used\n";
4        exit 0;
5    }
6    require Config;
7    if (($Config::Config{'extensions'} !~ m!\bPerlIO/via\b!) ){
8        print "1..0 # Skip -- Perl configured without PerlIO::via module\n";
9        exit 0;
10    }
11    if (ord("A") == 193) {
12        print "1..0 # Skip: EBCDIC\n";
13    }
14}
15
16use strict;
17use warnings;
18use Test::More tests => 11;
19
20BEGIN { use_ok('PerlIO::via::QuotedPrint') }
21
22my $file = 'test.qp';
23
24my $decoded = <<EOD;
25This is a t�st for quoted-printable text that has h�rdly any spe�ial characters
26in it.
27EOD
28
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;
39This is a t=E9st for quoted-printable text that has h=E0rdly any spe=E7ial =
40characters
41in it.
42EOD
43}
44
45# Create the encoded test-file
46
47ok(
48 open( my $out,'>:via(PerlIO::via::QuotedPrint)', $file ),
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(
67 open( my $in,'<:via(QuotedPrint)', $file ),
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'" );
76