2x faster. Who needs a Buffer instance, anyway?
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Mustache.php.
|
||||
*
|
||||
* (c) 2012 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mustache\Test;
|
||||
|
||||
use Mustache\Mustache;
|
||||
use Mustache\Buffer;
|
||||
|
||||
/**
|
||||
* @group unit
|
||||
*/
|
||||
class BufferTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @dataProvider getConstructorArgs
|
||||
*/
|
||||
public function testConstructor($indent, $charset) {
|
||||
$buffer = new Buffer($indent, $charset);
|
||||
$this->assertEquals($indent, $buffer->getIndent());
|
||||
$this->assertEquals($charset, $buffer->getCharset());
|
||||
}
|
||||
|
||||
public function getConstructorArgs() {
|
||||
return array(
|
||||
array('', 'UTF-8'),
|
||||
array(' ', 'ISO-8859-1'),
|
||||
array("\t\t\t", 'Shift_JIS'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testWrite() {
|
||||
$buffer = new Buffer;
|
||||
$this->assertEquals('', $buffer->flush());
|
||||
|
||||
$buffer->writeLine();
|
||||
$buffer->writeLine();
|
||||
$buffer->writeLine();
|
||||
$this->assertEquals("\n\n\n", $buffer->flush());
|
||||
$this->assertEquals('', $buffer->flush());
|
||||
|
||||
$buffer->write('foo');
|
||||
$buffer->write('bar');
|
||||
$buffer->writeLine();
|
||||
$buffer->write('baz');
|
||||
$this->assertEquals("foobar\nbaz", $buffer->flush());
|
||||
$this->assertEquals('', $buffer->flush());
|
||||
|
||||
$indent = "\t\t";
|
||||
$buffer->setIndent($indent);
|
||||
$buffer->writeText('foo');
|
||||
$buffer->writeLine();
|
||||
$buffer->writeText('bar');
|
||||
$this->assertEquals("\t\tfoo\n\t\tbar", $buffer->flush());
|
||||
$this->assertEquals('', $buffer->flush());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getEscapeAndIndent
|
||||
*/
|
||||
public function testEscapingAndIndenting($text, $escape, $indent, $whitespace, $expected) {
|
||||
$buffer = new Buffer;
|
||||
$buffer->setIndent($whitespace);
|
||||
|
||||
$buffer->write($text, $indent, $escape);
|
||||
$this->assertEquals($expected, $buffer->flush());
|
||||
}
|
||||
|
||||
public function getEscapeAndIndent() {
|
||||
return array(
|
||||
array('> "fun & games" <', false, false, "\t", '> "fun & games" <'),
|
||||
array('> "fun & games" <', true, false, "\t", '> "fun & games" <'),
|
||||
array('> "fun & games" <', true, true, "\t", "\t> "fun & games" <"),
|
||||
array('> "fun & games" <', false, true, "\t", "\t> \"fun & games\" <"),
|
||||
);
|
||||
}
|
||||
|
||||
public function testChangeIndent() {
|
||||
$indent = "\t\t";
|
||||
$buffer = new Buffer($indent);
|
||||
$this->assertEquals($indent, $buffer->getIndent());
|
||||
|
||||
$indent = "";
|
||||
$buffer->setIndent($indent);
|
||||
$this->assertEquals($indent, $buffer->getIndent());
|
||||
|
||||
$indent = " ";
|
||||
$buffer->setIndent($indent);
|
||||
$this->assertEquals($indent, $buffer->getIndent());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,13 +35,13 @@ class CompilerTest extends \PHPUnit_Framework_TestCase {
|
||||
return array(
|
||||
array('', array(), 'Banana', array(
|
||||
"\nclass Banana extends \Mustache\Template",
|
||||
'$buffer->flush();',
|
||||
'return $buffer;',
|
||||
)),
|
||||
|
||||
array('', array('TEXT'), 'Monkey', array(
|
||||
"\nclass Monkey extends \Mustache\Template",
|
||||
'$buffer->writeText(\'TEXT\');',
|
||||
'$buffer->flush();',
|
||||
'$buffer .= $indent . \'TEXT\';',
|
||||
'return $buffer;',
|
||||
)),
|
||||
|
||||
array(
|
||||
@@ -62,13 +62,13 @@ class CompilerTest extends \PHPUnit_Framework_TestCase {
|
||||
'Monkey',
|
||||
array(
|
||||
"\nclass Monkey extends \Mustache\Template",
|
||||
'$buffer->writeText(\'foo\');',
|
||||
'$buffer->writeLine();',
|
||||
'$buffer .= $indent . \'foo\'',
|
||||
'$buffer .= "\n"',
|
||||
'$value = $context->find(\'name\');',
|
||||
'$buffer->writeText($value, true);',
|
||||
'$buffer .= $indent . htmlspecialchars($value, ENT_COMPAT, $this->mustache->getCharset());',
|
||||
'$value = $context->last();',
|
||||
'$buffer->writeText(\'\\\'bar\\\'\');',
|
||||
'$buffer->flush();',
|
||||
'$buffer .= $indent . \'\\\'bar\\\'\';',
|
||||
'return $buffer;',
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ class TemplateStub extends Template {
|
||||
return $this->mustache;
|
||||
}
|
||||
|
||||
public function renderInternal(Context $context) {
|
||||
public function renderInternal(Context $context, $indent = '', $escape = false) {
|
||||
return $this->rendered;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user