xref: /php-src/ext/mbstring/tests/mb_ord.phpt (revision 5853cdb7)
1--TEST--
2mb_ord()
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7var_dump(
8    0x20bb7 === mb_ord("\u{20bb7}"),
9    false === mb_ord("\u{d800}"),
10    0x50aa === mb_ord("\x8f\xa1\xef", "EUC-JP-2004")
11);
12
13// Empty string
14try {
15    var_dump( mb_ord("") );
16} catch (\ValueError $e) {
17    echo $e->getMessage() . \PHP_EOL;
18}
19
20// Invalid
21try {
22    var_dump( mb_ord("\u{d800}", "typo") );
23} catch (\ValueError $e) {
24    echo $e->getMessage() . \PHP_EOL;
25}
26try {
27    var_dump( mb_ord("\u{d800}", "pass") );
28} catch (\ValueError $e) {
29    echo $e->getMessage() . \PHP_EOL;
30}
31try {
32    var_dump( mb_ord("\u{d800}", "jis") );
33} catch (\ValueError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36try {
37    var_dump( mb_ord("\u{d800}", "cp50222") );
38} catch (\ValueError $e) {
39    echo $e->getMessage() . \PHP_EOL;
40}
41try {
42    var_dump( mb_ord("\u{d800}", "utf-7") );
43} catch (\ValueError $e) {
44    echo $e->getMessage() . \PHP_EOL;
45}
46
47mb_internal_encoding("utf-7");
48try {
49    var_dump( mb_ord("\u{d800}") );
50} catch (\ValueError $e) {
51    echo $e->getMessage() . \PHP_EOL;
52}
53
54?>
55--EXPECT--
56bool(true)
57bool(true)
58bool(true)
59mb_ord(): Argument #1 ($string) must not be empty
60mb_ord(): Argument #2 ($encoding) must be a valid encoding, "typo" given
61mb_ord(): Argument #2 ($encoding) must be a valid encoding, "pass" given
62mb_ord() does not support the "JIS" encoding
63mb_ord() does not support the "CP50222" encoding
64mb_ord() does not support the "UTF-7" encoding
65mb_ord() does not support the "UTF-7" encoding
66