aboutsummaryrefslogtreecommitdiffstats
path: root/tests/query/highlights
diff options
context:
space:
mode:
authorCaleb White <cdwhite3@pm.me>2024-03-18 21:19:50 -0500
committerChristian Clason <c.clason@uni-graz.at>2024-03-27 08:29:44 +0100
commit34007887059238f63a49ab4d382d839d9405c66c (patch)
treea5d7b7aa35fa3a8dda72194023eec2e587d13c74 /tests/query/highlights
parentbot(lockfile): update djot, hlsplaylist, html, meson, muttrc, query, svelte, ... (diff)
downloadnvim-treesitter-34007887059238f63a49ab4d382d839d9405c66c.tar
nvim-treesitter-34007887059238f63a49ab4d382d839d9405c66c.tar.gz
nvim-treesitter-34007887059238f63a49ab4d382d839d9405c66c.tar.bz2
nvim-treesitter-34007887059238f63a49ab4d382d839d9405c66c.tar.lz
nvim-treesitter-34007887059238f63a49ab4d382d839d9405c66c.tar.xz
nvim-treesitter-34007887059238f63a49ab4d382d839d9405c66c.tar.zst
nvim-treesitter-34007887059238f63a49ab4d382d839d9405c66c.zip
feat(php): add highlight tests
Diffstat (limited to 'tests/query/highlights')
-rw-r--r--tests/query/highlights/php/keywords.php173
-rw-r--r--tests/query/highlights/php/literals.php26
-rw-r--r--tests/query/highlights/php/types.php23
-rw-r--r--tests/query/highlights/php/variables.php28
4 files changed, 250 insertions, 0 deletions
diff --git a/tests/query/highlights/php/keywords.php b/tests/query/highlights/php/keywords.php
new file mode 100644
index 000000000..e11a9f351
--- /dev/null
+++ b/tests/query/highlights/php/keywords.php
@@ -0,0 +1,173 @@
+<?php
+//^^^ @punctuation.bracket
+
+declare(strict_types=1);
+//^^^^^ @keyword
+// ^^^^^^^^^^^^ @variable.parameter
+// ^ @operator
+// ^ @number
+// ^ @punctuation.delimiter
+
+include "file.php";
+//^^^^^ @keyword.import
+// ^^^^^^^^^ @string
+include_once "file.php";
+//^^^^^^^^^^ @keyword.import
+require "file.php";
+//^^^^^ @keyword.import
+require_once "file.php";
+//^^^^^^^^^^ @keyword.import
+
+namespace A\B;
+//^^^^^^^ @keyword
+// ^^^ @module
+
+if ($a and $b or $c xor $d) {} elseif ($b) {} else {}
+// <- @keyword.conditional
+// ^^^ @keyword.operator
+// ^^ @keyword.operator
+// ^^^ @keyword.operator
+// ^^^^^^ @keyword.conditional
+// ^^^^ @keyword.conditional
+
+for ($i = 0; $i < 1; $i++) { continue; }
+// <- @keyword.repeat
+// ^ @operator
+// ^^ @operator
+// ^^^^^^^^ @keyword.repeat
+
+while ($b) {}
+//^^^ @keyword.repeat
+
+do { } while ($c);
+// <- @keyword.repeat
+// ^^^^^ @keyword.repeat
+
+foreach ($foos as $foo) {}
+//^^^^^ @keyword.repeat
+// ^^ @keyword.operator
+
+try {} catch (Exception $e) {} finally {}
+//^ @keyword.exception
+// ^^^^^ @keyword.exception
+// ^^^^^^^^^ @type
+// ^^^^^^^ @keyword.exception
+
+function a() {}
+//^^^^^^ @keyword.function
+// ^ @function
+
+abstract class A
+//^^^^^^ @keyword.modifier
+// ^^^^^ @keyword
+// ^ @type
+{
+ private const BAR = 1;
+//^^^^^^^ @keyword.modifier
+// ^^^^^ @keyword.modifier
+ // ^^^ @constant
+ protected readonly static $a;
+//^^^^^^^^^ @keyword.modifier
+// ^^^^^^^^ @keyword.modifier
+// ^^^^^^ @keyword.modifier
+ // ^^ @property
+ final public $b;
+//^^^^^ @keyword.modifier
+ public static function foo(): static {}
+//^^^^^^ @keyword.modifier
+// ^^^^^^ @keyword.modifier
+// ^^^^^^^^ @keyword.function
+// ^^^ @function.method
+// ^^^^^^ @type.builtin
+ public function __construct() {}
+// ^^^^^^^^^^^ @constructor
+}
+
+class B extends A implements T
+// ^ @type
+// ^^^^^^^ @keyword
+// ^ @type
+// ^^^^^^^^^^ @keyword
+// ^ @type
+{
+ use T, U {
+//^^^ @keyword.import
+// ^ @punctuation.delimiter
+ U::small insteadof T;
+// ^ @type
+// ^^ @operator
+// ^^^^^ @constant
+// ^^^^^^^^^ @keyword
+// ^ @type
+ }
+ public function foo(callable $call): self
+// ^^^^^^^^ @type.builtin
+// ^^^^ @type.builtin
+ {
+ $call instanceof Closure;
+// ^^^^^ @variable
+// ^^^^^^^^^^ @keyword
+// ^^^^^^^ @type
+ fn ($a, $b) => $a + $b;
+// ^^ @keyword.function
+ static $a;
+// ^^^^^^ @keyword.modifier
+ global $a;
+// ^^^^^^ @keyword
+ clone $call;
+// ^^^^^ @keyword
+ match ($a) {
+// ^^^^^ @keyword.conditional
+ default => "other",
+// ^^^^^^^ @keyword
+// ^^ @operator
+ };
+
+ switch ($a) {
+// ^^^^^^ @keyword.conditional
+ case 'value':
+// ^^^^ @keyword.conditional
+ break;
+// ^^^^^ @keyword
+ default:
+// ^^^^^^^ @keyword
+ }
+ yield $a;
+// ^^^^^ @keyword.return
+ yield from $a;
+// ^^^^ @keyword.return
+ return $a;
+// ^^^^^^ @keyword.return
+ goto a;
+// ^^^^ @keyword
+ echo "a";
+// ^^^^ @keyword
+ print "a";
+// ^^^^^ @keyword
+ print("a");
+// ^^^^^ @keyword
+ exit;
+// ^^^^ @keyword
+ exit();
+// ^^^^ @function.builtin
+ exit(1);
+// ^^^^ @function.builtin
+ }
+}
+
+throw new Exception("oh");
+//^^^ @keyword.exception
+// ^^^ @keyword
+// ^^^^^^^^^ @constructor
+
+interface T {}
+//^^^^^^^ @keyword
+// ^ @type
+
+trait T { public function small(): void {} }
+//^^^ @keyword
+// ^ @type
+// ^^^^ @type.builtin
+enum Foo { case Bar; }
+//^^ @keyword
+// ^^^^ @keyword.conditional
diff --git a/tests/query/highlights/php/literals.php b/tests/query/highlights/php/literals.php
new file mode 100644
index 000000000..17b539362
--- /dev/null
+++ b/tests/query/highlights/php/literals.php
@@ -0,0 +1,26 @@
+<?php
+
+echo <<<OMG
+// ^^^ @operator
+// ^^^ @label
+ something
+OMG;
+//^ @label
+
+echo true, TRUE, false, FALSE;
+// ^^^^ @boolean
+// ^^^^ @boolean
+// ^^^^^ @boolean
+// ^^^^^ @boolean
+
+echo PI_314;
+// ^^^^^^ @constant
+
+echo __DIR__;
+// ^^^^^^^ @constant.builtin
+
+echo null, 42, 42.524, "Testing\n";
+// ^^^^ @constant.builtin
+// ^^ @number
+// ^^^^^^ @number.float
+// ^^ @string.escape
diff --git a/tests/query/highlights/php/types.php b/tests/query/highlights/php/types.php
new file mode 100644
index 000000000..7a3adb233
--- /dev/null
+++ b/tests/query/highlights/php/types.php
@@ -0,0 +1,23 @@
+<?php
+
+function b(int $a, string $b, Person $e): Foo\Dog {}
+// ^^^ @type.builtin
+// ^^ @variable
+// ^^^^^^ @type.builtin
+// ^^^^^^ @type
+// ^^^ @module
+// ^^^ @type
+
+function a(array $b) {
+// ^^^^^ @type.builtin
+ echo (int) $foo;
+// ^^^ @type.builtin
+}
+
+class A {
+ public function foo(self $a): self {}
+// ^^^^ @type.builtin
+// ^^^^ @type.builtin
+ private function baz(): static {}
+// ^^^^^^ @type.builtin
+}
diff --git a/tests/query/highlights/php/variables.php b/tests/query/highlights/php/variables.php
new file mode 100644
index 000000000..6a466357c
--- /dev/null
+++ b/tests/query/highlights/php/variables.php
@@ -0,0 +1,28 @@
+<?php
+
+class A {
+ public function foo(self $a): self {
+// ^ @variable
+ new self();
+// ^^^^ @constructor
+ new static();
+// ^^^^^^ @constructor
+ new parent();
+// ^^^^^^ @constructor
+ $this->foo();
+// ^^^^ @variable.builtin
+// ^^ @operator
+// ^^^ @function.method.call
+ self::foo();
+// ^^^^ @variable.builtin
+// ^^^ @function.call
+ static::foo();
+// ^^^^^^ @variable.builtin
+ parent::foo();
+// ^^^^^^ @variable.builtin
+ $this->foo;
+// ^^^ @variable.member
+ $this->foo(a: 5);
+// ^ @variable.parameter
+ }
+}