|
1 | 1 | <?php |
2 | 2 | namespace JmesPath\Tests; |
3 | 3 |
|
| 4 | +use JmesPath\AstRuntime; |
4 | 5 | use JmesPath\Utils; |
5 | 6 | use PHPUnit\Framework\TestCase; |
6 | 7 |
|
@@ -111,6 +112,31 @@ public function testSlicesStrings(): void |
111 | 112 | $this->assertEquals('ac', Utils::slice('abc', null, null, 2)); |
112 | 113 | $this->assertEquals('bc', Utils::slice('abc', 1)); |
113 | 114 | } |
| 115 | + |
| 116 | + public function testSlicesUtf8Strings(): void |
| 117 | + { |
| 118 | + $this->assertSame('é', Utils::slice('éa', 0, 1)); |
| 119 | + $this->assertSame('cbaé', Utils::slice('éabc', null, null, -1)); |
| 120 | + } |
| 121 | + |
| 122 | + public function testSlicesArrayAccessCountable(): void |
| 123 | + { |
| 124 | + $this->assertSame([1, 2], Utils::slice(new \ArrayObject([1, 2, 3]), 0, 2)); |
| 125 | + } |
| 126 | + |
| 127 | + public function testRejectsObjectLikeValuesInSlice(): void |
| 128 | + { |
| 129 | + $this->expectException(\InvalidArgumentException::class); |
| 130 | + |
| 131 | + Utils::slice(new \ArrayObject(['foo' => 'bar']), 0, 1); |
| 132 | + } |
| 133 | + |
| 134 | + public function testRuntimeSlicesArrayAccessCountable(): void |
| 135 | + { |
| 136 | + $runtime = new AstRuntime(); |
| 137 | + |
| 138 | + $this->assertSame([1, 2], $runtime('[0:2]', new \ArrayObject([1, 2, 3]))); |
| 139 | + } |
114 | 140 | } |
115 | 141 |
|
116 | 142 | class _TestClass implements \ArrayAccess |
|
0 commit comments