Commit | Line | Data |
---|---|---|
8d063cd8 LW |
1 | #!./perl |
2 | ||
9466bab6 JH |
3 | BEGIN { |
4 | chdir 't' if -d 't'; | |
127212b2 | 5 | @INC = qw(. ../lib); # ../lib needed for test.deparse |
9466bab6 JH |
6 | require "test.pl"; |
7 | } | |
8 | ||
4c5ed6e2 | 9 | plan tests => 35; |
8d063cd8 LW |
10 | |
11 | # compile time evaluation | |
12 | ||
ecf52eaf JH |
13 | # 'A' 65 ASCII |
14 | # 'A' 193 EBCDIC | |
8d063cd8 | 15 | |
9466bab6 JH |
16 | ok(ord('A') == 65 || ord('A') == 193, "ord('A') is ".ord('A')); |
17 | ||
18 | is(ord(chr(500)), 500, "compile time chr 500"); | |
bed171df | 19 | |
8d063cd8 LW |
20 | # run time evaluation |
21 | ||
22 | $x = 'ABC'; | |
bed171df | 23 | |
9466bab6 | 24 | ok(ord($x) == 65 || ord($x) == 193, "ord('$x') is ".ord($x)); |
463ee0b2 | 25 | |
9466bab6 | 26 | ok(chr 65 eq 'A' || chr 193 eq 'A', "chr can produce 'A'"); |
ecf52eaf | 27 | |
bed171df | 28 | $x = 500; |
9466bab6 | 29 | is(ord(chr($x)), $x, "runtime chr $x"); |
ecf52eaf | 30 | |
9466bab6 | 31 | is(ord("\x{1234}"), 0x1234, 'compile time ord \x{....}'); |
ecf52eaf JH |
32 | |
33 | $x = "\x{1234}"; | |
9466bab6 JH |
34 | is(ord($x), 0x1234, 'runtime ord \x{....}'); |
35 | ||
4c5ed6e2 TS |
36 | { |
37 | no warnings 'utf8'; # avoid Unicode warnings | |
38 | ||
39 | # The following code points are some interesting steps. | |
40 | is(ord(chr( 0x100)), 0x100, '0x0100'); | |
41 | is(ord(chr( 0x3FF)), 0x3FF, 'last two-byte char in UTF-EBCDIC'); | |
42 | is(ord(chr( 0x400)), 0x400, 'first three-byte char in UTF-EBCDIC'); | |
43 | is(ord(chr( 0x7FF)), 0x7FF, 'last two-byte char in UTF-8'); | |
44 | is(ord(chr( 0x800)), 0x800, 'first three-byte char in UTF-8'); | |
45 | is(ord(chr( 0xFFF)), 0xFFF, '0x0FFF'); | |
46 | is(ord(chr( 0x1000)), 0x1000, '0x1000'); | |
47 | is(ord(chr( 0x3FFF)), 0x3FFF, 'last three-byte char in UTF-EBCDIC'); | |
48 | is(ord(chr( 0x4000)), 0x4000, 'first four-byte char in UTF-EBCDIC'); | |
49 | is(ord(chr( 0xCFFF)), 0xCFFF, '0xCFFF'); | |
50 | is(ord(chr( 0xD000)), 0xD000, '0xD000'); | |
51 | is(ord(chr( 0xD7FF)), 0xD7FF, '0xD7FF'); | |
52 | is(ord(chr( 0xD800)), 0xD800, 'surrogate begin (not strict utf-8)'); | |
53 | is(ord(chr( 0xDFFF)), 0xDFFF, 'surrogate end (not strict utf-8)'); | |
54 | is(ord(chr( 0xE000)), 0xE000, '0xE000'); | |
55 | is(ord(chr( 0xFDD0)), 0xFDD0, 'first additional noncharacter in BMP'); | |
56 | is(ord(chr( 0xFDEF)), 0xFDEF, 'last additional noncharacter in BMP'); | |
57 | is(ord(chr( 0xFFFE)), 0xFFFE, '0xFFFE'); | |
58 | is(ord(chr( 0xFFFF)), 0xFFFF, 'last three-byte char in UTF-8'); | |
59 | is(ord(chr( 0x10000)), 0x10000, 'first four-byte char in UTF-8'); | |
60 | is(ord(chr( 0x3FFFF)), 0x3FFFF, 'last four-byte char in UTF-EBCDIC'); | |
61 | is(ord(chr( 0x40000)), 0x40000, 'first five-byte char in UTF-EBCDIC'); | |
62 | is(ord(chr( 0xFFFFF)), 0xFFFFF, '0xFFFFF'); | |
63 | is(ord(chr(0x100000)), 0x100000, '0x100000'); | |
64 | is(ord(chr(0x10FFFF)), 0x10FFFF, 'Unicode last code point'); | |
65 | is(ord(chr(0x110000)), 0x110000, '0x110000'); | |
66 | is(ord(chr(0x1FFFFF)), 0x1FFFFF, 'last four-byte char in UTF-8'); | |
67 | is(ord(chr(0x200000)), 0x200000, 'first five-byte char in UTF-8'); | |
68 | } |