forked from hhvm/hack-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodegenTraitTest.hack
More file actions
87 lines (81 loc) · 2.61 KB
/
CodegenTraitTest.hack
File metadata and controls
87 lines (81 loc) · 2.61 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
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
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright (c) 2015-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\HackCodegen;
final class CodegenTraitTest extends CodegenBaseTest {
public function testDocblock(): void {
$cgf = $this->getCodegenFactory();
$code = $cgf
->codegenTrait('TestDocblockInternal')
->setDocBlock(
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed '.
'do eiusmod tempor incididunt ut labore et dolore magna aliqua. '.
'Ut enim ad minim veniam, quis nostrud exercitation ullamco '.
"laboris nisi ut aliquip ex ea commodo consequat.\n".
"Understood?\n".
'Yes!',
)
->render();
expect_with_context(static::class, $code)->toBeUnchanged();
}
public function testDemo(): void {
$cgf = $this->getCodegenFactory();
$code = $cgf
->codegenTrait('DemoInternal')
->addRequireClass('RequiredClass')
->addRequireInterface('RequiredInterface')
->addTrait($cgf->codegenUsesTrait('DemoTrait'))
->addTrait(
$cgf
->codegenUsesTrait('WhateverTrait')
->setGeneratedFrom(
$cgf->codegenGeneratedFromMethod('Whatever', 'Method'),
),
)
->addTrait($cgf->codegenUsesTrait('Useless'))
->addConstant(
$cgf->codegenClassConstant('MAX_SIZE')
->setValue(256, HackBuilderValues::export()),
)
->addConstant(
$cgf->codegenClassConstant('DEFAULT_NAME')
->setValue('MyEnt', HackBuilderValues::export())
->setDocBlock('Default name of Ent.'),
)
->addConstant(
$cgf->codegenClassConstant('PI')
->setValue(3.1415, HackBuilderValues::export()),
)
->setHasManualMethodSection()
->setHasManualDeclarations()
->addProperty(
$cgf->codegenProperty('text')->setProtected()->setType('string'),
)
->addProperty(
$cgf
->codegenProperty('id')
->setType('?int')
->setValue(12345, HackBuilderValues::export()),
)
->addMethod(
$cgf
->codegenMethod('genX')
->setProtected()
->setDocBlock(
'This is a 76 characters comment to test the splitting '.
'based on indentation.',
)
->setReturnType('Awaitable<int>')
->setManualBody()
->setBody('// your code here'),
)
->setDocBlock('doc-doc-doc!')
->render();
expect_with_context(static::class, $code)->toBeUnchanged();
}
}