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>
<testsuites>
<testsuite name="PHPKilo">
<directory phpVersion="7.4.0" phpVersionOperator="&gt;=">tests</directory>
<directory phpVersion="8.0.0" phpVersionOperator="&gt;=">tests</directory>
</testsuite>
</testsuites>
<logging/>

View File

@ -105,12 +105,12 @@ class Document {
if ($c === KeyType::ENTER || $c === RawKeyCode::CARRIAGE_RETURN)
{
$this->insertNewline($at);
$this->dirty = true;
return;
}
$this->dirty = true;
$this->rows[$at->y]->insert($at->x, $c);
$this->dirty = true;
}
public function delete(Point $at): void
@ -120,7 +120,6 @@ class Document {
return;
}
$this->dirty = true;
$row =& $this->rows[$at->y];
if ($at->x === $this->rows[$at->y]->size && $at->y + 1 < $this->numRows)
@ -132,6 +131,8 @@ class Document {
{
$row->delete($at->x);
}
$this->dirty = true;
}
public function insertRow(int $at, string $s, bool $updateSyntax = TRUE): void
@ -171,6 +172,8 @@ class Document {
{
$this->refreshPHPSyntax();
}
$this->dirty = true;
}
protected function deleteRow(int $at): void
@ -223,11 +226,13 @@ class Document {
$newChars = substr($chars, 0, $at->x);
// 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
$this->insertRow($at->y + 1, substr($chars, $at->x));
}
$this->dirty = true;
}
protected function selectSyntaxHighlight(): void
@ -255,7 +260,7 @@ class Document {
public function refreshSyntax(): void
{
// 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

View File

@ -8,10 +8,10 @@ use Aviat\Kilo\Enum\RawKeyCode;
/**
* @property-read int $size
* @property-read int $rsize
* @property string $chars
* @property-read string $chars
*/
class Row {
use Traits\MagicProperties;
// use Traits\MagicProperties;
/**
* 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 const T_RAW = -1;
/**
* 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
*
@ -152,8 +141,6 @@ class Row {
// Safely insert into arbitrary position in the existing string
$this->chars = substr($this->chars, 0, $at) . $c . substr($this->chars, $at);
$this->update();
$this->parent->dirty = true;
}
/**
@ -165,8 +152,6 @@ class Row {
{
$this->chars .= $s;
$this->update();
$this->parent->dirty = true;
}
/**
@ -183,8 +168,12 @@ class Row {
$this->chars = substr_replace($this->chars, '', $at, 1);
$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)
{
// Multi-line comments
if ($mcsLen > 0 && $mceLen > 0 && $inString === '')
if ($syntax->mlComments() && $inString === '')
{
if ($inComment)
{
@ -257,15 +246,14 @@ class Row {
if (
$this->highlightComment($i, $syntax)
|| $this->highlightMultilineComments($i, $syntax)
|| $this->highlightPrimaryKeywords($i, $syntax)
|| $this->highlightSecondaryKeywords($i, $syntax)
|| $this->highlightOperators($i, $syntax)
|| $this->highlightCommonOperators($i)
|| $this->highlightCommonDelimeters($i)
|| $this->highlightCharacter($i, $syntax)
|| $this->highlightString($i, $syntax)
|| $this->highlightNumber($i, $syntax)
|| $this->highlightOperators($i, $syntax)
|| $this->highlightCommonOperators($i)
|| $this->highlightCommonDelimeters($i)
) {
$i++;
continue;
@ -401,6 +389,11 @@ class Row {
protected function highlightCharacter(int &$i, Syntax $opts): bool
{
if (($i + 1) >= $this->rsize)
{
return false;
}
$char = $this->render[$i];
$nextChar = $this->render[$i + 1];
@ -447,35 +440,6 @@ class Row {
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
{
$char = $this->render[$i];
@ -625,17 +589,12 @@ class Row {
$highlight = match(true) {
// Matches a predefined PHP token
$token['type'] !== self::T_RAW && $tokenHighlight !== Highlight::NORMAL
$token['type'] !== T_RAW && $tokenHighlight !== Highlight::NORMAL
=> $tokenHighlight,
// Matches a specific syntax character
$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,
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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