diff --git a/composer.json b/composer.json index 6c6dcc4..32a0165 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,13 @@ } }, "require-dev": { - "phpunit/phpunit": "^8" + "phpunit/phpunit": "^8", + "spatie/phpunit-snapshot-assertions": "^2.2.0" }, "scripts": { "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": { "ext-ffi": "*" diff --git a/composer.lock b/composer.lock index 261ff2f..19f077e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,21 +4,21 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7ac69bab358a14faafdf4864a1b16e05", + "content-hash": "f11505a6676b236651e7784cfcd62ec8", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.2.0", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "a2c590166b2133a4633738648b6b064edae0814a" + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", - "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/ae466f726242e637cebdd526a7d991b9433bacf1", + "reference": "ae466f726242e637cebdd526a7d991b9433bacf1", "shasum": "" }, "require": { @@ -61,7 +61,7 @@ "constructor", "instantiate" ], - "time": "2019-03-17T17:37:11+00:00" + "time": "2019-10-21T16:45:58+00:00" }, { "name": "myclabs/deep-copy", @@ -428,16 +428,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "7.0.8", + "version": "7.0.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f" + "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/aa0d179a13284c7420fc281fc32750e6cc7c9e2f", - "reference": "aa0d179a13284c7420fc281fc32750e6cc7c9e2f", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f1884187926fbb755a9aaf0b3836ad3165b478bf", + "reference": "f1884187926fbb755a9aaf0b3836ad3165b478bf", "shasum": "" }, "require": { @@ -487,7 +487,7 @@ "testing", "xunit" ], - "time": "2019-09-17T06:24:36+00:00" + "time": "2019-11-20T13:55:58+00:00" }, { "name": "phpunit/php-file-iterator", @@ -928,16 +928,16 @@ }, { "name": "sebastian/environment", - "version": "4.2.2", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404" + "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/f2a2c8e1c97c11ace607a7a667d73d47c19fe404", - "reference": "f2a2c8e1c97c11ace607a7a667d73d47c19fe404", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/464c90d7bdf5ad4e8a6aea15c091fec0603d4368", + "reference": "464c90d7bdf5ad4e8a6aea15c091fec0603d4368", "shasum": "" }, "require": { @@ -977,7 +977,7 @@ "environment", "hhvm" ], - "time": "2019-05-05T09:05:15+00:00" + "time": "2019-11-20T08:46:58+00:00" }, { "name": "sebastian/exporter", @@ -1376,6 +1376,56 @@ "homepage": "https://github.com/sebastianbergmann/version", "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", "version": "v1.12.0", @@ -1434,6 +1484,65 @@ ], "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", "version": "1.1.3", @@ -1530,6 +1639,8 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-ffi": "*" + }, "platform-dev": [] } diff --git a/src/Editor.php b/src/Editor.php index bfa78e9..2b81c96 100644 --- a/src/Editor.php +++ b/src/Editor.php @@ -65,6 +65,25 @@ class Editor { 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 // ------------------------------------------------------------------------ @@ -139,7 +158,9 @@ class Editor { // Update the syntax highlighting for all the rows of the file for ($i = 0; $i < $this->numRows; $i++) { + // @codeCoverageIgnoreStart $this->rows[$i]->updateSyntax(); + // @codeCoverageIgnoreEnd } return; diff --git a/src/Row.php b/src/Row.php index 97a6c81..2aae6a5 100644 --- a/src/Row.php +++ b/src/Row.php @@ -196,17 +196,13 @@ class Row { { switch ($name) { - case 'size': - return strlen($this->chars); + case 'size': return strlen($this->chars); - case 'rsize': - return strlen($this->render); + case 'rsize': return strlen($this->render); - case 'chars': - return $this->chars; + case 'chars': return $this->chars; - default: - return NULL; + default: return NULL; } } @@ -224,7 +220,7 @@ class Row { return $this->chars . "\n"; } - public function __debugInfo() + public function __debugInfo(): array { return [ 'size' => $this->size, @@ -240,7 +236,8 @@ class Row { { if ($at < 0 || $at > $this->size) { - $at = $this->size; + $this->appendString($c); + return; } // Safely insert into arbitrary position in the existing string @@ -286,7 +283,7 @@ class Row { { $this->hl = array_fill(0, $this->rsize, Highlight::NORMAL); - if ( ! isset($this->parent->syntax)) + if ($this->parent->syntax === NULL) { return; } diff --git a/tests/EditorTest.php b/tests/EditorTest.php index c182967..ecd79b5 100644 --- a/tests/EditorTest.php +++ b/tests/EditorTest.php @@ -4,8 +4,11 @@ namespace Aviat\Kilo\Tests\Traits; use Aviat\Kilo\Editor; use PHPUnit\Framework\TestCase; +use Spatie\Snapshots\MatchesSnapshots; class EditorTest extends TestCase { + use MatchesSnapshots; + protected Editor $editor; public function setUp(): void @@ -20,4 +23,18 @@ class EditorTest extends TestCase { $this->assertEquals(0, $this->editor->numRows); $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); + } } \ No newline at end of file diff --git a/tests/RowTest.php b/tests/RowTest.php index ca12c25..800996e 100644 --- a/tests/RowTest.php +++ b/tests/RowTest.php @@ -21,7 +21,74 @@ class RowTest extends TestCase { { $this->assertEquals(0, $this->row->size); $this->assertEquals(0, $this->row->rsize); + $this->assertNull($this->row->foo); $this->assertEmpty($this->row->chars); $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); + } } \ No newline at end of file diff --git a/tests/__snapshots__/EditorTest__testOpen__1.json b/tests/__snapshots__/EditorTest__testOpen__1.json new file mode 100644 index 0000000..eaf6dc0 --- /dev/null +++ b/tests/__snapshots__/EditorTest__testOpen__1.json @@ -0,0 +1,4397 @@ +{ + "rows": [ + { + "render": "doNothing();", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 8, + 8, + 8, + 8, + 8, + 7, + 7, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 9, + 9, + 7 + ], + "idx": 31 + }, + { + "render": "", + "hl": [], + "idx": 32 + }, + { + "render": " $c = $a + $b;", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 7 + ], + "idx": 33 + }, + { + "render": " $a = $c - $b;", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 7 + ], + "idx": 34 + }, + { + "render": "", + "hl": [], + "idx": 35 + }, + { + "render": " $c = $a * $b;", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 7 + ], + "idx": 36 + }, + { + "render": " $b = (int) ($c \/ $a);", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 8, + 8, + 0, + 7, + 0, + 4, + 4, + 4, + 4, + 4, + 0, + 9, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 9, + 7 + ], + "idx": 37 + }, + { + "render": "", + "hl": [], + "idx": 38 + }, + { + "render": " return $c;", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 3, + 3, + 3, + 3, + 3, + 3, + 0, + 8, + 8, + 7 + ], + "idx": 39 + }, + { + "render": " }", + "hl": [ + 0, + 0, + 0, + 0, + 9 + ], + "idx": 40 + }, + { + "render": "}", + "hl": [ + 9 + ], + "idx": 41 + }, + { + "render": "", + "hl": [], + "idx": 42 + }, + { + "render": "\/*", + "hl": [ + 2, + 2 + ], + "idx": 43 + }, + { + "render": " * Multi-line comment", + "hl": [ + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2 + ], + "idx": 44 + }, + { + "render": " *\/", + "hl": [ + 2, + 2, + 2 + ], + "idx": 45 + }, + { + "render": "$foobar = new FooBar();", + "hl": [ + 8, + 8, + 8, + 8, + 8, + 8, + 8, + 0, + 7, + 0, + 3, + 3, + 3, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 9, + 9, + 7 + ], + "idx": 46 + }, + { + "render": "", + "hl": [], + "idx": 47 + }, + { + "render": "$baz = ['a' => 'b'];", + "hl": [ + 8, + 8, + 8, + 8, + 0, + 7, + 0, + 9, + 5, + 5, + 5, + 0, + 7, + 7, + 0, + 5, + 5, + 5, + 9, + 7 + ], + "idx": 48 + }, + { + "render": "", + "hl": [], + "idx": 49 + }, + { + "render": "\/\/ C++ style comment", + "hl": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ], + "idx": 50 + }, + { + "render": "$x = 3;", + "hl": [ + 8, + 8, + 0, + 7, + 0, + 6, + 7 + ], + "idx": 51 + }, + { + "render": "", + "hl": [], + "idx": 52 + }, + { + "render": "# Perl-style comment", + "hl": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ], + "idx": 53 + }, + { + "render": "$y = [", + "hl": [ + 8, + 8, + 0, + 7, + 0, + 9 + ], + "idx": 54 + }, + { + "render": " 1,", + "hl": [ + 0, + 0, + 0, + 0, + 6, + 7 + ], + "idx": 55 + }, + { + "render": " 2,", + "hl": [ + 0, + 0, + 0, + 0, + 6, + 7 + ], + "idx": 56 + }, + { + "render": " 3", + "hl": [ + 0, + 0, + 0, + 0, + 6 + ], + "idx": 57 + }, + { + "render": "];", + "hl": [ + 9, + 7 + ], + "idx": 58 + }, + { + "render": "", + "hl": [], + "idx": 59 + }, + { + "render": "\/\/ Multi-line ternary statement", + "hl": [ + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1 + ], + "idx": 60 + }, + { + "render": "$q = ($x !== 2)", + "hl": [ + 8, + 8, + 0, + 7, + 0, + 9, + 8, + 8, + 0, + 7, + 7, + 7, + 0, + 6, + 9 + ], + "idx": 61 + }, + { + "render": " ? 'yes'", + "hl": [ + 0, + 0, + 0, + 0, + 7, + 0, + 5, + 5, + 5, + 5, + 5 + ], + "idx": 62 + }, + { + "render": " : 'no';", + "hl": [ + 0, + 0, + 0, + 0, + 7, + 0, + 5, + 5, + 5, + 5, + 7 + ], + "idx": 63 + }, + { + "render": "", + "hl": [], + "idx": 64 + }, + { + "render": "\/*", + "hl": [ + 2, + 2 + ], + "idx": 65 + }, + { + "render": "Heredoc", + "hl": [ + 2, + 2, + 2, + 2, + 2, + 2, + 2 + ], + "idx": 66 + }, + { + "render": "*\/$z = $x + $y;", + "hl": [ + 2, + 2, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 0, + 7, + 0, + 8, + 8, + 7 + ], + "idx": 67 + }, + { + "render": "$sql = <<{x}<\/foo>", + "hl": [ + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5 + ], + "idx": 74 + }, + { + "render": "TEMPLATE;", + "hl": [ + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 7 + ], + "idx": 75 + }, + { + "render": "", + "hl": [], + "idx": 76 + }, + { + "render": "?>", + "hl": [ + 9, + 9 + ], + "idx": 77 + }, + { + "render": "", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "idx": 78 + }, + { + "render": "", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0 + ], + "idx": 79 + }, + { + "render": "

<\/h1>", + "hl": [ + 0, + 0, + 0, + 0, + 9, + 9, + 9, + 0, + 8, + 8, + 8, + 8, + 8, + 8, + 8, + 8, + 9, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 5, + 9, + 0, + 9, + 9, + 0, + 0, + 0, + 0, + 0 + ], + "idx": 80 + }, + { + "render": "<\/body>", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "idx": 81 + }, + { + "render": "<\/html>", + "hl": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "idx": 82 + }, + { + "render": "", + "hl": [ + 9, + 9, + 9, + 9, + 9, + 9, + 0, + 0, + 0, + 0, + 9, + 9, + 7, + 0, + 9, + 9 + ], + "idx": 83 + } + ], + "dirty": 0, + "filename": "test.php", + "syntax": { + "filetype": "PHP", + "filematch": [ + ".php", + "kilo" + ], + "singleLineCommentStart": "\/\/", + "multiLineCommentStart": "\/*", + "multiLineCommentEnd": "*\/", + "keywords1": [ + "?php", + "$this", + "__halt_compiler", + "abstract", + "and", + "array", + "as", + "break", + "callable", + "case", + "catch", + "class", + "clone", + "const", + "continue", + "declare", + "default", + "die", + "do", + "echo", + "else", + "elseif", + "empty", + "enddeclare", + "endfor", + "endforeach", + "endif", + "endswitch", + "endwhile", + "eval", + "exit", + "extends", + "final", + "finally", + "for", + "foreach", + "function", + "global", + "goto", + "if", + "implements", + "include", + "include_once", + "instanceof", + "insteadof", + "interface", + "isset", + "list", + "namespace", + "new", + "or", + "print", + "private", + "protected", + "public", + "require", + "require_once", + "return", + "static", + "switch", + "throw", + "trait", + "try", + "unset", + "use", + "var", + "while", + "xor", + "yield", + "yield from", + "__CLASS__", + "__DIR__", + "__FILE__", + "__FUNCTION__", + "__LINE__", + "__METHOD__", + "__NAMESPACE__", + "__TRAIT__" + ], + "keywords2": [ + "int", + "float", + "bool", + "string", + "true", + "TRUE", + "false", + "FALSE", + "null", + "NULL", + "void", + "iterable", + "object", + "strict_types" + ], + "tokens": [], + "flags": 3 + }, + "tokens": { + "1": [ + { + "type": 382, + "typeName": "T_OPEN_TAG", + "char": "", + "line": 32 + }, + { + "type": 311, + "typeName": "T_STRING", + "char": "doNothing", + "line": 32 + }, + { + "type": -1, + "typeName": "RAW", + "char": "(" + }, + { + "type": -1, + "typeName": "RAW", + "char": ")" + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n ", + "line": 32 + } + ], + "33": [], + "34": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$c", + "line": 34 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 34 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 34 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$a", + "line": 34 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 34 + }, + { + "type": -1, + "typeName": "RAW", + "char": "+" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 34 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$b", + "line": 34 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 34 + } + ], + "35": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$a", + "line": 35 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 35 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 35 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$c", + "line": 35 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 35 + }, + { + "type": -1, + "typeName": "RAW", + "char": "-" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 35 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$b", + "line": 35 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n ", + "line": 35 + } + ], + "36": [], + "37": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$c", + "line": 37 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 37 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 37 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$a", + "line": 37 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 37 + }, + { + "type": -1, + "typeName": "RAW", + "char": "*" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 37 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$b", + "line": 37 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 37 + } + ], + "38": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$b", + "line": 38 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 38 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 38 + }, + { + "type": 296, + "typeName": "T_INT_CAST", + "char": "(int)", + "line": 38 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 38 + }, + { + "type": -1, + "typeName": "RAW", + "char": "(" + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$c", + "line": 38 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 38 + }, + { + "type": -1, + "typeName": "RAW", + "char": "\/" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 38 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$a", + "line": 38 + }, + { + "type": -1, + "typeName": "RAW", + "char": ")" + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n ", + "line": 38 + } + ], + "39": [], + "40": [ + { + "type": 345, + "typeName": "T_RETURN", + "char": "return", + "line": 40 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 40 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$c", + "line": 40 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 40 + } + ], + "41": [ + { + "type": -1, + "typeName": "RAW", + "char": "}" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n", + "line": 41 + } + ], + "42": [ + { + "type": -1, + "typeName": "RAW", + "char": "}" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n", + "line": 42 + } + ], + "43": [], + "44": [ + { + "type": 380, + "typeName": "T_COMMENT", + "char": "\/*", + "line": 44, + "original": { + "string": "\/*\n * Multi-line comment\n *\/", + "lines": [ + "\/*", + " * Multi-line comment", + " *\/" + ] + } + } + ], + "45": [ + { + "type": -1, + "typeName": "RAW", + "char": " * Multi-line comment" + } + ], + "46": [ + { + "type": -1, + "typeName": "RAW", + "char": " *\/" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n", + "line": 46 + } + ], + "47": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$foobar", + "line": 47 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 47 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 47 + }, + { + "type": 304, + "typeName": "T_NEW", + "char": "new", + "line": 47 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 47 + }, + { + "type": 311, + "typeName": "T_STRING", + "char": "FooBar", + "line": 47 + }, + { + "type": -1, + "typeName": "RAW", + "char": "(" + }, + { + "type": -1, + "typeName": "RAW", + "char": ")" + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n", + "line": 47 + } + ], + "48": [], + "49": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$baz", + "line": 49 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 49 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 49 + }, + { + "type": -1, + "typeName": "RAW", + "char": "[" + }, + { + "type": 315, + "typeName": "T_CONSTANT_ENCAPSED_STRING", + "char": "'a'", + "line": 49 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 49 + }, + { + "type": 268, + "typeName": "T_DOUBLE_ARROW", + "char": "=>", + "line": 49 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 49 + }, + { + "type": 315, + "typeName": "T_CONSTANT_ENCAPSED_STRING", + "char": "'b'", + "line": 49 + }, + { + "type": -1, + "typeName": "RAW", + "char": "]" + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n", + "line": 49 + } + ], + "50": [], + "51": [ + { + "type": 380, + "typeName": "T_COMMENT", + "char": "\/\/ C++ style comment", + "line": 51, + "original": { + "string": "\/\/ C++ style comment\n", + "lines": [ + "\/\/ C++ style comment", + "" + ] + } + } + ], + "52": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$x", + "line": 52 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 52 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 52 + }, + { + "type": 309, + "typeName": "T_LNUMBER", + "char": "3", + "line": 52 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n", + "line": 52 + } + ], + "53": [], + "54": [ + { + "type": 380, + "typeName": "T_COMMENT", + "char": "# Perl-style comment", + "line": 54, + "original": { + "string": "# Perl-style comment\n", + "lines": [ + "# Perl-style comment", + "" + ] + } + } + ], + "55": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$y", + "line": 55 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 55 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 55 + }, + { + "type": -1, + "typeName": "RAW", + "char": "[" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 55 + } + ], + "56": [ + { + "type": 309, + "typeName": "T_LNUMBER", + "char": "1", + "line": 56 + }, + { + "type": -1, + "typeName": "RAW", + "char": "," + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 56 + } + ], + "57": [ + { + "type": 309, + "typeName": "T_LNUMBER", + "char": "2", + "line": 57 + }, + { + "type": -1, + "typeName": "RAW", + "char": "," + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 57 + } + ], + "58": [ + { + "type": 309, + "typeName": "T_LNUMBER", + "char": "3", + "line": 58 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n", + "line": 58 + } + ], + "59": [ + { + "type": -1, + "typeName": "RAW", + "char": "]" + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n", + "line": 59 + } + ], + "60": [], + "61": [ + { + "type": 380, + "typeName": "T_COMMENT", + "char": "\/\/ Multi-line ternary statement", + "line": 61, + "original": { + "string": "\/\/ Multi-line ternary statement\n", + "lines": [ + "\/\/ Multi-line ternary statement", + "" + ] + } + } + ], + "62": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$q", + "line": 62 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 62 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 62 + }, + { + "type": -1, + "typeName": "RAW", + "char": "(" + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$x", + "line": 62 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 62 + }, + { + "type": 289, + "typeName": "T_IS_NOT_IDENTICAL", + "char": "!==", + "line": 62 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 62 + }, + { + "type": 309, + "typeName": "T_LNUMBER", + "char": "2", + "line": 62 + }, + { + "type": -1, + "typeName": "RAW", + "char": ")" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 62 + } + ], + "63": [ + { + "type": -1, + "typeName": "RAW", + "char": "?" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 63 + }, + { + "type": 315, + "typeName": "T_CONSTANT_ENCAPSED_STRING", + "char": "'yes'", + "line": 63 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n ", + "line": 63 + } + ], + "64": [ + { + "type": -1, + "typeName": "RAW", + "char": ":" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 64 + }, + { + "type": 315, + "typeName": "T_CONSTANT_ENCAPSED_STRING", + "char": "'no'", + "line": 64 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n", + "line": 64 + } + ], + "65": [], + "66": [ + { + "type": 380, + "typeName": "T_COMMENT", + "char": "\/*", + "line": 66, + "original": { + "string": "\/*\nHeredoc\n*\/", + "lines": [ + "\/*", + "Heredoc", + "*\/" + ] + } + } + ], + "67": [ + { + "type": -1, + "typeName": "RAW", + "char": "Heredoc" + } + ], + "68": [ + { + "type": -1, + "typeName": "RAW", + "char": "*\/" + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$z", + "line": 68 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 68 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 68 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$x", + "line": 68 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 68 + }, + { + "type": -1, + "typeName": "RAW", + "char": "+" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 68 + }, + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$y", + "line": 68 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n", + "line": 68 + } + ], + "69": [ + { + "type": 312, + "typeName": "T_VARIABLE", + "char": "$sql", + "line": 69 + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 69 + }, + { + "type": -1, + "typeName": "RAW", + "char": "=" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": " ", + "line": 69 + }, + { + "type": 386, + "typeName": "T_START_HEREDOC", + "char": "<<{x}<\/foo>", + "line": 75, + "original": { + "string": " {x}<\/foo>\n", + "lines": [ + " {x}<\/foo>", + "" + ] + } + } + ], + "76": [ + { + "type": 387, + "typeName": "T_END_HEREDOC", + "char": "TEMPLATE", + "line": 76 + }, + { + "type": -1, + "typeName": "RAW", + "char": ";" + }, + { + "type": 385, + "typeName": "T_WHITESPACE", + "char": "\n\n", + "line": 76 + } + ], + "77": [], + "78": [ + { + "type": 384, + "typeName": "T_CLOSE_TAG", + "char": "?>", + "line": 78, + "original": { + "string": "?>\n", + "lines": [ + "?>", + "" + ] + } + } + ], + "79": [ + { + "type": 313, + "typeName": "T_INLINE_HTML", + "char": "", + "line": 79, + "original": { + "string": "\n\n

", + "lines": [ + "", + "", + "

" + ] + } + } + ], + "80": [ + { + "type": -1, + "typeName": "RAW", + "char": "" + } + ], + "81": [ + { + "type": -1, + "typeName": "RAW", + "char": "

" + }, + { + "type": 383, + "typeName": "T_OPEN_TAG_WITH_ECHO", + "char": "", + "line": 81 + }, + { + "type": 313, + "typeName": "T_INLINE_HTML", + "char": "<\/h1>", + "line": 81, + "original": { + "string": "<\/h1>\n<\/body>\n<\/html>\n", + "lines": [ + "<\/h1>", + "<\/body>", + "<\/html>", + "" + ] + } + } + ], + "82": [ + { + "type": -1, + "typeName": "RAW", + "char": "<\/body>" + } + ], + "83": [ + { + "type": -1, + "typeName": "RAW", + "char": "<\/html>" + } + ], + "84": [ + { + "type": 382, + "typeName": "T_OPEN_TAG", + "char": "", + "line": 84 + } + ] + } +} diff --git a/tests/__snapshots__/EditorTest__test__debugInfo__1.json b/tests/__snapshots__/EditorTest__test__debugInfo__1.json new file mode 100644 index 0000000..81985db --- /dev/null +++ b/tests/__snapshots__/EditorTest__test__debugInfo__1.json @@ -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": [] +}