Changeset View
Changeset View
Standalone View
Standalone View
src/parser/__tests__/PhutilEditorConfigTestCase.php
- This file was added.
<?php | |||||
final class PhutilEditorConfigTestCase extends PhutilTestCase { | |||||
public function testGetProperty() { | |||||
$parser = new PhutilEditorConfig(dirname(phutil_get_library_root())); | |||||
$tests = array( | |||||
'file' => array( | |||||
'indent_style' => 'tab', | |||||
'indent_size' => 4, | |||||
'charset' => 'utf-8', | |||||
'trim_trailing_whitespace' => true, | |||||
'insert_final_newline' => true, | |||||
), | |||||
'other-file' => array( | |||||
'indent_style' => 'tab', | |||||
'indent_size' => 4, | |||||
'charset' => 'utf-8', | |||||
), | |||||
'file.txt' => array( | |||||
'indent_style' => 'tab', | |||||
'indent_size' => 4, | |||||
'charset' => 'latin1', | |||||
'trim_trailing_whitespace' => false, | |||||
'insert_final_newline' => false, | |||||
), | |||||
); | |||||
$invalid_properties = array( | |||||
'invalid', | |||||
); | |||||
foreach ($tests as $path => $config) { | |||||
foreach ($config as $key => $value) { | |||||
$this->assertEqual( | |||||
$value, | |||||
$parser->getProperty($this->getTestFile($path), $key)); | |||||
} | |||||
$this->assertEqual( | |||||
$config, | |||||
$parser->getProperties($this->getTestFile($path))); | |||||
} | |||||
foreach ($invalid_properties as $invalid_property) { | |||||
$caught = null; | |||||
try { | |||||
$parser->getProperty('', $invalid_property); | |||||
} catch (Exception $ex) { | |||||
$caught = $ex; | |||||
} | |||||
$this->assertTrue($caught instanceof InvalidArgumentException); | |||||
} | |||||
} | |||||
private function getTestFile($path) { | |||||
return dirname(__FILE__).'/editorconfig/'.$path; | |||||
} | |||||
} |