diff options
Diffstat (limited to 'tests/strings')
-rw-r--r-- | tests/strings/001.phpt | 210 | ||||
-rw-r--r-- | tests/strings/002.phpt | 83 | ||||
-rw-r--r-- | tests/strings/004.phpt | 21 | ||||
-rw-r--r-- | tests/strings/bug22592.phpt | 27 | ||||
-rw-r--r-- | tests/strings/bug26703.phpt | 17 | ||||
-rw-r--r-- | tests/strings/offsets_chaining_1.phpt | 12 | ||||
-rw-r--r-- | tests/strings/offsets_chaining_2.phpt | 12 | ||||
-rw-r--r-- | tests/strings/offsets_chaining_3.phpt | 12 | ||||
-rw-r--r-- | tests/strings/offsets_chaining_4.phpt | 12 | ||||
-rw-r--r-- | tests/strings/offsets_chaining_5.phpt | 27 | ||||
-rw-r--r-- | tests/strings/offsets_general.phpt | 38 |
11 files changed, 471 insertions, 0 deletions
diff --git a/tests/strings/001.phpt b/tests/strings/001.phpt new file mode 100644 index 0000000..3bfd3db --- /dev/null +++ b/tests/strings/001.phpt @@ -0,0 +1,210 @@ +--TEST-- +String functions +--FILE-- +<?php + +error_reporting(0); + +echo "Testing strtok: "; + +$str = "testing 1/2\\3"; +$tok1 = strtok($str, " "); +$tok2 = strtok("/"); +$tok3 = strtok("\\"); +$tok4 = strtok("."); +if ($tok1 != "testing") { + echo("failed 1\n"); +} elseif ($tok2 != "1") { + echo("failed 2\n"); +} elseif ($tok3 != "2") { + echo("failed 3\n"); +} elseif ($tok4 != "3") { + echo("failed 4\n"); +} else { + echo("passed\n"); +} + +echo "Testing strstr: "; +$test = "This is a test"; +$found1 = strstr($test, 32); +$found2 = strstr($test, "a "); +if ($found1 != " is a test") { + echo("failed 1\n"); +} elseif ($found2 != "a test") { + echo("failed 2\n"); +} else { + echo("passed\n"); +} + +echo "Testing strrchr: "; +$test = "fola fola blakken"; +$found1 = strrchr($test, "b"); +$found2 = strrchr($test, 102); +if ($found1 != "blakken") { + echo("failed 1\n"); +} elseif ($found2 != "fola blakken") { + echo("failed 2\n"); +} +else { + echo("passed\n"); +} + +echo "Testing strtoupper: "; +$test = "abCdEfg"; +$upper = strtoupper($test); +if ($upper == "ABCDEFG") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing strtolower: "; +$test = "ABcDeFG"; +$lower = strtolower($test); +if ($lower == "abcdefg") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing substr: "; +$tests = $ok = 0; +$string = "string12345"; +$tests++; if (substr($string, 2, 10) == "ring12345") { $ok++; } +$tests++; if (substr($string, 4, 7) == "ng12345") { $ok++; } +$tests++; if (substr($string, 4) == "ng12345") { $ok++; } +$tests++; if (substr($string, 10, 2) == "5") { $ok++; } +$tests++; if (substr($string, 6, 0) == "") { $ok++; } +$tests++; if (substr($string, -2, 2) == "45") { $ok++; } +$tests++; if (substr($string, 1, -1) == "tring1234") { $ok++; } +$tests++; if (substr($string, -1, -2) == "") { $ok++; } +$tests++; if (substr($string, -3, -2) == "3") { $ok++; } + +if ($tests == $ok) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +$raw = ' !"#$%&\'()*+,-./0123456789:;<=>?' + . '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_' + . '`abcdefghijklmnopqrstuvwxyz{|}~' + . "\0"; + +echo "Testing rawurlencode: "; +$encoded = rawurlencode($raw); +$correct = '%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F' + . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_' + . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~' + . '%00'; +if ($encoded == $correct) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing rawurldecode: "; +$decoded = rawurldecode($correct); +if ($decoded == $raw) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing urlencode: "; +$encoded = urlencode($raw); +$correct = '+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F' + . '%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_' + . '%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E' + . '%00'; +if ($encoded == $correct) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing urldecode: "; +$decoded = urldecode($correct); +if ($decoded == $raw) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing quotemeta: "; +$raw = "a.\\+*?" . chr(91) . "^" . chr(93) . "b\$c"; +$quoted = quotemeta($raw); +if ($quoted == "a\\.\\\\\\+\\*\\?\\[\\^\\]b\\\$c") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing ufirst: "; +$str = "fahrvergnuegen"; +$uc = ucfirst($str); +if ($uc == "Fahrvergnuegen") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing strtr: "; +$str = "test abcdefgh"; +$tr = strtr($str, "def", "456"); +if ($tr == "t5st abc456gh") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing addslashes: "; +$str = "\"\\'"; +$as = addslashes($str); +if ($as == "\\\"\\\\\\'") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +echo "Testing stripslashes: "; +$str = "\$\\'"; +$ss = stripslashes($str); +if ($ss == "\$'") { + echo("passed\n"); +} else { + echo("failed!\n"); +} + + +echo "Testing uniqid: "; +$str = "prefix"; +$ui1 = uniqid($str); +$ui2 = uniqid($str); + +$len = strncasecmp(PHP_OS, 'CYGWIN', 6) ? 19 : 29; + +if (strlen($ui1) == strlen($ui2) && strlen($ui1) == $len && $ui1 != $ui2) { + echo("passed\n"); +} else { + echo("failed!\n"); +} + +?> +--EXPECT-- +Testing strtok: passed +Testing strstr: passed +Testing strrchr: passed +Testing strtoupper: passed +Testing strtolower: passed +Testing substr: passed +Testing rawurlencode: passed +Testing rawurldecode: passed +Testing urlencode: passed +Testing urldecode: passed +Testing quotemeta: passed +Testing ufirst: passed +Testing strtr: passed +Testing addslashes: passed +Testing stripslashes: passed +Testing uniqid: passed diff --git a/tests/strings/002.phpt b/tests/strings/002.phpt new file mode 100644 index 0000000..7b95a25 --- /dev/null +++ b/tests/strings/002.phpt @@ -0,0 +1,83 @@ +--TEST-- +Formatted print functions +--FILE-- +<?php +error_reporting(0); + +$fp = fopen("php://stdout", "w") or die("Arrggsgg!!"); +$x = fprintf($fp, "fprintf test 1:%.5s", "abcdefghij"); +echo "\n"; +var_dump($x); + +printf("printf test 1:%s\n", "simple string"); +printf("printf test 2:%d\n", 42); +printf("printf test 3:%f\n", 10.0/3); +printf("printf test 4:%.10f\n", 10.0/3); +printf("printf test 5:%-10.2f\n", 2.5); +printf("printf test 6:%-010.2f\n", 2.5); +printf("printf test 7:%010.2f\n", 2.5); +printf("printf test 8:<%20s>\n", "foo"); +printf("printf test 9:<%-20s>\n", "bar"); +printf("printf test 10: 123456789012345\n"); +printf("printf test 10:<%15s>\n", "høyesterettsjustitiarius"); +printf("printf test 11: 123456789012345678901234567890\n"); +printf("printf test 11:<%30s>\n", "høyesterettsjustitiarius"); +printf("printf test 12:%5.2f\n", -12.34); +printf("printf test 13:%5d\n", -12); +printf("printf test 14:%c\n", 64); +printf("printf test 15:%b\n", 170); +printf("printf test 16:%x\n", 170); +printf("printf test 17:%X\n", 170); +printf("printf test 18:%16b\n", 170); +printf("printf test 19:%16x\n", 170); +printf("printf test 20:%16X\n", 170); +printf("printf test 21:%016b\n", 170); +printf("printf test 22:%016x\n", 170); +printf("printf test 23:%016X\n", 170); +printf("printf test 24:%.5s\n", "abcdefghij"); +printf("printf test 25:%-2s\n", "gazonk"); +printf("printf test 26:%2\$d %1\$d\n", 1, 2); +printf("printf test 27:%3\$d %d %d\n", 1, 2, 3); +printf("printf test 28:%2\$02d %1\$2d\n", 1, 2); +printf("printf test 29:%2\$-2d %1\$2d\n", 1, 2); +print("printf test 30:"); printf("%0\$s", 1); print("x\n"); +vprintf("vprintf test 1:%2\$-2d %1\$2d\n", array(1, 2)); + + +?> +--EXPECT-- +fprintf test 1:abcde +int(20) +printf test 1:simple string +printf test 2:42 +printf test 3:3.333333 +printf test 4:3.3333333333 +printf test 5:2.50 +printf test 6:2.50000000 +printf test 7:0000002.50 +printf test 8:< foo> +printf test 9:<bar > +printf test 10: 123456789012345 +printf test 10:<høyesterettsjustitiarius> +printf test 11: 123456789012345678901234567890 +printf test 11:< høyesterettsjustitiarius> +printf test 12:-12.34 +printf test 13: -12 +printf test 14:@ +printf test 15:10101010 +printf test 16:aa +printf test 17:AA +printf test 18: 10101010 +printf test 19: aa +printf test 20: AA +printf test 21:0000000010101010 +printf test 22:00000000000000aa +printf test 23:00000000000000AA +printf test 24:abcde +printf test 25:gazonk +printf test 26:2 1 +printf test 27:3 1 2 +printf test 28:02 1 +printf test 29:2 1 +printf test 30:x +vprintf test 1:2 1 diff --git a/tests/strings/004.phpt b/tests/strings/004.phpt new file mode 100644 index 0000000..7bcb452 --- /dev/null +++ b/tests/strings/004.phpt @@ -0,0 +1,21 @@ +--TEST-- +highlight_string() buffering +--INI-- +highlight.string=#DD0000 +highlight.comment=#FF9900 +highlight.keyword=#007700 +highlight.default=#0000BB +highlight.html=#000000 +--FILE-- +<?php +$var = highlight_string("<br /><?php echo \"foo\"; ?><br />"); +$var = highlight_string("<br /><?php echo \"bar\"; ?><br />", TRUE); +echo "\n[$var]\n"; +?> +--EXPECT-- +<code><span style="color: #000000"> +<br /><span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">"foo"</span><span style="color: #007700">; </span><span style="color: #0000BB">?></span><br /></span> +</code> +[<code><span style="color: #000000"> +<br /><span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">"bar"</span><span style="color: #007700">; </span><span style="color: #0000BB">?></span><br /></span> +</code>] diff --git a/tests/strings/bug22592.phpt b/tests/strings/bug22592.phpt new file mode 100644 index 0000000..3443c32 --- /dev/null +++ b/tests/strings/bug22592.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #22592 (Cascading assignments to strings with curly braces broken) +--FILE-- +<?php +$wrong = $correct = 'abcdef'; + +$t = $x[] = 'x'; + +var_dump($correct); +var_dump($wrong); + +$correct[1] = '*'; +$correct[3] = '*'; +$correct[5] = '*'; + +// This produces the +$wrong[1] = $wrong[3] = $wrong[5] = '*'; + +var_dump($correct); +var_dump($wrong); + +?> +--EXPECT-- +string(6) "abcdef" +string(6) "abcdef" +string(6) "a*c*e*" +string(6) "a*c*e*" diff --git a/tests/strings/bug26703.phpt b/tests/strings/bug26703.phpt new file mode 100644 index 0000000..bea8fb1 --- /dev/null +++ b/tests/strings/bug26703.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #26703 (Certain characters inside strings incorrectly treated as keywords) +--INI-- +highlight.string=#DD0000 +highlight.comment=#FF9900 +highlight.keyword=#007700 +highlight.default=#0000BB +highlight.html=#000000 +--FILE-- +<?php + highlight_string('<?php echo "foo[] $a \n"; ?>'); +?> +--EXPECT-- +<code><span style="color: #000000"> +<span style="color: #0000BB"><?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">"foo[] </span><span style="color: #0000BB">$a</span><span style="color: #DD0000"> \n"</span><span style="color: #007700">; </span><span style="color: #0000BB">?></span> +</span> +</code> diff --git a/tests/strings/offsets_chaining_1.phpt b/tests/strings/offsets_chaining_1.phpt new file mode 100644 index 0000000..eecdfb9 --- /dev/null +++ b/tests/strings/offsets_chaining_1.phpt @@ -0,0 +1,12 @@ +--TEST-- +testing the behavior of string offset chaining +--INI-- +error_reporting=E_ALL | E_DEPRECATED +--FILE-- +<?php +$string = "foobar"; +var_dump($string[0][0][0][0]); +?> +--EXPECTF-- +string(1) "f" + diff --git a/tests/strings/offsets_chaining_2.phpt b/tests/strings/offsets_chaining_2.phpt new file mode 100644 index 0000000..07f67f0 --- /dev/null +++ b/tests/strings/offsets_chaining_2.phpt @@ -0,0 +1,12 @@ +--TEST-- +testing the behavior of string offset chaining +--INI-- +error_reporting=E_ALL | E_DEPRECATED +--FILE-- +<?php +$string = "foobar"; +var_dump($string{0}{0}[0][0]); +?> +--EXPECTF-- +string(1) "f" + diff --git a/tests/strings/offsets_chaining_3.phpt b/tests/strings/offsets_chaining_3.phpt new file mode 100644 index 0000000..23b8e70 --- /dev/null +++ b/tests/strings/offsets_chaining_3.phpt @@ -0,0 +1,12 @@ +--TEST-- +testing the behavior of string offset chaining +--INI-- +error_reporting=E_ALL | E_DEPRECATED +--FILE-- +<?php +$string = "foobar"; +var_dump(isset($string[0][0][0][0])); +?> +--EXPECTF-- +bool(true) + diff --git a/tests/strings/offsets_chaining_4.phpt b/tests/strings/offsets_chaining_4.phpt new file mode 100644 index 0000000..79b95c1 --- /dev/null +++ b/tests/strings/offsets_chaining_4.phpt @@ -0,0 +1,12 @@ +--TEST-- +testing the behavior of string offset chaining +--INI-- +error_reporting=E_ALL | E_DEPRECATED +--FILE-- +<?php +$string = "foobar"; +var_dump(isset($string{0}{0}[0][0])); +?> +--EXPECTF-- +bool(true) + diff --git a/tests/strings/offsets_chaining_5.phpt b/tests/strings/offsets_chaining_5.phpt new file mode 100644 index 0000000..efcf2f3 --- /dev/null +++ b/tests/strings/offsets_chaining_5.phpt @@ -0,0 +1,27 @@ +--TEST-- +testing the behavior of string offset chaining +--INI-- +error_reporting=E_ALL | E_DEPRECATED +--FILE-- +<?php +$array = array('expected_array' => "foobar"); +var_dump(isset($array['expected_array'])); +var_dump($array['expected_array']); +var_dump(isset($array['expected_array']['foo'])); +var_dump($array['expected_array']['foo']); +var_dump(isset($array['expected_array']['foo']['bar'])); +var_dump($array['expected_array']['foo']['bar']); +?> +--EXPECTF-- +bool(true) +string(6) "foobar" +bool(false) + +Warning: Illegal string offset 'foo' in %soffsets_chaining_5.php on line %d +string(1) "f" +bool(false) + +Warning: Illegal string offset 'foo' in %soffsets_chaining_5.php on line %d + +Warning: Illegal string offset 'bar' in %soffsets_chaining_5.php on line %d +string(1) "f" diff --git a/tests/strings/offsets_general.phpt b/tests/strings/offsets_general.phpt new file mode 100644 index 0000000..9d69ea2 --- /dev/null +++ b/tests/strings/offsets_general.phpt @@ -0,0 +1,38 @@ +--TEST-- +testing the behavior of string offsets +--INI-- +error_reporting=E_ALL | E_DEPRECATED +--FILE-- +<?php +$string = "foobar"; +var_dump($string[0]); +var_dump($string[1]); +var_dump(isset($string[0])); +var_dump(isset($string[0][0])); +var_dump($string["foo"]); +var_dump(isset($string["foo"]["bar"])); +var_dump($string{0}); +var_dump($string{1}); +var_dump(isset($string{0})); +var_dump(isset($string{0}{0})); +var_dump($string{"foo"}); +var_dump(isset($string{"foo"}{"bar"})); +?> +--EXPECTF-- +string(1) "f" +string(1) "o" +bool(true) +bool(true) + +Warning: Illegal string offset 'foo' in %s line %d +string(1) "f" +bool(false) +string(1) "f" +string(1) "o" +bool(true) +bool(true) + +Warning: Illegal string offset 'foo' in %s line %d +string(1) "f" +bool(false) + |