forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeAtPositionTest.hack
51 lines (45 loc) · 1.23 KB
/
NodeAtPositionTest.hack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
namespace Facebook\HHAST;
use function Facebook\FBExpect\expect;
use type Facebook\HackTest\DataProvider;
final class NodeAtPositionTest extends TestCase {
public function getExamples(
): vec<(string, (int, int), classname<Node>, string)> {
return vec[
tuple(
"<?hh\nreturn 123;\n",
tuple(2, 1),
ReturnStatement::class,
"return 123;\n",
),
tuple(
"<?hh\n return 123;\n",
tuple(2, 3),
ReturnStatement::class,
" return 123;\n",
),
];
}
<<DataProvider('getExamples')>>
public async function testNodeAtPosition(
string $code,
(int, int) $position,
classname<Node> $node_class,
string $node_code,
): Awaitable<void> {
list($line, $column) = $position;
$root = await from_file_async(
File::fromPathAndContents('/dev/null', $code),
);
$node = find_node_at_position($root, $line, $column);
expect($node)->toBeInstanceOf($node_class);
expect($node->getCode())->toBeSame($node_code);
}
}