Fix more tests
timw4mail/php-kilo/pipeline/head This commit looks good Details

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>
<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
@ -228,6 +231,8 @@ class Document {
// 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

View File

@ -8,7 +8,7 @@ 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;
@ -28,8 +28,6 @@ class Row {
*/
private bool $hlOpenComment = FALSE;
private const T_RAW = -1;
/**
* Create a row in the current document
*
@ -143,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;
}
/**
@ -156,8 +152,6 @@ class Row {
{
$this->chars .= $s;
$this->update();
$this->parent->dirty = true;
}
/**
@ -174,8 +168,6 @@ class Row {
$this->chars = substr_replace($this->chars, '', $at, 1);
$this->update();
$this->parent->dirty = true;
}
public function setChars(string $chars): void
@ -226,7 +218,7 @@ class Row {
while ($i < $this->rsize)
{
// Multi-line comments
if ($mcsLen > 0 && $mceLen > 0 && $inString === '')
if ($syntax->mlComments() && $inString === '')
{
if ($inComment)
{
@ -254,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;
@ -398,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];
@ -444,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];
@ -622,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

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

View File

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