From 457560137d64777779d3cd3838515a0e83463af3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 14 Apr 2021 19:00:37 -0400 Subject: [PATCH] Comments and tests --- src/FileType.php | 13 ++++++++++++- src/Row.php | 2 -- src/Syntax.php | 12 ++++++++++-- tests/Type/PointTest.php | 24 ++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 tests/Type/PointTest.php diff --git a/src/FileType.php b/src/FileType.php index c800c9b..e8ed1b3 100644 --- a/src/FileType.php +++ b/src/FileType.php @@ -3,7 +3,12 @@ namespace Aviat\Kilo; class FileType { - + /** + * Create the FileType object from the filename + * + * @param string|null $filename + * @return self + */ public static function from(?string $filename): self { $syntax = self::getSyntaxFromFilename((string)$filename); @@ -11,6 +16,12 @@ class FileType { return new self($syntax->filetype, $syntax); } + /** + * Create the Syntax object from the filename + * + * @param string $filename + * @return Syntax + */ private static function getSyntaxFromFilename(string $filename): Syntax { $ext = strstr(basename($filename), '.'); diff --git a/src/Row.php b/src/Row.php index 9d7dab9..8874806 100644 --- a/src/Row.php +++ b/src/Row.php @@ -11,8 +11,6 @@ use Aviat\Kilo\Enum\RawKeyCode; * @property-read string $chars */ class Row { - // use Traits\MagicProperties; - /** * The version of the row to be displayed (where tabs are converted to display spaces) */ diff --git a/src/Syntax.php b/src/Syntax.php index d311b14..06ac164 100644 --- a/src/Syntax.php +++ b/src/Syntax.php @@ -41,7 +41,15 @@ class Syntax { public static function default(): self { - return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false, hasCommonOperators: false); + return self::new( + 'No filetype', slcs: + '', mcs: + '', mce: + '', + highlightNumbers: false, + highlightStrings: false, + hasCommonOperators: false, + ); } private function __construct( @@ -57,7 +65,7 @@ class Syntax { public string $singleLineCommentStart, /** Syntax to start a multi-line comment */ public string $multiLineCommentStart, - /** Syntax to end a multi-line commment */ + /** Syntax to end a multi-line comment */ public string $multiLineCommentEnd, /** Should we highlight numbers? */ private bool $highlightNumbers, diff --git a/tests/Type/PointTest.php b/tests/Type/PointTest.php new file mode 100644 index 0000000..5b4c4e2 --- /dev/null +++ b/tests/Type/PointTest.php @@ -0,0 +1,24 @@ +assertEquals(1, $p->x); + $this->assertEquals(2, $p->y); + } + + public function testPointFrom(): void + { + $p = Point::new(3, 7); + $p2 = Point::from($p); + + $this->assertEquals($p->x, $p2->x); + $this->assertEquals($p->y, $p2->y); + } +}