forked from hhvm/hhast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNonHackFileTest.hack
75 lines (67 loc) · 2.24 KB
/
NonHackFileTest.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
68
69
70
71
72
73
74
75
/*
* 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 namespace HH\Lib\Vec;
use type Facebook\HackTest\{DataProvider, HackTest};
use function Facebook\FBExpect\expect;
final class NonHackFileTest extends HackTest {
public function provideNonHackFiles(): vec<(File)> {
return vec[
'php_files/empty_file.php.unparsable',
'php_files/html_file.php.unparsable',
'php_files/templated_html_file.php.unparsable',
'php_files/real_php_file.php.unparsable',
]
|> static::filePathsTheFiles($$)
|> Vec\map($$, $file ==> tuple($file));
}
<<DataProvider('provideNonHackFiles')>>
public function testFilesThatDoNotStartWithAnHHTokenOrASheebangFollowedByAnHHTokenAreNotHackFiles(
File $file,
): void {
expect($file->isHackFile())->toBeFalse(
'File "%s" should not be a Hack file',
$file->getPath(),
);
}
public function provideHackFilesWithAmbiguousExtensions(): vec<(File)> {
return vec[
// We cannot exclude extensions, since `.in` and friends are valid hack files
'incorrect_extension/hackfile.hack.in',
'hack_files/deprecated.hck',
'hack_files/hello_world.hh',
'hack_files/hello_world.php',
'hack_files/shee_bang.php',
]
|> static::filePathsTheFiles($$)
|> Vec\map($$, $file ==> tuple($file));
}
<<DataProvider('provideHackFilesWithAmbiguousExtensions')>>
public function testFileThatStartWithAnHHTokenOrASheebangFollowedByAnHHTokenAreHackFiles(
File $file,
): void {
expect($file->isHackFile())->toBeTrue(
'File "%s" should be a Hack file',
$file->getPath(),
);
}
public function testFilesWithADotHackExtensionAreAlwaysHackFiles(): void {
$file = File::fromPathAndContents('_.hack', 'function main(): void {}');
expect($file->isHackFile())->toBeTrue(
'File "%s" should be a Hack file',
$file->getContents(),
);
}
private static function filePathsTheFiles(vec<string> $paths): vec<File> {
return Vec\map(
$paths,
$path ==> File::fromPath(__DIR__.'/examples/NonHackFileTest/'.$path),
);
}
}