1
0
Fork 0

Make JSON formatter test clearer

pull/7552/head^2
Alexander Kurilo 2018-08-07 23:20:08 +03:00 committed by Jordi Boggiano
parent 5a22a4f1f3
commit e1a6bd5ff1
1 changed files with 6 additions and 22 deletions

View File

@ -18,19 +18,18 @@ use PHPUnit\Framework\TestCase;
class JsonFormatterTest extends TestCase
{
/**
* Test if \u0119 (196+153) will get correctly formatted
* See ticket #2613
* Test if \u0119 will get correctly formatted (unescaped)
* https://github.com/composer/composer/issues/2613
*/
public function testUnicodeWithPrependedSlash()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped('Test requires the mbstring extension');
}
$data = '"' . chr(92) . chr(92) . chr(92) . 'u0119"';
$encodedData = JsonFormatter::format($data, true, true);
$expected = '34+92+92+196+153+34';
$this->assertEquals($expected, $this->getCharacterCodes($encodedData));
$backslash = chr(92);
$data = '"' . $backslash . $backslash . $backslash . 'u0119"';
$expected = '"' . $backslash . $backslash . 'ę"';
$this->assertEquals($expected, JsonFormatter::format($data, true, true));
}
/**
@ -46,19 +45,4 @@ class JsonFormatterTest extends TestCase
$escaped = '"\ud83d\ude00"';
$this->assertEquals($escaped, JsonFormatter::format($escaped, true, true));
}
/**
* Convert string to character codes split by a plus sign
* @param string $string
* @return string
*/
protected function getCharacterCodes($string)
{
$codes = array();
for ($i = 0; $i < strlen($string); $i++) {
$codes[] = ord($string[$i]);
}
return implode('+', $codes);
}
}