From cc0bdabe5f9a9705bf2992831dd45e95d116fe0c Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Tue, 23 Nov 2021 18:23:57 +0100 Subject: highlights(hack): extend queries add tests --- tests/query/highlights/hack/as-foreach.hack | 6 ++++ tests/query/highlights/hack/async-functions.hack | 8 +++++ tests/query/highlights/hack/attribute-type.hack | 15 ++++++++ tests/query/highlights/hack/generics.hack | 23 ++++++++++++ tests/query/highlights/hack/heredoc-dollar.hack | 4 +++ tests/query/highlights/hack/use.hack | 28 +++++++++++++++ tests/query/highlights/hack/using.hack | 3 ++ tests/query/highlights/hack/xhp.hack | 10 ++++++ tests/query/highlights/xhp-intro.hack | 46 ++++++++++++++++++++++++ 9 files changed, 143 insertions(+) create mode 100644 tests/query/highlights/hack/as-foreach.hack create mode 100644 tests/query/highlights/hack/async-functions.hack create mode 100644 tests/query/highlights/hack/attribute-type.hack create mode 100644 tests/query/highlights/hack/generics.hack create mode 100644 tests/query/highlights/hack/heredoc-dollar.hack create mode 100644 tests/query/highlights/hack/use.hack create mode 100644 tests/query/highlights/hack/using.hack create mode 100644 tests/query/highlights/hack/xhp.hack create mode 100644 tests/query/highlights/xhp-intro.hack (limited to 'tests/query') diff --git a/tests/query/highlights/hack/as-foreach.hack b/tests/query/highlights/hack/as-foreach.hack new file mode 100644 index 00000000..8969be8f --- /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 00000000..4488c992 --- /dev/null +++ b/tests/query/highlights/hack/async-functions.hack @@ -0,0 +1,8 @@ +async function func0(): void {} +// ^ type.builtin +async function func1() {} +// ^ 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 00000000..9f62d19d --- /dev/null +++ b/tests/query/highlights/hack/attribute-type.hack @@ -0,0 +1,15 @@ +<> +newtype T1 = ?shape( +// TODO: ?operator (? not captureable at the moment) + ?'int' => int +// ^ operator +); + +<> +// ^ attribute +type T2 = (function(T1): string); +// ^ type +// ^ function (cannot capture keyword "function" as keyword.function) + +<> +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 00000000..ea605420 --- /dev/null +++ b/tests/query/highlights/hack/generics.hack @@ -0,0 +1,23 @@ +class Box { + // ^ 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 00000000..8034cc86 --- /dev/null +++ b/tests/query/highlights/hack/heredoc-dollar.hack @@ -0,0 +1,4 @@ +<<Hello $user_name"; + +// XHP: Typechecked, well-formed, and secure +$user_name = 'Andrew'; +$xhp = Hello {$user_name}; +// ^ 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 00000000..cc25f584 --- /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 { + $id = $this->getID(); + + $anchor = {$this->getChildren()}; + // ^ tag.delimiter + // ^ tag + $form = ( +
:href} + target={$this->:target} + class="postLink"> + {$anchor} +
+ ); + + $anchor->setAttribute( + 'onclick', + 'document.getElementById("'.$id.'").submit(); return false;', + ); + $anchor->setAttribute('href', '#'); + // ^ method + + return $form; + } +} + -- cgit v1.2.3