Fix more tests
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-04-14 14:40:35 -04:00
parent 8f5986e91e
commit a50c22c0e0
7 changed files with 56 additions and 199 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
@ -228,6 +231,8 @@ class Document {
// 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

View File

@ -8,7 +8,7 @@ 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;
@ -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
* *
@ -143,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;
} }
/** /**
@ -156,8 +152,6 @@ class Row {
{ {
$this->chars .= $s; $this->chars .= $s;
$this->update(); $this->update();
$this->parent->dirty = true;
} }
/** /**
@ -174,8 +168,6 @@ 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 public function setChars(string $chars): void
@ -226,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)
{ {
@ -254,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;
@ -398,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];
@ -444,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];
@ -622,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

@ -33,16 +33,13 @@ class RowTest extends TestCase {
public function testSetRunsUpdate(): void public function testSetRunsUpdate(): void
{ {
// $this->markTestSkipped('Hangs');
$this->row->setChars('abcde'); $this->row->setChars('abcde');
// $this->assertNotEmpty($this->row->chars); $this->assertNotEmpty($this->row->chars);
// $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->setChars('abcde');
$this->assertEquals("abcde\n", (string)$this->row); $this->assertEquals("abcde\n", (string)$this->row);
} }
@ -64,8 +61,6 @@ class RowTest extends TestCase {
public function testInsert(): void public function testInsert(): void
{ {
$this->markTestSkipped('Hangs');
$this->row->setChars('abde'); $this->row->setChars('abde');
$this->row->insert(2, 'c'); $this->row->insert(2, 'c');
@ -76,8 +71,6 @@ class RowTest extends TestCase {
public function testInsertBadOffset(): void public function testInsertBadOffset(): void
{ {
$this->markTestSkipped('Hangs');
$this->row->setChars('ab'); $this->row->setChars('ab');
$this->row->insert(5, 'c'); $this->row->insert(5, 'c');
@ -88,8 +81,6 @@ class RowTest extends TestCase {
public function testDelete(): void public function testDelete(): void
{ {
$this->markTestSkipped('Hangs');
$this->row->setChars('abcdef'); $this->row->setChars('abcdef');
$this->row->delete(5); $this->row->delete(5);
@ -100,12 +91,9 @@ class RowTest extends TestCase {
public function testDeleteBadOffset(): void public function testDeleteBadOffset(): void
{ {
$this->markTestSkipped('Hangs');
$this->row->setChars('ab'); $this->row->setChars('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

@ -654,7 +654,7 @@
5, 5,
5, 5,
5, 5,
7 0
], ],
"idx": 16 "idx": 16
}, },
@ -678,7 +678,7 @@
13, 13,
13, 13,
13, 13,
7 0
], ],
"idx": 17 "idx": 17
}, },
@ -1218,29 +1218,8 @@
{ {
"render": " \/* Input modes. *\/", "render": " \/* Input modes. *\/",
"hl": [ "hl": [
2, 0,
2, 0,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2, 2,
2, 2,
2, 2,
@ -1296,28 +1275,8 @@
{ {
"render": " \/* Output modes. *\/", "render": " \/* Output modes. *\/",
"hl": [ "hl": [
2, 0,
2, 0,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2, 2,
2, 2,
2, 2,
@ -1374,27 +1333,8 @@
{ {
"render": " \/* Control modes. *\/", "render": " \/* Control modes. *\/",
"hl": [ "hl": [
2, 0,
2, 0,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2, 2,
2, 2,
2, 2,
@ -1452,29 +1392,8 @@
{ {
"render": " \/* Local modes. *\/", "render": " \/* Local modes. *\/",
"hl": [ "hl": [
2, 0,
2, 0,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2, 2,
2, 2,
2, 2,
@ -1530,22 +1449,8 @@
{ {
"render": " \/* Control characters. *\/", "render": " \/* Control characters. *\/",
"hl": [ "hl": [
2, 0,
2, 0,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2,
2, 2,
2, 2,
2, 2,
@ -1590,10 +1495,10 @@
0, 0,
0, 0,
9, 9,
6, 0,
6, 0,
9, 9,
7 0
], ],
"idx": 49 "idx": 49
}, },
@ -1605,13 +1510,8 @@
{ {
"render": " \/* Input and output baud rates. *\/", "render": " \/* Input and output baud rates. *\/",
"hl": [ "hl": [
2, 0,
2, 0,
2,
2,
2,
2,
2,
2, 2,
2, 2,
2, 2,
@ -1689,7 +1589,7 @@
"render": "};", "render": "};",
"hl": [ "hl": [
9, 9,
7 0
], ],
"idx": 53 "idx": 53
}, },
@ -1716,9 +1616,9 @@
0, 0,
0, 0,
9, 9,
4, 0,
4, 0,
4, 0,
0, 0,
0, 0,
0, 0,
@ -1750,7 +1650,7 @@
0, 0,
0, 0,
9, 9,
7 0
], ],
"idx": 55 "idx": 55
}, },
@ -1772,9 +1672,9 @@
0, 0,
0, 0,
9, 9,
4, 0,
4, 0,
4, 0,
0, 0,
0, 0,
0, 0,
@ -1834,7 +1734,7 @@
0, 0,
0, 0,
9, 9,
7 0
], ],
"idx": 56 "idx": 56
}, },
@ -2198,7 +2098,7 @@
"render": "};", "render": "};",
"hl": [ "hl": [
9, 9,
7 0
], ],
"idx": 66 "idx": 66
}, },
@ -2216,9 +2116,9 @@
0, 0,
0, 0,
9, 9,
4, 0,
4, 0,
4, 0,
7, 7,
0, 0,
4, 4,
@ -2230,7 +2130,7 @@
0, 0,
0, 0,
9, 9,
7 0
], ],
"idx": 67 "idx": 67
} }