From db36d263badd9a496f8bb4cd9231e7d6a7f3dee7 Mon Sep 17 00:00:00 2001 From: Smoren Date: Sun, 17 Mar 2024 19:43:17 +0300 Subject: [PATCH] More example tests added. --- tests/unit/Examples/ExamplesTest.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unit/Examples/ExamplesTest.php b/tests/unit/Examples/ExamplesTest.php index 025233c..4bbed6d 100644 --- a/tests/unit/Examples/ExamplesTest.php +++ b/tests/unit/Examples/ExamplesTest.php @@ -159,4 +159,29 @@ public function testSelectorsPipe() $subview[':'] = [55, 77]; $this->assertSame([1, 2, 3, 4, 55, 6, 77, 8, 9, 10], $originalArray); } + + public function testSelectorsPipeNested() + { + $originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + + $selector = new PipeSelector([ + new SliceSelector('::2'), + new PipeSelector([ + new MaskSelector([true, false, true, true, true]), + new IndexListSelector([0, 1, 2]), + ]), + new SliceSelector('1:'), + ]); + + $view = ArrayView::toView($originalArray); + $this->assertTrue(isset($view[$selector])); + + $subview = $view->subview($selector); + + $this->assertSame([5, 7], $subview->toArray()); + $this->assertSame([5, 7], $subview[':']); + + $subview[':'] = [55, 77]; + $this->assertSame([1, 2, 3, 4, 55, 6, 77, 8, 9, 10], $originalArray); + } }