More test coverage, and snapshots

This commit is contained in:
Timothy Warren 2019-11-20 15:03:48 -05:00
parent eb116a5072
commit 5c73b3db2b
8 changed files with 4657 additions and 30 deletions

View File

@ -14,11 +14,13 @@
} }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^8" "phpunit/phpunit": "^8",
"spatie/phpunit-snapshot-assertions": "^2.2.0"
}, },
"scripts": { "scripts": {
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c phpunit.xml tests", "coverage": "phpdbg -qrr -- vendor/bin/phpunit -c phpunit.xml tests",
"test": "vendor/bin/phpunit -c phpunit.xml tests" "test": "vendor/bin/phpunit -c phpunit.xml --no-coverage tests",
"test-update": "vendor/bin/phpunit -c phpunit.xml --no-coverage -d --update-snapshots tests"
}, },
"require": { "require": {
"ext-ffi": "*" "ext-ffi": "*"

145
composer.lock generated
View File

@ -4,21 +4,21 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "7ac69bab358a14faafdf4864a1b16e05", "content-hash": "f11505a6676b236651e7784cfcd62ec8",
"packages": [], "packages": [],
"packages-dev": [ "packages-dev": [
{ {
"name": "doctrine/instantiator", "name": "doctrine/instantiator",
"version": "1.2.0", "version": "1.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/doctrine/instantiator.git", "url": "https://github.com/doctrine/instantiator.git",
"reference": "a2c590166b2133a4633738648b6b064edae0814a" "reference": "ae466f726242e637cebdd526a7d991b9433bacf1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1",
"reference": "a2c590166b2133a4633738648b6b064edae0814a", "reference": "ae466f726242e637cebdd526a7d991b9433bacf1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -61,7 +61,7 @@
"constructor", "constructor",
"instantiate" "instantiate"
], ],
"time": "2019-03-17T17:37:11+00:00" "time": "2019-10-21T16:45:58+00:00"
}, },
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
@ -428,16 +428,16 @@
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "7.0.8", "version": "7.0.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f" "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f1884187926fbb755a9aaf0b3836ad3165b478bf",
"reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f", "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -487,7 +487,7 @@
"testing", "testing",
"xunit" "xunit"
], ],
"time": "2019-09-17T06:24:36+00:00" "time": "2019-11-20T13:55:58+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
@ -928,16 +928,16 @@
}, },
{ {
"name": "sebastian/environment", "name": "sebastian/environment",
"version": "4.2.2", "version": "4.2.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/environment.git", "url": "https://github.com/sebastianbergmann/environment.git",
"reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404" "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/f2a2c8e1c97c11ace607a7a667d73d47c19fe404", "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368",
"reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404", "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -977,7 +977,7 @@
"environment", "environment",
"hhvm" "hhvm"
], ],
"time": "2019-05-05T09:05:15+00:00" "time": "2019-11-20T08:46:58+00:00"
}, },
{ {
"name": "sebastian/exporter", "name": "sebastian/exporter",
@ -1376,6 +1376,56 @@
"homepage": "https://github.com/sebastianbergmann/version", "homepage": "https://github.com/sebastianbergmann/version",
"time": "2016-10-03T07:35:21+00:00" "time": "2016-10-03T07:35:21+00:00"
}, },
{
"name": "spatie/phpunit-snapshot-assertions",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/spatie/phpunit-snapshot-assertions.git",
"reference": "7da647e383d5ba960b384a45e8bd59c4211b366d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/spatie/phpunit-snapshot-assertions/zipball/7da647e383d5ba960b384a45e8bd59c4211b366d",
"reference": "7da647e383d5ba960b384a45e8bd59c4211b366d",
"shasum": ""
},
"require": {
"ext-dom": "*",
"php": "^7.2",
"phpunit/phpunit": "^8.0",
"symfony/yaml": "^4.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Spatie\\Snapshots\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Sebastian De Deyne",
"email": "sebastian@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"description": "Snapshot testing with PHPUnit",
"homepage": "https://github.com/spatie/phpunit-snapshot-assertions",
"keywords": [
"assert",
"phpunit",
"phpunit-snapshot-assertions",
"snapshot",
"spatie",
"testing"
],
"time": "2019-10-23T15:00:34+00:00"
},
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.12.0", "version": "v1.12.0",
@ -1434,6 +1484,65 @@
], ],
"time": "2019-08-06T08:03:45+00:00" "time": "2019-08-06T08:03:45+00:00"
}, },
{
"name": "symfony/yaml",
"version": "v4.3.8",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "324cf4b19c345465fad14f3602050519e09e361d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/324cf4b19c345465fad14f3602050519e09e361d",
"reference": "324cf4b19c345465fad14f3602050519e09e361d",
"shasum": ""
},
"require": {
"php": "^7.1.3",
"symfony/polyfill-ctype": "~1.8"
},
"conflict": {
"symfony/console": "<3.4"
},
"require-dev": {
"symfony/console": "~3.4|~4.0"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.3-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Yaml\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2019-10-30T12:58:49+00:00"
},
{ {
"name": "theseer/tokenizer", "name": "theseer/tokenizer",
"version": "1.1.3", "version": "1.1.3",
@ -1530,6 +1639,8 @@
"stability-flags": [], "stability-flags": [],
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": {
"ext-ffi": "*"
},
"platform-dev": [] "platform-dev": []
} }

View File

@ -65,6 +65,25 @@ class Editor {
return NULL; return NULL;
} }
public function __debugInfo(): array
{
return [
'colOffset' => $this->colOffset,
'cursorX' => $this->cursorX,
'cursorY' => $this->cursorY,
'dirty' => $this->dirty,
'filename' => $this->filename,
'renderX' => $this->renderX,
'rowOffset' => $this->rowOffset,
'rows' => $this->rows,
'screenCols' => $this->screenCols,
'screenRows' => $this->screenRows,
'statusMsg' => $this->statusMsg,
'syntax' => $this->syntax,
'tokens' => $this->tokens,
];
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// ! Terminal // ! Terminal
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -139,7 +158,9 @@ class Editor {
// Update the syntax highlighting for all the rows of the file // Update the syntax highlighting for all the rows of the file
for ($i = 0; $i < $this->numRows; $i++) for ($i = 0; $i < $this->numRows; $i++)
{ {
// @codeCoverageIgnoreStart
$this->rows[$i]->updateSyntax(); $this->rows[$i]->updateSyntax();
// @codeCoverageIgnoreEnd
} }
return; return;

View File

@ -196,17 +196,13 @@ class Row {
{ {
switch ($name) switch ($name)
{ {
case 'size': case 'size': return strlen($this->chars);
return strlen($this->chars);
case 'rsize': case 'rsize': return strlen($this->render);
return strlen($this->render);
case 'chars': case 'chars': return $this->chars;
return $this->chars;
default: default: return NULL;
return NULL;
} }
} }
@ -224,7 +220,7 @@ class Row {
return $this->chars . "\n"; return $this->chars . "\n";
} }
public function __debugInfo() public function __debugInfo(): array
{ {
return [ return [
'size' => $this->size, 'size' => $this->size,
@ -240,7 +236,8 @@ class Row {
{ {
if ($at < 0 || $at > $this->size) if ($at < 0 || $at > $this->size)
{ {
$at = $this->size; $this->appendString($c);
return;
} }
// Safely insert into arbitrary position in the existing string // Safely insert into arbitrary position in the existing string
@ -286,7 +283,7 @@ class Row {
{ {
$this->hl = array_fill(0, $this->rsize, Highlight::NORMAL); $this->hl = array_fill(0, $this->rsize, Highlight::NORMAL);
if ( ! isset($this->parent->syntax)) if ($this->parent->syntax === NULL)
{ {
return; return;
} }

View File

@ -4,8 +4,11 @@ namespace Aviat\Kilo\Tests\Traits;
use Aviat\Kilo\Editor; use Aviat\Kilo\Editor;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Spatie\Snapshots\MatchesSnapshots;
class EditorTest extends TestCase { class EditorTest extends TestCase {
use MatchesSnapshots;
protected Editor $editor; protected Editor $editor;
public function setUp(): void public function setUp(): void
@ -20,4 +23,18 @@ class EditorTest extends TestCase {
$this->assertEquals(0, $this->editor->numRows); $this->assertEquals(0, $this->editor->numRows);
$this->assertNull($this->editor->syntax); $this->assertNull($this->editor->syntax);
} }
public function test__debugInfo(): void
{
$state = json_encode($this->editor->__debugInfo());
$this->assertMatchesJsonSnapshot($state);
}
public function testOpen(): void
{
$this->editor->open('test.php');
$state = json_encode($this->editor);
$this->assertMatchesJsonSnapshot($state);
}
} }

View File

@ -21,7 +21,74 @@ class RowTest extends TestCase {
{ {
$this->assertEquals(0, $this->row->size); $this->assertEquals(0, $this->row->size);
$this->assertEquals(0, $this->row->rsize); $this->assertEquals(0, $this->row->rsize);
$this->assertNull($this->row->foo);
$this->assertEmpty($this->row->chars); $this->assertEmpty($this->row->chars);
$this->assertEmpty($this->row->render); $this->assertEmpty($this->row->render);
} }
public function testSetRunsUpdate(): void
{
$this->row->chars = 'abcde';
$this->assertEquals('abcde', $this->row->render);
}
public function test__toString(): void
{
$this->row->chars = 'abcde';
$this->assertEquals("abcde\n", (string)$this->row);
}
public function test__debugInfo(): void
{
$actual = $this->row->__debugInfo();
$expected = [
'size' => 0,
'rsize' => 0,
'chars' => '',
'render' => '',
'hl' => [],
'hlOpenComment' => FALSE,
];
$this->assertEquals($expected, $actual);
}
public function testInsertChar(): void
{
$this->row->chars = 'abde';
$this->row->insertChar(2, 'c');
$this->assertEquals('abcde', $this->row->chars);
$this->assertEquals('abcde', $this->row->render);
$this->assertEquals(1, $this->editor->dirty);
}
public function testInsertCharBadOffset(): void
{
$this->row->chars = 'ab';
$this->row->insertChar(5, 'c');
$this->assertEquals('abc', $this->row->chars);
$this->assertEquals('abc', $this->row->render);
$this->assertEquals(1, $this->editor->dirty);
}
public function testDeleteChar(): void
{
$this->row->chars = 'abcdef';
$this->row->deleteChar(5);
$this->assertEquals('abcde', $this->row->chars);
$this->assertEquals('abcde', $this->row->render);
$this->assertEquals(1, $this->editor->dirty);
}
public function testDeleteCharBadOffset(): void
{
$this->row->chars = 'ab';
$this->row->deleteChar(5);
$this->assertEquals('ab', $this->row->chars);
$this->assertEquals(0, $this->editor->dirty);
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,15 @@
{
"colOffset": 0,
"cursorX": 0,
"cursorY": 0,
"dirty": 0,
"filename": "",
"renderX": 0,
"rowOffset": 0,
"rows": [],
"screenCols": 80,
"screenRows": 23,
"statusMsg": "",
"syntax": null,
"tokens": []
}