<?php
namespace Tlf\Lexer\Test;
/**
* Super cleanly written tests for use in Documentation
*/
class Documentation extends \Taeluf\Tester {
/**
*
*/
public function testParsingJson(){
//@export_start(ParsingJson)
$json = '["Cool",["yes","please"],"okay"]';
$lexer = new \Tlf\Lexer();
// $lexer->debug = true;
// $lexer->useCache = false; // useCache only matters when lexing a file
$lexer->addGrammar($jsonGrammar = new \Tlf\Lexer\JsonGrammar());
//this is the root ast
$ast = new \Tlf\Lexer\JsonAst("json"); //"json" is the type
$ast->source = $json; //Not required, but I like keeping source in the ast root.
$ast = $lexer->lexAst($ast, $json);
// $tree = $ast->getTree(); // not what we normally want with json
$data = $ast->getJsonData(); // custom method on the JsonAst class
//@export_end(ParsingJson)
$this->compare(json_decode($json), $data);
}
}