Ejemplo n.º 1
0
 /**
  * Tests the functionality of the array matcher
  */
 public function testMatchArray()
 {
     $testArrays = ["[1, 2, 3, 4, 5]" => [1, 2, 3, 4, 5], "[1, \"abc\", 2, \"def\"]" => [1, "\"abc\"", 2, "\"def\""]];
     $parser = new Parser();
     foreach ($testArrays as $testArray => $expectedResult) {
         $tokenStream = Lexer::lex($testArray);
         $parser->setTokenStream($tokenStream);
         $parser->setTokenIndex(-1);
         $array = $parser->matchArray();
         $this->assertNotEquals($array, false, 'Array should not be false (meaning it did interpret an array)');
         $this->assertTrue($array instanceof ASTArray, 'Arrays should Parse into ASTArrays');
         $this->assertCount(count($expectedResult), $array->getElements(), 'Array doesn\'t match the expected number of items');
         foreach ($array->getElements() as $index => $element) {
             $this->assertEquals($expectedResult[$index], $element, "Element '{$element}' on index {$index} doesn't match the expected {$expectedResult[$index]}");
         }
     }
 }