1
1
package fr .adrienbrault .idea .symfony2plugin .tests .templating .util ;
2
2
3
+ import com .intellij .psi .PsiFile ;
4
+ import com .intellij .psi .PsiFileFactory ;
3
5
import com .jetbrains .php .lang .psi .PhpPsiElementFactory ;
4
6
import com .jetbrains .php .lang .psi .elements .Method ;
7
+ import com .jetbrains .twig .TwigFile ;
8
+ import com .jetbrains .twig .TwigLanguage ;
5
9
import fr .adrienbrault .idea .symfony2plugin .templating .util .TwigTypeResolveUtil ;
6
10
import fr .adrienbrault .idea .symfony2plugin .tests .SymfonyLightCodeInsightFixtureTestCase ;
7
11
import org .jetbrains .annotations .NotNull ;
8
12
13
+ import java .util .Map ;
14
+
9
15
/**
10
16
* @author Daniel Espendiller <daniel@espendiller.net>
11
17
*/
@@ -17,6 +23,49 @@ public void testThatTwigGetAttributeSupportShortcuts() {
17
23
assertEquals ("foo" , TwigTypeResolveUtil .getPropertyShortcutMethodName (createMethod ("isFoo" )));
18
24
}
19
25
26
+ /**
27
+ * @see TwigTypeResolveUtil#findFileVariableDocBlock
28
+ */
29
+ public void testFindFileVariableDocBlock () {
30
+ PsiFile fileFromText = PsiFileFactory .getInstance (getProject ()).createFileFromText (TwigLanguage .INSTANCE , "" +
31
+ "{# @var foo_1 \\ AppBundle\\ Entity\\ MeterValueDTO #}\n " +
32
+ "{# @var foo_2 \\ AppBundle\\ Entity\\ MeterValueDTO[] #}\n " +
33
+ "{# @var \\ AppBundle\\ Entity\\ MeterValueDTO foo_3 #}\n " +
34
+ "{# @var \\ AppBundle\\ Entity\\ MeterValueDTO[] foo_4 #}\n " +
35
+ "" +
36
+ "{#\n " +
37
+ "@var \\ AppBundle\\ Entity\\ MeterValueDTO foo_5\n " +
38
+ "@var foo_6 \\ AppBundle\\ Entity\\ MeterValueDTO\n " +
39
+ "#}\n "
40
+ );
41
+
42
+ Map <String , String > fileVariableDocBlock = TwigTypeResolveUtil .findFileVariableDocBlock ((TwigFile ) fileFromText );
43
+
44
+ assertEquals ("\\ AppBundle\\ Entity\\ MeterValueDTO" , fileVariableDocBlock .get ("foo_1" ));
45
+ assertEquals ("\\ AppBundle\\ Entity\\ MeterValueDTO[]" , fileVariableDocBlock .get ("foo_2" ));
46
+ assertEquals ("\\ AppBundle\\ Entity\\ MeterValueDTO" , fileVariableDocBlock .get ("foo_3" ));
47
+ assertEquals ("\\ AppBundle\\ Entity\\ MeterValueDTO[]" , fileVariableDocBlock .get ("foo_4" ));
48
+
49
+ assertEquals ("\\ AppBundle\\ Entity\\ MeterValueDTO" , fileVariableDocBlock .get ("foo_5" ));
50
+ assertEquals ("\\ AppBundle\\ Entity\\ MeterValueDTO" , fileVariableDocBlock .get ("foo_6" ));
51
+ }
52
+
53
+ public void testReqExForInlineDocVariables () {
54
+ assertMatches ("{# @var foo_1 \\ AppBundle\\ Entity\\ MeterValueDTO #}" , TwigTypeResolveUtil .DOC_TYPE_PATTERN_SINGLE );
55
+ assertMatches ("{# @var \\ AppBundle\\ Entity\\ MeterValueDTO foo_1 #}" , TwigTypeResolveUtil .DOC_TYPE_PATTERN_SINGLE );
56
+ assertMatches ("{# foo_1 \\ AppBundle\\ Entity\\ MeterValueDTO #}" , TwigTypeResolveUtil .DOC_TYPE_PATTERN_SINGLE );
57
+ }
58
+
59
+ private void assertMatches (@ NotNull String content , @ NotNull String ... regularExpressions ) {
60
+ for (String regularExpression : regularExpressions ) {
61
+ if (content .matches (regularExpression )) {
62
+ return ;
63
+ }
64
+ }
65
+
66
+ fail ("invalid regular expression: " + content );
67
+ }
68
+
20
69
@ NotNull
21
70
private Method createMethod (@ NotNull String method ) {
22
71
return PhpPsiElementFactory .createFromText (
0 commit comments