File: iostring-write.t

package info (click to toggle)
libio-callback-perl 2.00-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 248 kB
  • sloc: perl: 389; makefile: 2; sh: 1
file content (45 lines) | stat: -rw-r--r-- 872 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
39
40
41
42
43
44
45
# IO::Callback 1.08 t/iostring-write.t
# This is t/write.t from IO::String 1.08, adapted to IO::Callback.

use strict;
use warnings;

use Test::More tests => 2;
use Test::NoWarnings;

use IO::Callback;

my $str = '';
my $io = IO::Callback->new('>', sub { $str .= shift });

print $io "Heisan\n";
$io->print("a", "b", "c");

{
    local($\) = "\n";
    print $io "d", "e";
    local($,) = ",";
    print $io "f", "g", "h";
}

my $foo = "1234567890";

syswrite($io, $foo, length($foo));
$io->syswrite($foo);
$io->syswrite($foo, length($foo));
$io->write($foo, length($foo), 5);
$io->write("xxx\n", 100, -1);

for (1..3) {
    printf $io "i(%d)", $_;
    $io->printf("[%d]\n", $_);
}
select $io;
print "\n";

is( $str, "Heisan\nabcde\nf,g,h\n" .
          ("1234567890" x 3) . "67890\n" .
          "i(1)[1]\ni(2)[2]\ni(3)[3]\n\n",
    'data written to $str as expected'
);