RE: a bit of trouble with compiling with MSVC++ on Win32
[p5sagit/p5-mst-13.2.git] / t / op / chr.t
CommitLineData
646ca15d 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = qw(. ../lib); # ../lib needed for test.deparse
6 require "test.pl";
7}
8
9plan tests => 26;
10
11# Note that t/op/ord.t already tests for chr() <-> ord() rountripping.
12
13# Don't assume ASCII.
14
15is(chr(ord("A")), "A");
16
17is(chr( 0), "\x00");
18is(chr(127), "\x7F");
19is(chr(128), "\x80");
20is(chr(255), "\xFF");
21
22# is(chr(-1), undef); # Shouldn't it be?
23
24# Check UTF-8.
25
26sub hexes { join(" ",map{sprintf"%02x",$_}unpack("C*",chr($_[0]))) }
27
28# The following code points are some interesting steps in UTF-8.
29is(hexes( 0x100), "c4 80");
30is(hexes( 0x7FF), "df bf");
31is(hexes( 0x800), "e0 a0 80");
32is(hexes( 0xFFF), "e0 bf bf");
33is(hexes( 0x1000), "e1 80 80");
34is(hexes( 0xCFFF), "ec bf bf");
35is(hexes( 0xD000), "ed 80 80");
36is(hexes( 0xD7FF), "ed 9f bf");
37is(hexes( 0xD800), "ed a0 80"); # not strict utf-8 (surrogate area begin)
38is(hexes( 0xDFFF), "ed bf bf"); # not strict utf-8 (surrogate area end)
39is(hexes( 0xE000), "ee 80 80");
40is(hexes( 0xFFFF), "ef bf bf");
41is(hexes( 0x10000), "f0 90 80 80");
42is(hexes( 0x3FFFF), "f0 bf bf bf");
43is(hexes( 0x40000), "f1 80 80 80");
44is(hexes( 0xFFFFF), "f3 bf bf bf");
45is(hexes(0x100000), "f4 80 80 80");
46is(hexes(0x10FFFF), "f4 8f bf bf"); # Unicode (4.1) last code point
47is(hexes(0x110000), "f4 90 80 80");
48is(hexes(0x1FFFFF), "f7 bf bf bf"); # last four byte encoding
49is(hexes(0x200000), "f8 88 80 80 80");
50