aboutsummaryrefslogtreecommitdiffstats
path: root/tests/query
diff options
context:
space:
mode:
authorStephan Seitz <stephan.seitz@fau.de>2021-11-23 18:23:57 +0100
committerStephan Seitz <stephan.seitz@fau.de>2022-01-17 10:53:35 +0100
commitcc0bdabe5f9a9705bf2992831dd45e95d116fe0c (patch)
treeed755e7e9dc1122d52b1431271fbe3c814347c93 /tests/query
parentAdd ftdect for hack (diff)
downloadnvim-treesitter-cc0bdabe5f9a9705bf2992831dd45e95d116fe0c.tar
nvim-treesitter-cc0bdabe5f9a9705bf2992831dd45e95d116fe0c.tar.gz
nvim-treesitter-cc0bdabe5f9a9705bf2992831dd45e95d116fe0c.tar.bz2
nvim-treesitter-cc0bdabe5f9a9705bf2992831dd45e95d116fe0c.tar.lz
nvim-treesitter-cc0bdabe5f9a9705bf2992831dd45e95d116fe0c.tar.xz
nvim-treesitter-cc0bdabe5f9a9705bf2992831dd45e95d116fe0c.tar.zst
nvim-treesitter-cc0bdabe5f9a9705bf2992831dd45e95d116fe0c.zip
highlights(hack): extend queries add tests
Diffstat (limited to 'tests/query')
-rw-r--r--tests/query/highlights/hack/as-foreach.hack6
-rw-r--r--tests/query/highlights/hack/async-functions.hack8
-rw-r--r--tests/query/highlights/hack/attribute-type.hack15
-rw-r--r--tests/query/highlights/hack/generics.hack23
-rw-r--r--tests/query/highlights/hack/heredoc-dollar.hack4
-rw-r--r--tests/query/highlights/hack/use.hack28
-rw-r--r--tests/query/highlights/hack/using.hack3
-rw-r--r--tests/query/highlights/hack/xhp.hack10
-rw-r--r--tests/query/highlights/xhp-intro.hack46
9 files changed, 143 insertions, 0 deletions
diff --git a/tests/query/highlights/hack/as-foreach.hack b/tests/query/highlights/hack/as-foreach.hack
new file mode 100644
index 000000000..8969be8fc
--- /dev/null
+++ b/tests/query/highlights/hack/as-foreach.hack
@@ -0,0 +1,6 @@
+foreach (($array as vec[]) as $item) {}
+// ^ repeat
+// ^ type
+
+# Our expectation test for the code below intentionally includes an ERROR.
+foreach ($array as vec[] as $item) {}
diff --git a/tests/query/highlights/hack/async-functions.hack b/tests/query/highlights/hack/async-functions.hack
new file mode 100644
index 000000000..4488c992d
--- /dev/null
+++ b/tests/query/highlights/hack/async-functions.hack
@@ -0,0 +1,8 @@
+async function func0(): void {}
+// ^ type.builtin
+async function func1<T1 as int>() {}
+// ^ type.builtin
+// ^ keyword.operator
+
+
+async ($x) ==> $x + 1;
diff --git a/tests/query/highlights/hack/attribute-type.hack b/tests/query/highlights/hack/attribute-type.hack
new file mode 100644
index 000000000..9f62d19df
--- /dev/null
+++ b/tests/query/highlights/hack/attribute-type.hack
@@ -0,0 +1,15 @@
+<<A1>>
+newtype T1 = ?shape(
+// TODO: ?operator (? not captureable at the moment)
+ ?'int' => int
+// ^ operator
+);
+
+<<A3(1), A2(2,3,)>>
+// ^ attribute
+type T2 = (function(T1): string);
+// ^ type
+// ^ function (cannot capture keyword "function" as keyword.function)
+
+<<A4(1), A5, A6(1,3,4)>>
+newtype T3 as int = int;
diff --git a/tests/query/highlights/hack/generics.hack b/tests/query/highlights/hack/generics.hack
new file mode 100644
index 000000000..ea605420c
--- /dev/null
+++ b/tests/query/highlights/hack/generics.hack
@@ -0,0 +1,23 @@
+class Box<T> {
+ // ^ type
+ // ^ type
+ protected T $data;
+ // ^ keyword
+ // ^ type
+
+ public function __construct(T $data) {
+ // ^ type
+ // ^ parameter
+ // ^ keyword
+ // ^ method
+ $this->data = $data;
+ }
+
+ public function getData(): T {
+ // ^ method
+ // ^ keyword
+ return $this->data;
+ // ^ operator
+ // ^ variable.builtin
+ }
+}
diff --git a/tests/query/highlights/hack/heredoc-dollar.hack b/tests/query/highlights/hack/heredoc-dollar.hack
new file mode 100644
index 000000000..8034cc863
--- /dev/null
+++ b/tests/query/highlights/hack/heredoc-dollar.hack
@@ -0,0 +1,4 @@
+<<<EOT
+ $('a') abc $(function{return;})
+EOT;
+// <- comment ^ comment
diff --git a/tests/query/highlights/hack/use.hack b/tests/query/highlights/hack/use.hack
new file mode 100644
index 000000000..d7b7ce784
--- /dev/null
+++ b/tests/query/highlights/hack/use.hack
@@ -0,0 +1,28 @@
+use const Space\Const\C;
+// ^ keyword
+// ^ constant
+use function Space\Func\F as E;
+// ^ function
+// ^ function
+use type Space\Type\T;
+// ^ keyword
+use namespace Space\Name\N as M;
+// ^ keyword
+// ^ namespace
+
+use namespace Space\Name2\N2, Space\Nothing\N3 as N8, type Space\Type2\N4,;
+// ^ namespace
+// ^ type
+use namespace Space\Name\N10\{A as A2, B\};
+// ^ namespace
+// ^ namespace
+// ^ namespace
+use namespace Space\Name\{\C, Slash as Forward};
+
+use \What\Is\This\{function A as A2, B, const H\S\L as stdlib, function F};
+
+use type \{kind,};
+use Q\B\{kind2,};
+// ^ namespace
+use type Q\B\{kind3,};
+// <- include
diff --git a/tests/query/highlights/hack/using.hack b/tests/query/highlights/hack/using.hack
new file mode 100644
index 000000000..4452ea962
--- /dev/null
+++ b/tests/query/highlights/hack/using.hack
@@ -0,0 +1,3 @@
+using ($new = new Object(), $file = new File('using', '+using')) {}
+// <- keyword
+// ^ type
diff --git a/tests/query/highlights/hack/xhp.hack b/tests/query/highlights/hack/xhp.hack
new file mode 100644
index 000000000..992296b97
--- /dev/null
+++ b/tests/query/highlights/hack/xhp.hack
@@ -0,0 +1,10 @@
+$user_name = 'Fred';
+echo "<tt>Hello <strong>$user_name</tt></strong>";
+
+// XHP: Typechecked, well-formed, and secure
+$user_name = 'Andrew';
+$xhp = <tt>Hello <strong>{$user_name}</strong></tt>;
+// ^ tag
+// ^ tag
+// ^ string
+echo await $xhp->toStringAsync();
diff --git a/tests/query/highlights/xhp-intro.hack b/tests/query/highlights/xhp-intro.hack
new file mode 100644
index 000000000..cc25f5843
--- /dev/null
+++ b/tests/query/highlights/xhp-intro.hack
@@ -0,0 +1,46 @@
+// From https://docs.hhvm.com/hack/XHP/introduction (MIT licensed)
+
+use namespace Facebook\XHP\Core as x;
+use type Facebook\XHP\HTML\{XHPHTMLHelpers, a, form};
+
+
+final xhp class a_post extends x\element {
+// ^ keyword
+// ^ keyword
+// ^ keyword
+ use XHPHTMLHelpers;
+
+ attribute string href @required;
+ // ^ attribute
+ attribute string target;
+ // ^ keyword
+
+ <<__Override>>
+ protected async function renderAsync(): Awaitable<x\node> {
+ $id = $this->getID();
+
+ $anchor = <a>{$this->getChildren()}</a>;
+ // ^ tag.delimiter
+ // ^ tag
+ $form = (
+ <form
+ id={$id}
+ method="post"
+ action={$this->:href}
+ target={$this->:target}
+ class="postLink">
+ {$anchor}
+ </form>
+ );
+
+ $anchor->setAttribute(
+ 'onclick',
+ 'document.getElementById("'.$id.'").submit(); return false;',
+ );
+ $anchor->setAttribute('href', '#');
+ // ^ method
+
+ return $form;
+ }
+}
+