File: utf8.t

package info (click to toggle)
libipc-run-perl 20231003.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 844 kB
  • sloc: perl: 6,255; makefile: 5
file content (35 lines) | stat: -rw-r--r-- 1,149 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
use Test::More;

BEGIN {
    if ( $^O eq 'MSWin32' ) {
        plan skip_all => "no cat on Windows";    #and "cmd /C type con" reads from real STDIN
    }
    else {
        plan tests => 4;
    }
}

use strict;
use warnings;
use IPC::Run ();
use Encode   ();

##### data setup and sanity check
my $unicode_string = "string\x{2026}";
my $byte_string    = "string\xE2\x80\xA6";

## make sure what we're doing doesn't incidentally change the data and that the data is what we expect
my $x = Encode::decode_utf8($byte_string);
isnt( $x, $byte_string, "Encode::decode_utf8() does not lvalue our bytes string var" );
is( $unicode_string, Encode::decode_utf8($byte_string), "byte string and unicode string same string as far as humans are concerned" );

##### actual IPC::Run::run() tests
my $bytes_out;

## Test using the byte string: "cat" should be transparent.
IPC::Run::run( ["cat"], \$byte_string, \$bytes_out );
is( $bytes_out, $byte_string, "run() w/ byte string" );

##  Same test using the Unicode string
IPC::Run::run( ["cat"], \$unicode_string, \$bytes_out );
is( Encode::decode_utf8($bytes_out), $unicode_string, "run() w/ unicode string" );