Differential D19089 Diff 45754 src/applications/typeahead/datasource/__tests__/PhabricatorTypeaheadDatasourceTestCase.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/typeahead/datasource/__tests__/PhabricatorTypeaheadDatasourceTestCase.php
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | final class PhabricatorTypeaheadDatasourceTestCase | ||||
private function assertTokenization($input, $expect) { | private function assertTokenization($input, $expect) { | ||||
$this->assertEqual( | $this->assertEqual( | ||||
$expect, | $expect, | ||||
PhabricatorTypeaheadDatasource::tokenizeString($input), | PhabricatorTypeaheadDatasource::tokenizeString($input), | ||||
pht('Tokenization of "%s"', $input)); | pht('Tokenization of "%s"', $input)); | ||||
} | } | ||||
public function testFunctionEvaluation() { | |||||
$viewer = PhabricatorUser::getOmnipotentUser(); | |||||
$datasource = id(new PhabricatorTypeaheadTestNumbersDatasource()) | |||||
->setViewer($viewer); | |||||
$constraints = $datasource->evaluateTokens( | |||||
array( | |||||
9, | |||||
'seven()', | |||||
12, | |||||
3, | |||||
)); | |||||
$this->assertEqual( | |||||
array(9, 7, 12, 3), | |||||
$constraints); | |||||
$map = array( | |||||
'inc(3)' => 4, | |||||
'sum(3, 4)' => 7, | |||||
'inc(seven())' => 8, | |||||
'inc(inc(3))' => 5, | |||||
'inc(inc(seven()))' => 9, | |||||
'sum(seven(), seven())' => 14, | |||||
'sum(inc(seven()), inc(inc(9)))' => 19, | |||||
); | |||||
foreach ($map as $input => $expect) { | |||||
$constraints = $datasource->evaluateTokens( | |||||
array( | |||||
$input, | |||||
)); | |||||
$this->assertEqual( | |||||
array($expect), | |||||
$constraints, | |||||
pht('Constraints for input "%s".', $input)); | |||||
} | |||||
} | |||||
} | } |