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 class JsonFormatterTest extends TestCase
{ {
/** /**
* Test if \u0119 (196+153) will get correctly formatted * Test if \u0119 will get correctly formatted (unescaped)
* See ticket #2613 * https://github.com/composer/composer/issues/2613
*/ */
public function testUnicodeWithPrependedSlash() public function testUnicodeWithPrependedSlash()
{ {
if (!extension_loaded('mbstring')) { if (!extension_loaded('mbstring')) {
$this->markTestSkipped('Test requires the mbstring extension'); $this->markTestSkipped('Test requires the mbstring extension');
} }
$backslash = chr(92);
$data = '"' . chr(92) . chr(92) . chr(92) . 'u0119"'; $data = '"' . $backslash . $backslash . $backslash . 'u0119"';
$encodedData = JsonFormatter::format($data, true, true); $expected = '"' . $backslash . $backslash . 'ę"';
$expected = '34+92+92+196+153+34'; $this->assertEquals($expected, JsonFormatter::format($data, true, true));
$this->assertEquals($expected, $this->getCharacterCodes($encodedData));
} }
/** /**
@ -46,19 +45,4 @@ class JsonFormatterTest extends TestCase
$escaped = '"\ud83d\ude00"'; $escaped = '"\ud83d\ude00"';
$this->assertEquals($escaped, JsonFormatter::format($escaped, true, true)); $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);
}
} }