1 ################################################################################
3 # !!!!! Do NOT edit this file directly! !!!!!
5 # Edit mktests.PL and/or parts/inc/utf8 instead.
7 # This file was automatically generated from the definition files in the
8 # parts/inc/ subdirectory by mktests.PL. To learn more about how all this
9 # works, please read the F<HACKERS> file that came with this distribution.
11 ################################################################################
14 if ($ENV{'PERL_CORE'}) {
16 @INC = ('../lib', '../ext/Devel-PPPort/t') if -d '../lib' && -d '../ext';
17 require Config; import Config;
19 if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
20 print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
30 require 'testutil.pl' if $@;
43 package Devel::PPPort;
46 @ISA = qw(DynaLoader);
47 bootstrap Devel::PPPort;
51 BEGIN { require warnings if "$]" gt '5.006' }
53 # skip tests on 5.6.0 and earlier
54 if ("$]" le '5.006') {
55 skip 'skip: broken utf8 support', 0 for 1..55;
59 ok(&Devel::PPPort::UTF8_SAFE_SKIP("A", 0), 1);
60 ok(&Devel::PPPort::UTF8_SAFE_SKIP("A", -1), 0);
62 ok(&Devel::PPPort::isUTF8_CHAR("A", -1), 0);
63 ok(&Devel::PPPort::isUTF8_CHAR("A", 0), 1);
64 ok(&Devel::PPPort::isUTF8_CHAR("\x{100}", -1), 0);
65 ok(&Devel::PPPort::isUTF8_CHAR("\x{100}", 0), 2);
67 my $ret = &Devel::PPPort::utf8_to_uvchr("A");
68 ok($ret->[0], ord("A"));
71 $ret = &Devel::PPPort::utf8_to_uvchr("\0");
75 $ret = &Devel::PPPort::utf8_to_uvchr_buf("A", 0);
76 ok($ret->[0], ord("A"));
79 $ret = &Devel::PPPort::utf8_to_uvchr_buf("\0", 0);
83 if (ord("A") != 65) { # tests not valid for EBCDIC
84 ok(1, 1) for 1 .. (2 + 4 + (7 * 5));
87 $ret = &Devel::PPPort::utf8_to_uvchr_buf("\xc4\x80", 0);
92 local $SIG{__WARN__} = sub { push @warnings, @_; };
95 BEGIN { 'warnings'->import('utf8') if "$]" gt '5.006' }
96 $ret = &Devel::PPPort::utf8_to_uvchr("\xe0\0\x80");
100 BEGIN { 'warnings'->unimport() if "$]" gt '5.006' }
101 $ret = &Devel::PPPort::utf8_to_uvchr("\xe0\0\x80");
102 ok($ret->[0], 0xFFFD);
110 warning => qr/empty/,
111 no_warnings_returned_length => 0,
116 warning => qr/non-continuation/,
117 no_warnings_returned_length => 1,
122 warning => qr/short|1 byte, need 2/,
123 no_warnings_returned_length => 1,
128 warning => qr/overlong|2 bytes, need 1/,
129 no_warnings_returned_length => 2,
132 input => "\xe0\x80\x81",
134 warning => qr/overlong|3 bytes, need 1/,
135 no_warnings_returned_length => 3,
138 input => "\xf0\x80\x80\x81",
140 warning => qr/overlong|4 bytes, need 1/,
141 no_warnings_returned_length => 4,
143 { # Old algorithm failed to detect this
144 input => "\xff\x80\x90\x90\x90\xbf\xbf\xbf\xbf\xbf\xbf\xbf\xbf",
146 warning => qr/overflow/,
147 no_warnings_returned_length => 13,
151 # An empty input is an assertion failure on debugging builds. It is
152 # deliberately the first test.
153 require Config; import Config;
155 if ($Config{ccflags} =~ /-DDEBUGGING/) {
160 for my $test (@buf_tests) {
161 my $input = $test->{'input'};
162 my $adjustment = $test->{'adjustment'};
163 my $display = 'utf8_to_uvchr_buf("';
164 for (my $i = 0; $i < length($input) + $adjustment; $i++) {
165 $display .= sprintf "\\x%02x", ord substr($input, $i, 1);
169 my $warning = $test->{'warning'};
172 BEGIN { 'warnings'->import('utf8') if "$]" gt '5.006' }
173 $ret = &Devel::PPPort::utf8_to_uvchr_buf($input, $adjustment);
174 ok($ret->[0], 0, "returned value $display; warnings enabled");
175 ok($ret->[1], -1, "returned length $display; warnings enabled");
176 my $all_warnings = join "; ", @warnings;
177 my $contains = grep { $_ =~ $warning } $all_warnings;
178 ok($contains, 1, $display
179 . "; Got: '$all_warnings', which should contain '$warning'");
182 BEGIN { 'warnings'->unimport('utf8') if "$]" gt '5.006' }
183 $ret = &Devel::PPPort::utf8_to_uvchr_buf($input, $adjustment);
184 ok($ret->[0], 0xFFFD, "returned value $display; warnings disabled");
185 ok($ret->[1], $test->{'no_warnings_returned_length'},
186 "returned length $display; warnings disabled");