1--TEST--
2Calling mb_convert_case() with an invalid casing mode
3--EXTENSIONS--
4mbstring
5--FILE--
6<?php
7
8var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_UPPER));
9var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_LOWER));
10var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_TITLE));
11var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_FOLD));
12var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_UPPER_SIMPLE));
13var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_LOWER_SIMPLE));
14var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_TITLE_SIMPLE));
15var_dump(mb_convert_case('foo BAR Spaß', MB_CASE_FOLD_SIMPLE));
16
17// Invalid mode
18try {
19    var_dump(mb_convert_case('foo BAR Spaß', 100));
20} catch (\ValueError $e) {
21    echo $e->getMessage() . \PHP_EOL;
22}
23
24echo "\n-- Greek letter sigma --\n";
25var_dump(mb_convert_case("Σ", MB_CASE_TITLE, 'UTF-8'));
26var_dump(mb_convert_case("aΣ", MB_CASE_TITLE, 'UTF-8'));
27var_dump(mb_convert_case("aΣb", MB_CASE_TITLE, 'UTF-8'));
28var_dump(mb_convert_case("aΣ b", MB_CASE_TITLE, 'UTF-8'));
29var_dump(mb_convert_case(" ΣΣΣΣ ", MB_CASE_TITLE, 'UTF-8'));
30
31// Apostrophe, full stop, colon, etc. are "case-ignorable"
32// When checking whether capital sigma is at the end of a word or not, we skip over
33// any number of case-ignorable characters, both when scanning back and when scanning forward
34var_dump(mb_convert_case("'Σ", MB_CASE_TITLE, 'UTF-8'));
35var_dump(mb_convert_case("ab'Σ", MB_CASE_TITLE, 'UTF-8'));
36var_dump(mb_convert_case("Σ'", MB_CASE_TITLE, 'UTF-8'));
37var_dump(mb_convert_case("Σ'a", MB_CASE_TITLE, 'UTF-8'));
38var_dump(mb_convert_case("a'Σ'a", MB_CASE_TITLE, 'UTF-8'));
39
40// We scan back by at least 63 characters when necessary,
41// but there is no guarantee that we will scan back further than that
42var_dump(mb_convert_case('a' . str_repeat('.', 63) . "Σ", MB_CASE_TITLE, 'UTF-8'));
43var_dump(mb_convert_case('a' . str_repeat('.', 64) . "Σ", MB_CASE_TITLE, 'UTF-8')); // Context-sensitive casing doesn't work here!
44
45// When scanning forward to confirm if capital sigma is at the end of a word or not,
46// there is no limit as to how far we will scan
47var_dump(mb_convert_case("abcΣ" . str_repeat('.', 64) . ' abc', MB_CASE_TITLE, 'UTF-8'));
48var_dump(mb_convert_case("abcΣ" . str_repeat('.', 64) . 'a abc', MB_CASE_TITLE, 'UTF-8'));
49var_dump(mb_convert_case("abcΣ" . str_repeat('.', 256) . ' abc', MB_CASE_TITLE, 'UTF-8'));
50
51/* Regression test for new implementation;
52 * When converting a codepoint, if we overwrite it with the converted version before
53 * checking whether we should shift in/out of 'title mode', then the conversion will be incorrect */
54var_dump(bin2hex(mb_convert_case("\x01I\x01,", MB_CASE_TITLE, 'UCS-2BE')));
55var_dump(bin2hex(mb_convert_case("\x01I\x01,", MB_CASE_TITLE_SIMPLE, 'UCS-2BE')));
56
57?>
58--EXPECT--
59string(13) "FOO BAR SPASS"
60string(13) "foo bar spaß"
61string(13) "Foo Bar Spaß"
62string(13) "foo bar spass"
63string(13) "FOO BAR SPAß"
64string(13) "foo bar spaß"
65string(13) "Foo Bar Spaß"
66string(13) "foo bar spaß"
67mb_convert_case(): Argument #2 ($mode) must be one of the MB_CASE_* constants
68
69-- Greek letter sigma --
70string(2) "Σ"
71string(3) "Aς"
72string(4) "Aσb"
73string(5) "Aς B"
74string(10) " Σσσς "
75string(3) "'Σ"
76string(5) "Ab'ς"
77string(3) "Σ'"
78string(4) "Σ'a"
79string(6) "A'σ'a"
80string(66) "A...............................................................ς"
81string(67) "A................................................................σ"
82string(73) "Abcς................................................................ Abc"
83string(74) "Abcσ................................................................a Abc"
84string(265) "Abcς................................................................................................................................................................................................................................................................ Abc"
85string(12) "02bc004e012d"
86string(8) "0149012d"
87