<?php
namespace gnomephp\string;
class TestParsers extends \gnomephp\testsuite\TestController{
protected function testStringParser(){
$str = "abc [b]t[/b]";
$s = new StringParser($str);
// Length ( 12 )
$this->test($s->length())->assertEqual(strlen($str));
// Test bbcode callback.
$s->addBBCodeCallback('b', function($content){ return '<strong>'.$content[1].'</strong>';});
$parsedStr = (string)$s;
$this->test($parsedStr)->assertEqual("abc <strong>t</strong>");
// Test Toc
$str = '<h1>Test</h1><h2>Test</h2>';
$s = new StringParser($str);
$s->addTocParser();
$parsedStr = (string)$s;
$this->test($parsedStr)->assertEqual('<h1 id="header-test">Test</h1><h2 id="header-test-1">Test</h2>');
// Test getting toc html
$this->test(str_replace(array("\r","\n"), '',$s->getTocHTML()))
->assertEqual('<ol><li><a href="#header-test">Test</a></li><li><a href="#header-test-1">Test</a></li></ol>');
}
protected function testPHPParser(){
$php = "notphp[php]echo '|thisisphp'; if (true){echo 'ok';}[/php]|notphp";
$s = new PHPParser($php);
$this->test((string)$s)->assertEqual('notphp|thisisphpok|notphp');
}
}