xref: /PHP-7.1/tests/run-test/test007.phpt (revision fa0ac8a2)
1--TEST--
2dirname test
3--FILE--
4<?php
5
6// Allow for either Win32 or Unix.
7$s = dirname("/foo");
8// $s should be either / (Unix) or \ (Win32)
9
10function check_dirname($path) {
11    global $s;
12    $path1 = str_replace("%",$s,$path);
13    $path2 = dirname($path1);
14    $path3 = str_replace($s,"%",$path2);
15    print "dirname($path) == $path3\n";
16}
17
18check_dirname("%foo%");
19check_dirname("%foo");
20check_dirname("%foo%bar");
21check_dirname("%");
22check_dirname("...%foo");
23check_dirname(".%foo");
24check_dirname("foobar%%%");
25check_dirname("%\0%\0%\0.%\0.");
26
27function same($a,$b) {
28    if ($a == $b) {
29        print "OK\n";
30    } else {
31        print "FAIL  $a == $b\n";
32    }
33}
34
35if ('/' == $s) {
36    same(".",dirname("d:\\foo\\bar.inc"));
37    same(".",dirname("c:\\foo"));
38    same(".",dirname("c:\\"));
39    same(".",dirname("c:"));
40} else {
41    same("d:\\foo",dirname("d:\\foo\\bar.inc"));
42    same("c:\\",dirname("c:\\foo"));
43    same("c:\\",dirname("c:\\"));
44    same("c:",dirname("c:"));
45}
46
47?>
48--EXPECT--
49dirname(%foo%) == %
50dirname(%foo) == %
51dirname(%foo%bar) == %foo
52dirname(%) == %
53dirname(...%foo) == ...
54dirname(.%foo) == .
55dirname(foobar%%%) == .
56dirname(%�%�%�.%�.) == %�%�%�.
57OK
58OK
59OK
60OK
61