1#!/usr/bin/env perl 2 3use strict; 4use warnings; 5use utf8; 6use open qw(:std :utf8); 7 8use Test::More; 9use MCE::Signal qw( $tmp_dir ); 10 11BEGIN { 12 use_ok 'MCE::Shared'; 13 use_ok 'MCE::Shared::Handle'; 14} 15 16# https://sacred-texts.com/cla/usappho/sph02.htm (VII) 17 18my $sappho_text = 19 "ἔλθε μοι καὶ νῦν, χαλεπᾶν δὲ λῦσον\n". 20 "ἐκ μερίμναν ὄσσα δέ μοι τέλεσσαι\n". 21 "θῦμοσ ἰμμέρρει τέλεσον, σὐ δ᾽ αὔτα\n". 22 "σύμμαχοσ ἔσσο.\n"; 23 24my $translation = 25 "Come then, I pray, grant me surcease from sorrow,\n". 26 "Drive away care, I beseech thee, O goddess\n". 27 "Fulfil for me what I yearn to accomplish,\n". 28 "Be thou my ally.\n"; 29 30## --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- 31 32# https://perldoc.perl.org/PerlIO.html 33 34my ($buf, $fno, $ret1, $ret2, $ret3, $ret4, $ret5, $ret6, $ret7, $size) = (''); 35my $tmp_file = "$tmp_dir/test.txt"; 36my $fh; 37 38mce_open $fh, ">:raw:utf8", $tmp_file or die "open error: $!"; 39 40$fno = fileno $fh; 41print $fh $sappho_text; 42 43close $fh; 44 45## --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- 46 47mce_open $fh, "<:raw:utf8", $tmp_file or die "open error: $!"; 48 49$ret1 = eof $fh; 50$buf .= $_ while <$fh>; 51$ret2 = eof $fh; 52$ret3 = tell $fh; 53 54seek $fh, 34, 0; 55$ret4 = readline $fh; chomp $ret4; 56$size = read $fh, $ret5, 8; 57$ret6 = $ret5; 58 59read $fh, $ret6, 3, 3; 60$ret7 = getc $fh; # " " 61$ret7 = getc $fh; # "ὄ" 62 63close $fh; 64 65like( $fno, qr/\A\d+\z/, "shared utf8 file, OPEN, FILENO, CLOSE" ); 66is( $buf, $sappho_text, "shared utf8 file, PRINT, PRINTF, READLINE, WRITE" ); 67 68is( $ret1, "", "shared utf8 file, EOF (test 1)" ); 69is( $ret2, "1", "shared utf8 file, EOF (test 2)" ); 70is( $ret3, "232", "shared utf8 file, TELL" ); 71is( $ret4, "χαλεπᾶν δὲ λῦσον", "shared utf8 file, SEEK, READLINE" ); 72is( $ret5, "ἐκ μερίμ", "shared utf8 file, READ" ); 73is( $ret6, "ἐκ ναν", "shared utf8 file, READ offset" ); 74is( $ret7, "ὄ", "shared utf8 file, GETC" ); 75 76## --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- 77 78mce_open $fh, ">:raw:utf8", $tmp_file or die "open error: $!"; 79 80print $fh $ret4, "\n"; 81printf $fh "%s\n", $ret5; 82print $fh "$ret6\n"; 83 84close $fh; 85 86mce_open $fh, "<:raw:utf8", $tmp_file or die "open error: $!"; 87 88$ret1 = readline($fh); chomp $ret1; 89$ret2 = readline($fh); chomp $ret2; 90$ret3 = readline($fh); chomp $ret3; 91 92is( $ret1, $ret4, "shared utf8 file, READLINE 1" ); 93is( $ret2, $ret5, "shared utf8 file, READLINE 1" ); 94is( $ret3, $ret6, "shared utf8 file, READLINE 1" ); 95 96close $fh; 97 98unlink $tmp_file if -f $tmp_file; 99 100done_testing; 101 102