@@ -263,7 +263,7 @@ public function testGeneratorQuitsAfterFirstFoundCollectionHasBeenFinished()
263263 public function testScalarResult ()
264264 {
265265 $ result = $ this ->createParser ('{"result":{"items": [1,2,3],"count": 3}} ' , '/result/count ' );
266- $ this ->assertSame ([3 ], iterator_to_array ($ result ));
266+ $ this ->assertSame ([' count ' => 3 ], iterator_to_array ($ result ));
267267 }
268268
269269 public function testScalarResultInArray ()
@@ -656,4 +656,46 @@ public function testGetPositionWorksInsideRecursion()
656656 $ this ->assertSame (0 , $ item ->getPosition ());
657657 }
658658 }
659+
660+ /**
661+ * @dataProvider data_testIssue125
662+ */
663+ public function testIssue125TheKeyOfAScalarValueAfterACompoundValueIsLost ($ tokens )
664+ {
665+ $ toAssert = [
666+ 'keytwo ' => 12 ,
667+ 'keythree ' => 13 ,
668+ ];
669+
670+ foreach ($ toAssert as $ key => $ value ) {
671+ $ items = new Parser (
672+ new \ArrayIterator ($ tokens ),
673+ "/ $ key "
674+ );
675+ $ result = iterator_to_array ($ items );
676+ $ this ->assertSame ([
677+ $ key => $ value ,
678+ ], $ result );
679+ }
680+ }
681+
682+ public function data_testIssue125 ()
683+ {
684+ return [
685+ 'after array ' => [[
686+ '{ ' ,
687+ '"keyone" ' , ': ' , '[ ' , '11 ' , '] ' , ', ' ,
688+ '"keytwo" ' , ': ' , '12 ' , ', ' ,
689+ '"keythree" ' , ': ' , '13 ' ,
690+ '} ' ,
691+ ]],
692+ 'after object ' => [[
693+ '{ ' ,
694+ '"keyone" ' , ': ' , '{ ' , '"key" ' , ': ' , '11 ' , '} ' , ', ' ,
695+ '"keytwo" ' , ': ' , '12 ' , ', ' ,
696+ '"keythree" ' , ': ' , '13 ' ,
697+ '} ' ,
698+ ]],
699+ ];
700+ }
659701}
0 commit comments