Commit | Line | Data |
d85e265b |
1 | #!perl -w |
2 | use strict; |
3 | use IO::Handle; # ungetc() |
4 | |
5 | use Test::More tests => 20; |
6 | |
7 | require_ok q{PerlIO::scalar}; |
8 | |
9 | my $s = 'foo'; |
10 | Internals::SvREADONLY($s, 1); |
11 | eval{ |
12 | $s = 'bar'; |
13 | }; |
14 | like $@, qr/Modification of a read-only value/, '$s is readonly'; |
15 | |
16 | ok open(my $io, '<', \$s), 'open'; |
17 | |
18 | getc $io; |
19 | |
20 | my $a = ord 'A'; |
21 | |
22 | note "buffer[$s]"; |
23 | is $io->ungetc($a), $a, 'ungetc'; |
24 | note "buffer[$s]"; |
25 | |
26 | is getc($io), chr($a), 'getc'; |
27 | |
28 | is $s, 'foo', '$s remains "foo"'; |
29 | |
30 | is getc($io), 'o', 'getc/2'; |
31 | is getc($io), 'o', 'getc/3'; |
32 | is getc($io), undef, 'getc/4'; |
33 | |
34 | for my $c($a .. ($a+10)){ |
35 | is $io->ungetc($c), $c, "ungetc($c)"; |
36 | } |