Changeset View
Changeset View
Standalone View
Standalone View
src/utils/__tests__/PhutilUtilsTestCase.php
Show First 20 Lines • Show All 499 Lines • ▼ Show 20 Lines | foreach ($bad_cases as $input) { | ||||
$this->assertTrue( | $this->assertTrue( | ||||
($caught instanceof InvalidArgumentException), | ($caught instanceof InvalidArgumentException), | ||||
'phutil_units("'.$input.'")'); | 'phutil_units("'.$input.'")'); | ||||
} | } | ||||
} | } | ||||
public function testPhutilJSONDecode() { | public function testPhutilJSONDecode() { | ||||
$valid_cases = array( | $valid_cases = array( | ||||
'null' => null, | |||||
'false' => false, | |||||
'true' => true, | |||||
'"string"' => 'string', | |||||
'123' => 123, | |||||
'{}' => array(), | '{}' => array(), | ||||
'[]' => array(), | '[]' => array(), | ||||
'[1, 2]' => array(1, 2), | '[1, 2]' => array(1, 2), | ||||
'{"a":"b"}' => array('a' => 'b'), | '{"a":"b"}' => array('a' => 'b'), | ||||
); | ); | ||||
foreach ($valid_cases as $input => $expect) { | foreach ($valid_cases as $input => $expect) { | ||||
$result = phutil_json_decode($input); | $result = phutil_json_decode($input); | ||||
$this->assertEqual($expect, $result, 'phutil_json_decode('.$input.')'); | $this->assertEqual($expect, $result, 'phutil_json_decode('.$input.')'); | ||||
} | } | ||||
$invalid_cases = array( | $invalid_cases = array( | ||||
'', | 'nil', | ||||
'"a"', | |||||
'{,}', | '{,}', | ||||
'null', | '[,]', | ||||
'"null"', | '{', | ||||
); | ); | ||||
foreach ($invalid_cases as $input) { | foreach ($invalid_cases as $input) { | ||||
$caught = null; | $caught = null; | ||||
try { | try { | ||||
phutil_json_decode($input); | phutil_json_decode($input); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$caught = $ex; | $caught = $ex; | ||||
▲ Show 20 Lines • Show All 248 Lines • Show Last 20 Lines |