forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeSpecifierOrContextsTest.hack
67 lines (61 loc) · 1.91 KB
/
TypeSpecifierOrContextsTest.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* 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 TypeSpecifierOrContextsTest extends TestCase {
public function getTypeConstraintExamples(
): dict<string, (string, classname<Node>)> {
return dict[
'unwrapped type specifier' => tuple(
'abstract const type TFoo as shape(...)',
ShapeTypeSpecifier::class,
),
'wrapped type specifier' => tuple(
'abstract const type TFoo as MyClass',
SimpleTypeSpecifier::class,
),
];
}
<<DataProvider('getTypeConstraintExamples')>>
public async function testTypeConstraintExample(
string $code,
classname<Node> $expected,
): Awaitable<void> {
$ast = await from_file_async(
File::fromPathAndContents(
'/dev/null',
'abstract class Foo { '.$code.'; }',
),
);
$constraint = expect($ast->getFirstDescendantByType<TypeConstraint>())
->toNotBeNull('Expected the AST to contain a %s!', TypeConstraint::class);
expect($constraint->getType())->toBeInstanceOf($expected);
}
public function getContextConstraintExamples(): dict<string, (string)> {
return dict[
'contexts' => tuple('abstract const ctx CFoo super [defaults]'),
];
}
<<DataProvider('getContextConstraintExamples')>>
public async function testContextConstraintExample(
string $code,
): Awaitable<void> {
$ast = await from_file_async(
File::fromPathAndContents(
'/dev/null',
'abstract class Foo { '.$code.'; }',
),
);
expect($ast->getFirstDescendantByType<ContextConstraint>())->toNotBeNull(
'Expected the AST to contain a %s!',
ContextConstraint::class,
);
}
}