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