|
4 | 4 |
|
5 | 5 | use PHPUnit\Framework\TestCase; |
6 | 6 | use Toolkit\FsUtil\FS; |
| 7 | +use Toolkit\Stdlib\OS; |
7 | 8 | use function strlen; |
8 | 9 | use function vdump; |
9 | 10 |
|
@@ -37,32 +38,42 @@ public function testBasicFsMethods(): void |
37 | 38 | { |
38 | 39 | // join |
39 | 40 | $this->assertEquals('/ab', FS::join('/ab')); |
40 | | - $this->assertEquals('/ab/d', FS::join('/ab', '', 'd')); |
41 | | - $this->assertEquals('/ab/d/e', FS::join('/ab', 'd', 'e')); |
42 | 41 | $this->assertEquals('/ab', FS::join('/ab', '.')); |
43 | 42 | $this->assertEquals('/ab', FS::join('/ab', './')); |
44 | | - $this->assertEquals('/ab/cd', FS::join('/ab', './cd')); |
| 43 | + if (OS::isWindows()) { |
| 44 | + $this->assertEquals('/ab\\d', FS::join('/ab', '', 'd')); |
| 45 | + $this->assertEquals('/ab\\d\\e', FS::join('/ab', 'd', 'e')); |
| 46 | + $this->assertEquals('/ab\\cd', FS::join('/ab', './cd')); |
| 47 | + } else { |
| 48 | + $this->assertEquals('/ab/d', FS::join('/ab', 'd')); |
| 49 | + $this->assertEquals('/ab/d/e', FS::join('/ab', 'd', 'e')); |
| 50 | + $this->assertEquals('/ab/cd', FS::join('/ab', './cd')); |
| 51 | + } |
| 52 | + |
45 | 53 | } |
46 | 54 |
|
47 | 55 | public function testIsExclude_isInclude(): void |
48 | 56 | { |
49 | | - $this->assertTrue(FS::isInclude('./abc.php', [])); |
50 | | - $this->assertTrue(FS::isInclude('./abc.php', ['*'])); |
51 | | - $this->assertTrue(FS::isInclude('./abc.php', ['*.php'])); |
52 | | - $this->assertTrue(FS::isInclude('path/to/abc.php', ['*.php'])); |
53 | | - $this->assertFalse(FS::isInclude('./abc.php', ['*.xml'])); |
| 57 | + $tests = [ |
| 58 | + ['./abc.php', '*', true], |
| 59 | + ['./abc.php', '*.php', true], |
| 60 | + ['./abc.php', '*.yml', false], |
| 61 | + ['path/to/abc.php', '*.php', true], |
| 62 | + ]; |
| 63 | + foreach ($tests as $item) { |
| 64 | + $this->assertEquals($item[2], FS::isInclude($item[0], [$item[1]])); |
| 65 | + $this->assertEquals($item[2], FS::isExclude($item[0], [$item[1]])); |
| 66 | + $this->assertEquals($item[2], FS::isMatch($item[0], [$item[1]])); |
| 67 | + } |
54 | 68 |
|
| 69 | + $this->assertTrue(FS::isInclude('./abc.php', [])); |
55 | 70 | $this->assertFalse(FS::isExclude('./abc.php', [])); |
56 | | - $this->assertTrue(FS::isExclude('./abc.php', ['*'])); |
57 | | - $this->assertTrue(FS::isExclude('./abc.php', ['*.php'])); |
58 | | - $this->assertTrue(FS::isExclude('path/to/abc.php', ['*.php'])); |
59 | | - $this->assertFalse(FS::isExclude('./abc.php', ['*.yml'])); |
60 | 71 | } |
61 | 72 |
|
62 | 73 | public function testRealpath(): void |
63 | 74 | { |
64 | 75 | $rPaths = []; |
65 | | - $tests = [ |
| 76 | + $tests = [ |
66 | 77 | '~', |
67 | 78 | '~/.kite', |
68 | 79 | ]; |
|
0 commit comments