forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOffsetFromPositionTest.hack
More file actions
46 lines (41 loc) · 1.22 KB
/
OffsetFromPositionTest.hack
File metadata and controls
46 lines (41 loc) · 1.22 KB
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
/*
* 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 OffsetFromPositionTest extends TestCase {
public function getExamples(): vec<(string, (int, int), int)> {
return vec[
tuple("<?hh // strict \n", tuple(1, 1), 0),
tuple("<?hh // strict \n", tuple(1, 3), 2),
tuple("<?hh\nbar();\n", tuple(2, 1), 5),
tuple("<?hh\nbar();\n", tuple(2, 2), 6),
];
}
<<DataProvider('getExamples')>>
public async function testOffsetFromPosition(
string $code,
(int, int) $position,
int $expected_offset,
): Awaitable<void> {
list($line, $column) = $position;
$root = await from_file_async(
File::fromPathAndContents('/dev/null', $code),
);
$actual_offset = offset_from_position($root, $line, $column);
expect($actual_offset)->toBeSame(
$expected_offset,
'Expected line %d column %d to be offset %d, but got %d',
$line,
$column,
$expected_offset,
$actual_offset,
);
}
}