1#!perl 2 3use strict; 4use warnings; 5 6BEGIN { 7 chdir 't' if -d 't'; 8 require './test.pl'; 9 set_up_inc('../lib'); 10 skip_all('Can\'t run under miniperl') if is_miniperl(); 11} 12 13plan(19); 14 15use IO::Handle; # ungetc() 16 17my $s = 'foo'; 18Internals::SvREADONLY($s, 1); 19eval{ 20 $s = 'bar'; 21}; 22like $@, qr/Modification of a read-only value/, '$s is readonly'; 23 24ok open(my $io, '<', \$s), 'open'; 25 26getc $io; 27 28my $a = ord 'A'; 29 30note "buffer[$s]"; 31is $io->ungetc($a), $a, 'ungetc'; 32note "buffer[$s]"; 33 34is getc($io), chr($a), 'getc'; 35 36is $s, 'foo', '$s remains "foo"'; 37 38is getc($io), 'o', 'getc/2'; 39is getc($io), 'o', 'getc/3'; 40is getc($io), undef, 'getc/4'; 41 42for my $c($a .. ($a+10)){ 43 is $io->ungetc($c), $c, "ungetc($c)"; 44} 45