File: 30_unicode.t

package info (click to toggle)
libfile-slurp-unicode-perl 0.7.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 84 kB
  • sloc: perl: 142; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

# This tests the meat of what File::Slurp::Unicode does.

use strict;
use warnings;

use Test::More;

plan tests => 7;

use File::Temp qw(tempfile);
my ($fh, $name) = tempfile();

use Encode;
use utf8;
my $wide_data = "Dävîd";
my $bin_data = "D\xc3\xa4v\xc3\xaed";
my $latin_data = "D\xe4v\xeed";

use File::Slurp::Unicode;

write_file $name, $wide_data;
is(read_file($name), $wide_data, "Basic in/out parity");

write_file $name, $bin_data;
is(read_file($name), $wide_data, "Don't touch byte coded strings");
is(read_file($name, encoding => 'binary'), $bin_data, "Binary encoding read");

write_file $name, { encoding => 'binary' }, $bin_data;
is(read_file($name, encoding => 'binary'), $bin_data, "Binary encoding write");

eval { write_file $name, { encoding => 'binary' }, $wide_data; };
like($@, qr/Can't encode wide characters as binary/, "Writing wide characters as binary should die");

write_file $name, { encoding => 'latin1' }, $wide_data;
is(read_file($name, encoding => 'binary'), $latin_data, "Latin1 encoding write");
is(read_file($name, encoding => 'latin1'), $wide_data, "Latin1 encoding read");