Compare commits

...

2 Commits

Author SHA1 Message Date
Timothy Warren a50c22c0e0 Fix more tests
timw4mail/php-kilo/pipeline/head This commit looks good Details
2021-04-14 14:40:35 -04:00
Timothy Warren 8f5986e91e Resolve merge conflict 2021-04-14 13:24:13 -04:00
10 changed files with 153 additions and 149 deletions

View File

@ -14,7 +14,7 @@
</coverage> </coverage>
<testsuites> <testsuites>
<testsuite name="PHPKilo"> <testsuite name="PHPKilo">
<directory phpVersion="7.4.0" phpVersionOperator="&gt;=">tests</directory> <directory phpVersion="8.0.0" phpVersionOperator="&gt;=">tests</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<logging/> <logging/>

View File

@ -105,12 +105,12 @@ class Document {
if ($c === KeyType::ENTER || $c === RawKeyCode::CARRIAGE_RETURN) if ($c === KeyType::ENTER || $c === RawKeyCode::CARRIAGE_RETURN)
{ {
$this->insertNewline($at); $this->insertNewline($at);
$this->dirty = true;
return; return;
} }
$this->dirty = true;
$this->rows[$at->y]->insert($at->x, $c); $this->rows[$at->y]->insert($at->x, $c);
$this->dirty = true;
} }
public function delete(Point $at): void public function delete(Point $at): void
@ -120,7 +120,6 @@ class Document {
return; return;
} }
$this->dirty = true;
$row =& $this->rows[$at->y]; $row =& $this->rows[$at->y];
if ($at->x === $this->rows[$at->y]->size && $at->y + 1 < $this->numRows) if ($at->x === $this->rows[$at->y]->size && $at->y + 1 < $this->numRows)
@ -132,6 +131,8 @@ class Document {
{ {
$row->delete($at->x); $row->delete($at->x);
} }
$this->dirty = true;
} }
public function insertRow(int $at, string $s, bool $updateSyntax = TRUE): void public function insertRow(int $at, string $s, bool $updateSyntax = TRUE): void
@ -171,6 +172,8 @@ class Document {
{ {
$this->refreshPHPSyntax(); $this->refreshPHPSyntax();
} }
$this->dirty = true;
} }
protected function deleteRow(int $at): void protected function deleteRow(int $at): void
@ -223,11 +226,13 @@ class Document {
$newChars = substr($chars, 0, $at->x); $newChars = substr($chars, 0, $at->x);
// Truncate the previous row // Truncate the previous row
$row->chars = $newChars; $row->setChars($newChars);
// Add a new row with the contents of the previous row at the point of the split // Add a new row with the contents of the previous row at the point of the split
$this->insertRow($at->y + 1, substr($chars, $at->x)); $this->insertRow($at->y + 1, substr($chars, $at->x));
} }
$this->dirty = true;
} }
protected function selectSyntaxHighlight(): void protected function selectSyntaxHighlight(): void
@ -255,7 +260,7 @@ class Document {
public function refreshSyntax(): void public function refreshSyntax(): void
{ {
// Update the syntax highlighting for all the rows of the file // Update the syntax highlighting for all the rows of the file
array_walk($this->rows, static fn (Row $row) => $row->highlight()); array_walk($this->rows, static fn (Row $row) => $row->update());
} }
private function refreshPHPSyntax(): void private function refreshPHPSyntax(): void

View File

@ -8,10 +8,10 @@ use Aviat\Kilo\Enum\RawKeyCode;
/** /**
* @property-read int $size * @property-read int $size
* @property-read int $rsize * @property-read int $rsize
* @property string $chars * @property-read string $chars
*/ */
class Row { class Row {
use Traits\MagicProperties; // use Traits\MagicProperties;
/** /**
* The version of the row to be displayed (where tabs are converted to display spaces) * The version of the row to be displayed (where tabs are converted to display spaces)
@ -28,8 +28,6 @@ class Row {
*/ */
private bool $hlOpenComment = FALSE; private bool $hlOpenComment = FALSE;
private const T_RAW = -1;
/** /**
* Create a row in the current document * Create a row in the current document
* *
@ -89,15 +87,6 @@ class Row {
}; };
} }
public function __set(string $name, mixed $value): void
{
if ($name === 'chars')
{
$this->chars = $value;
$this->highlight();
}
}
/** /**
* Convert the row contents to a string for saving * Convert the row contents to a string for saving
* *
@ -152,8 +141,6 @@ class Row {
// Safely insert into arbitrary position in the existing string // Safely insert into arbitrary position in the existing string
$this->chars = substr($this->chars, 0, $at) . $c . substr($this->chars, $at); $this->chars = substr($this->chars, 0, $at) . $c . substr($this->chars, $at);
$this->update(); $this->update();
$this->parent->dirty = true;
} }
/** /**
@ -165,8 +152,6 @@ class Row {
{ {
$this->chars .= $s; $this->chars .= $s;
$this->update(); $this->update();
$this->parent->dirty = true;
} }
/** /**
@ -183,8 +168,12 @@ class Row {
$this->chars = substr_replace($this->chars, '', $at, 1); $this->chars = substr_replace($this->chars, '', $at, 1);
$this->update(); $this->update();
}
$this->parent->dirty = true; public function setChars(string $chars): void
{
$this->chars = $chars;
$this->update();
} }
/** /**
@ -229,7 +218,7 @@ class Row {
while ($i < $this->rsize) while ($i < $this->rsize)
{ {
// Multi-line comments // Multi-line comments
if ($mcsLen > 0 && $mceLen > 0 && $inString === '') if ($syntax->mlComments() && $inString === '')
{ {
if ($inComment) if ($inComment)
{ {
@ -257,15 +246,14 @@ class Row {
if ( if (
$this->highlightComment($i, $syntax) $this->highlightComment($i, $syntax)
|| $this->highlightMultilineComments($i, $syntax)
|| $this->highlightPrimaryKeywords($i, $syntax) || $this->highlightPrimaryKeywords($i, $syntax)
|| $this->highlightSecondaryKeywords($i, $syntax) || $this->highlightSecondaryKeywords($i, $syntax)
|| $this->highlightOperators($i, $syntax)
|| $this->highlightCommonOperators($i)
|| $this->highlightCommonDelimeters($i)
|| $this->highlightCharacter($i, $syntax) || $this->highlightCharacter($i, $syntax)
|| $this->highlightString($i, $syntax) || $this->highlightString($i, $syntax)
|| $this->highlightNumber($i, $syntax) || $this->highlightNumber($i, $syntax)
|| $this->highlightOperators($i, $syntax)
|| $this->highlightCommonOperators($i)
|| $this->highlightCommonDelimeters($i)
) { ) {
$i++; $i++;
continue; continue;
@ -401,6 +389,11 @@ class Row {
protected function highlightCharacter(int &$i, Syntax $opts): bool protected function highlightCharacter(int &$i, Syntax $opts): bool
{ {
if (($i + 1) >= $this->rsize)
{
return false;
}
$char = $this->render[$i]; $char = $this->render[$i];
$nextChar = $this->render[$i + 1]; $nextChar = $this->render[$i + 1];
@ -447,35 +440,6 @@ class Row {
return false; return false;
} }
protected function highlightMultilineComments(int &$i, Syntax $opts): bool
{
if ( ! $opts->mlComments())
{
return false;
}
$mcs = $opts->multiLineCommentStart;
$mce = $opts->multiLineCommentEnd;
$mcsLen = strlen($mcs);
$mceLen = strlen($mce);
if ($i + $mcsLen < $this->rsize && \str_contains($this->render, $mcs))
{
$endix = strpos($this->render, $mcs);
$closingIndex = ($endix !== false)
? $i + $endix + $mcsLen + $mceLen
: $this->rsize;
array_replace_range($this->hl, $i, $closingIndex, Highlight::ML_COMMENT);
$i += $closingIndex;
return true;
}
return false;
}
protected function highlightString(int &$i, Syntax $opts): bool protected function highlightString(int &$i, Syntax $opts): bool
{ {
$char = $this->render[$i]; $char = $this->render[$i];
@ -625,17 +589,12 @@ class Row {
$highlight = match(true) { $highlight = match(true) {
// Matches a predefined PHP token // Matches a predefined PHP token
$token['type'] !== self::T_RAW && $tokenHighlight !== Highlight::NORMAL $token['type'] !== T_RAW && $tokenHighlight !== Highlight::NORMAL
=> $tokenHighlight, => $tokenHighlight,
// Matches a specific syntax character // Matches a specific syntax character
$charHighlight !== Highlight::NORMAL => $charHighlight, $charHighlight !== Highlight::NORMAL => $charHighlight,
// Types/identifiers/keywords that don't have their own token, but are
// defined as keywords
in_array($token['char'], $this->parent->fileType->syntax->keywords2, TRUE)
=> Highlight::KEYWORD2,
default => Highlight::NORMAL, default => Highlight::NORMAL,
}; };

View File

@ -6,6 +6,7 @@ use PhpToken;
use function Aviat\Kilo\str_contains; use function Aviat\Kilo\str_contains;
use function Aviat\Kilo\tabs_to_spaces; use function Aviat\Kilo\tabs_to_spaces;
use const Aviat\Kilo\T_RAW;
class PHP8 extends PhpToken { class PHP8 extends PhpToken {
private array $rawLines = []; private array $rawLines = [];
@ -119,7 +120,7 @@ class PHP8 extends PhpToken {
// Simple characters, usually delimiters or single character operators // Simple characters, usually delimiters or single character operators
$this->tokens[$lineNumber][] = [ $this->tokens[$lineNumber][] = [
'type' => -1, 'type' => T_RAW,
'typeName' => 'RAW', 'typeName' => 'RAW',
'char' => tabs_to_spaces($token), 'char' => tabs_to_spaces($token),
'line' => $lineNumber, 'line' => $lineNumber,

View File

@ -10,3 +10,4 @@ const KILO_TAB_STOP = 4;
const KILO_QUIT_TIMES = 3; const KILO_QUIT_TIMES = 3;
const NO_MATCH = -1; const NO_MATCH = -1;
const T_RAW = -1;

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits; namespace Aviat\Kilo\Tests;
use Aviat\Kilo\ANSI; use Aviat\Kilo\ANSI;
use Aviat\Kilo\Enum\Color; use Aviat\Kilo\Enum\Color;

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits; namespace Aviat\Kilo\Tests;
use Aviat\Kilo\Editor; use Aviat\Kilo\Editor;
use Aviat\Kilo\Type\TerminalSize; use Aviat\Kilo\Type\TerminalSize;
@ -47,8 +47,6 @@ class EditorTest extends TestCase {
public function testOpen(): void public function testOpen(): void
{ {
$this->markTestSkipped();
$editor = MockEditor::mock('src/ffi.h'); $editor = MockEditor::mock('src/ffi.h');
$state = json_encode($editor->__debugInfo(), JSON_THROW_ON_ERROR); $state = json_encode($editor->__debugInfo(), JSON_THROW_ON_ERROR);

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits; namespace Aviat\Kilo\Tests;
use Aviat\Kilo\ use Aviat\Kilo\
{ {
@ -17,7 +17,9 @@ class RowTest extends TestCase {
parent::setUp(); parent::setUp();
$this->document = Document::new(); $this->document = Document::new();
$this->row = Row::new($this->document, '', 0); $this->document->insertRow(0, '');
$this->row = $this->document->rows[0];
} }
public function testSanity(): void public function testSanity(): void
@ -31,17 +33,14 @@ class RowTest extends TestCase {
public function testSetRunsUpdate(): void public function testSetRunsUpdate(): void
{ {
$this->markTestSkipped('Hangs'); $this->row->setChars('abcde');
$this->assertNotEmpty($this->row->chars);
$this->row->chars = 'abcde';
$this->assertEquals('abcde', $this->row->render); $this->assertEquals('abcde', $this->row->render);
} }
public function test__toString(): void public function test__toString(): void
{ {
$this->markTestSkipped('Hangs'); $this->row->setChars('abcde');
$this->row->chars = 'abcde';
$this->assertEquals("abcde\n", (string)$this->row); $this->assertEquals("abcde\n", (string)$this->row);
} }
@ -62,9 +61,7 @@ class RowTest extends TestCase {
public function testInsert(): void public function testInsert(): void
{ {
$this->markTestSkipped('Hangs'); $this->row->setChars('abde');
$this->row->chars = 'abde';
$this->row->insert(2, 'c'); $this->row->insert(2, 'c');
$this->assertEquals('abcde', $this->row->chars); $this->assertEquals('abcde', $this->row->chars);
@ -74,9 +71,7 @@ class RowTest extends TestCase {
public function testInsertBadOffset(): void public function testInsertBadOffset(): void
{ {
$this->markTestSkipped('Hangs'); $this->row->setChars('ab');
$this->row->chars = 'ab';
$this->row->insert(5, 'c'); $this->row->insert(5, 'c');
$this->assertEquals('abc', $this->row->chars); $this->assertEquals('abc', $this->row->chars);
@ -86,9 +81,7 @@ class RowTest extends TestCase {
public function testDelete(): void public function testDelete(): void
{ {
$this->markTestSkipped('Hangs'); $this->row->setChars('abcdef');
$this->row->chars = 'abcdef';
$this->row->delete(5); $this->row->delete(5);
$this->assertEquals('abcde', $this->row->chars); $this->assertEquals('abcde', $this->row->chars);
@ -98,12 +91,9 @@ class RowTest extends TestCase {
public function testDeleteBadOffset(): void public function testDeleteBadOffset(): void
{ {
$this->markTestSkipped('Hangs'); $this->row->setChars('ab');
$this->row->chars = 'ab';
$this->row->delete(5); $this->row->delete(5);
$this->assertEquals('ab', $this->row->chars); $this->assertEquals('ab', $this->row->chars);
$this->assertEquals(false, $this->document->dirty);
} }
} }

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Traits; namespace Aviat\Kilo\Tests;
use Aviat\Kilo\{Termios, TermiosException}; use Aviat\Kilo\{Termios, TermiosException};
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;

View File

@ -10,7 +10,13 @@
"tokens": [], "tokens": [],
"filetype": "C", "filetype": "C",
"keywords1": [ "keywords1": [
"auto",
"break",
"case",
"const",
"continue", "continue",
"default",
"do",
"typedef", "typedef",
"switch", "switch",
"return", "return",
@ -18,13 +24,23 @@
"while", "while",
"break", "break",
"struct", "struct",
"extern",
"union", "union",
"class", "class",
"else", "else",
"enum", "enum",
"for", "for",
"case", "case",
"if" "if",
"inline",
"register",
"restrict",
"return",
"sizeof",
"switch",
"typedef",
"union",
"volatile"
], ],
"keywords2": [ "keywords2": [
"#include", "#include",
@ -38,16 +54,50 @@
"float", "float",
"#error", "#error",
"#undef", "#undef",
"#elif",
"long", "long",
"char", "char",
"int", "int",
"void", "void",
"#if" "#if",
"uint32_t",
"wchar_t",
"int32_t",
"int64_t",
"uint64_t",
"int16_t",
"uint16_t",
"uint8_t",
"int8_t"
],
"operators": [
"<=>",
"<<=",
">>=",
"++",
"--",
"==",
"!=",
">=",
"<=",
"&&",
"||",
"<<",
">>",
"+=",
"-=",
"*=",
"\/=",
"%=",
"&=",
"|=",
"^=",
"->",
"::"
], ],
"singleLineCommentStart": "\/\/", "singleLineCommentStart": "\/\/",
"multiLineCommentStart": "\/*", "multiLineCommentStart": "\/*",
"multiLineCommentEnd": "*\/", "multiLineCommentEnd": "*\/"
"flags": 3
} }
}, },
"tokens": [], "tokens": [],
@ -570,11 +620,11 @@
4, 4,
4, 4,
4, 4,
7,
0, 0,
0, 0,
0, 0,
0, 7,
0,
0, 0,
5, 5,
5, 5,
@ -623,11 +673,11 @@
0, 0,
0, 0,
0, 0,
7,
0, 0,
0, 13,
5, 13,
5, 13,
5,
0 0
], ],
"idx": 17 "idx": 17
@ -933,7 +983,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 25 "idx": 25
}, },
@ -1011,7 +1061,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 28 "idx": 28
}, },
@ -1089,7 +1139,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 31 "idx": 31
}, },
@ -1161,7 +1211,7 @@
{ {
"render": "{", "render": "{",
"hl": [ "hl": [
0 9
], ],
"idx": 35 "idx": 35
}, },
@ -1213,7 +1263,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 37 "idx": 37
}, },
@ -1271,7 +1321,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 40 "idx": 40
}, },
@ -1330,7 +1380,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 43 "idx": 43
}, },
@ -1387,7 +1437,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 46 "idx": 46
}, },
@ -1444,10 +1494,10 @@
0, 0,
0, 0,
0, 0,
9,
0, 0,
6,
6,
0, 0,
9,
0 0
], ],
"idx": 49 "idx": 49
@ -1521,6 +1571,7 @@
0, 0,
0, 0,
0, 0,
7,
0, 0,
0, 0,
0, 0,
@ -1530,15 +1581,14 @@
0, 0,
0, 0,
0, 0,
0, 7
0
], ],
"idx": 52 "idx": 52
}, },
{ {
"render": "};", "render": "};",
"hl": [ "hl": [
0, 9,
0 0
], ],
"idx": 53 "idx": 53
@ -1565,15 +1615,15 @@
0, 0,
0, 0,
0, 0,
0, 9,
4,
4,
4,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0,
7,
0,
3, 3,
3, 3,
3, 3,
@ -1589,6 +1639,7 @@
0, 0,
0, 0,
0, 0,
7,
0, 0,
0, 0,
0, 0,
@ -1598,8 +1649,7 @@
0, 0,
0, 0,
0, 0,
0, 9,
0,
0 0
], ],
"idx": 55 "idx": 55
@ -1621,6 +1671,14 @@
0, 0,
0, 0,
0, 0,
9,
0,
0,
0,
0,
0,
0,
7,
0, 0,
4, 4,
4, 4,
@ -1630,20 +1688,6 @@
0, 0,
0, 0,
0, 0,
4,
4,
4,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0, 0,
0, 0,
0, 0,
@ -1656,7 +1700,13 @@
0, 0,
0, 0,
0, 0,
7,
0, 0,
3,
3,
3,
3,
3,
0, 0,
3, 3,
3, 3,
@ -1673,6 +1723,7 @@
0, 0,
0, 0,
0, 0,
7,
0, 0,
0, 0,
0, 0,
@ -1682,8 +1733,7 @@
0, 0,
0, 0,
0, 0,
0, 9,
0,
0 0
], ],
"idx": 56 "idx": 56
@ -1906,7 +1956,7 @@
0, 0,
0, 0,
0, 0,
0 9
], ],
"idx": 61 "idx": 61
}, },
@ -1938,7 +1988,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 62 "idx": 62
}, },
@ -1970,7 +2020,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 63 "idx": 63
}, },
@ -2005,7 +2055,7 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 64 "idx": 64
}, },
@ -2040,14 +2090,14 @@
0, 0,
0, 0,
0, 0,
0 7
], ],
"idx": 65 "idx": 65
}, },
{ {
"render": "};", "render": "};",
"hl": [ "hl": [
0, 9,
0 0
], ],
"idx": 66 "idx": 66
@ -2065,21 +2115,21 @@
0, 0,
0, 0,
0, 0,
9,
0,
0,
0,
7,
0, 0,
4, 4,
4, 4,
4, 4,
0, 7,
0,
4,
4,
4,
0,
0,
0, 0,
0, 0,
0, 0,
0, 0,
9,
0 0
], ],
"idx": 67 "idx": 67