2011-08-20 10:40:27 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-06 14:44:16 +01:00
|
|
|
namespace PhpParser\Node\Scalar;
|
|
|
|
|
2017-04-27 18:14:07 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class StringTest extends TestCase
|
2011-08-20 10:40:27 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider provideTestParseEscapeSequences
|
|
|
|
*/
|
|
|
|
public function testParseEscapeSequences($expected, $string, $quote) {
|
2014-09-30 20:38:09 +02:00
|
|
|
$this->assertSame(
|
2011-08-20 10:40:27 +02:00
|
|
|
$expected,
|
2015-03-20 21:47:20 +01:00
|
|
|
String_::parseEscapeSequences($string, $quote)
|
2011-08-20 10:40:27 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-10-19 15:17:08 +02:00
|
|
|
* @dataProvider provideTestParse
|
2011-08-20 10:40:27 +02:00
|
|
|
*/
|
|
|
|
public function testCreate($expected, $string) {
|
2014-09-30 20:38:09 +02:00
|
|
|
$this->assertSame(
|
2011-08-20 10:40:27 +02:00
|
|
|
$expected,
|
2015-03-20 21:47:20 +01:00
|
|
|
String_::parse($string)
|
2011-08-20 10:40:27 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideTestParseEscapeSequences() {
|
|
|
|
return array(
|
|
|
|
array('"', '\\"', '"'),
|
|
|
|
array('\\"', '\\"', '`'),
|
|
|
|
array('\\"\\`', '\\"\\`', null),
|
|
|
|
array("\\\$\n\r\t\f\v", '\\\\\$\n\r\t\f\v', null),
|
2011-12-04 17:35:30 +01:00
|
|
|
array("\x1B", '\e', null),
|
2011-08-20 10:40:27 +02:00
|
|
|
array(chr(255), '\xFF', null),
|
|
|
|
array(chr(255), '\377', null),
|
|
|
|
array(chr(0), '\400', null),
|
|
|
|
array("\0", '\0', null),
|
|
|
|
array('\xFF', '\\\\xFF', null),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-10-19 15:17:08 +02:00
|
|
|
public function provideTestParse() {
|
2011-08-20 10:40:27 +02:00
|
|
|
$tests = array(
|
|
|
|
array('A', '\'A\''),
|
|
|
|
array('A', 'b\'A\''),
|
|
|
|
array('A', '"A"'),
|
|
|
|
array('A', 'b"A"'),
|
|
|
|
array('\\', '\'\\\\\''),
|
|
|
|
array('\'', '\'\\\'\''),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($this->provideTestParseEscapeSequences() as $i => $test) {
|
|
|
|
// skip second and third tests, they aren't for double quotes
|
|
|
|
if ($i != 1 && $i != 2) {
|
|
|
|
$tests[] = array($test[0], '"' . $test[1] . '"');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tests;
|
|
|
|
}
|
2015-03-20 21:47:20 +01:00
|
|
|
}
|