This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "Fix edge case test failure in ext/POSIX/t/mb.t"
[perl5.git] / ext / POSIX / t / mb.t
CommitLineData
25d7b7aa
NT
1#!./perl
2
3# These tests are in a separate file, because they use fresh_perl_is()
4# from test.pl.
5
6# The mb* functions use the "underlying locale" that is not affected by
7# the Perl one. So we run the tests in a separate "fresh_perl" process
8# with the correct LC_CTYPE set in the environment.
9
10BEGIN {
11 require Config; import Config;
12 if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
13 print "1..0\n";
14 exit 0;
15 }
16 unshift @INC, "../../t";
17 require 'loc_tools.pl';
ac542e2e 18 require 'charset_tools.pl';
25d7b7aa
NT
19 require 'test.pl';
20}
21
02b8575c 22plan tests => 4;
25d7b7aa
NT
23
24use POSIX qw();
25
26SKIP: {
02b8575c 27 skip("mblen() not present", 4) unless $Config{d_mblen};
25d7b7aa
NT
28
29 is(&POSIX::mblen("a", &POSIX::MB_CUR_MAX), 1, 'mblen() basically works');
30
02b8575c 31 skip("LC_CTYPE locale support not available", 3)
25d7b7aa
NT
32 unless locales_enabled('LC_CTYPE');
33
34 my $utf8_locale = find_utf8_ctype_locale();
02b8575c 35 skip("no utf8 locale available", 3) unless $utf8_locale;
25d7b7aa
NT
36
37 local $ENV{LC_CTYPE} = $utf8_locale;
7948efd4
JK
38 local $ENV{LC_ALL};
39 delete $ENV{LC_ALL};
25d7b7aa 40
02b8575c
KW
41 fresh_perl_like(
42 'use POSIX; print &POSIX::MB_CUR_MAX',
43 qr/[4-6]/, {}, 'MB_CUR_MAX is at least 4 in a UTF-8 locale');
44
918fbd43 45 SKIP: {
cbf79cee 46 my ($major, $minor, $rest) = $Config{osvers} =~ / (\d+) \. (\d+) .* /x;
b9893ba5 47 skip("mblen() broken (at least for c.utf8) on early HP-UX", 2)
918fbd43
KW
48 if $Config{osname} eq 'hpux'
49 && $major < 11 || ($major == 11 && $minor < 31);
25d7b7aa 50 fresh_perl_is(
ac542e2e
KW
51 'use POSIX; print &POSIX::mblen("'
52 . I8_to_native("\x{c3}\x{28}")
97198b30 53 . '", 2)',
25d7b7aa
NT
54 -1, {}, 'mblen() recognizes invalid multibyte characters');
55
56 fresh_perl_is(
97198b30 57 'use POSIX; print &POSIX::mblen("\N{GREEK SMALL LETTER SIGMA}", 2)',
25d7b7aa 58 2, {}, 'mblen() works on UTF-8 characters');
b9893ba5 59 }
25d7b7aa 60}