This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Preliminary Unicode 12.1
[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';
18 require 'test.pl';
19}
20
21plan tests => 3;
22
23use POSIX qw();
24
25SKIP: {
26 skip("mblen() not present", 3) unless $Config{d_mblen};
27
28 is(&POSIX::mblen("a", &POSIX::MB_CUR_MAX), 1, 'mblen() basically works');
29
30 skip("LC_CTYPE locale support not available", 2)
31 unless locales_enabled('LC_CTYPE');
32
33 my $utf8_locale = find_utf8_ctype_locale();
34 skip("no utf8 locale available", 2) unless $utf8_locale;
35
36 local $ENV{LC_CTYPE} = $utf8_locale;
37 local $ENV{LC_ALL};
38 delete $ENV{LC_ALL};
39
40 fresh_perl_is(
41 'use POSIX; print &POSIX::mblen("\x{c3}\x{28}", &POSIX::MB_CUR_MAX)',
42 -1, {}, 'mblen() recognizes invalid multibyte characters');
43
44 fresh_perl_is(
45 'use POSIX; print &POSIX::mblen("\N{GREEK SMALL LETTER SIGMA}", &POSIX::MB_CUR_MAX)',
46 2, {}, 'mblen() works on UTF-8 characters');
47}