get rid of intellij.build.toolbox.litegen parameter and use BuildOptions.TOOLBOX_LITE...
[idea/community.git] / RegExpSupport / test / org / intellij / lang / regexp / RegExpCompletionTest.java
1 /*
2  * Copyright 2000-2016 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.intellij.lang.regexp;
17
18 import com.intellij.codeInsight.lookup.LookupElement;
19 import com.intellij.openapi.application.PathManager;
20 import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
21 import com.intellij.util.ArrayUtil;
22 import com.intellij.util.containers.ContainerUtil;
23
24 import java.io.File;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28
29 public class RegExpCompletionTest extends CodeInsightFixtureTestCase {
30
31   // util methods
32     private static String getInputDataFileName(String testName) {
33         return Character.toUpperCase(testName.charAt(0)) + testName.substring(1) + ".regexp";
34     }
35
36     private static String getExpectedResultFileName(String testName) {
37         return Character.toUpperCase(testName.charAt(0)) + testName.substring(1) + "Expected" + ".regexp";
38     }
39
40     public void testNamedCharacter() {
41       myFixture.configureByText(RegExpFileType.INSTANCE, "\\N{SMILE<caret>}");
42       final LookupElement[] elements = myFixture.completeBasic();
43       final List<String> strings = ContainerUtil.map(elements, LookupElement::getLookupString);
44       List<String> alwaysPresent = Arrays.asList("SMILE", "SMILING FACE WITH SMILING EYES", "SMILING FACE WITH HEART-SHAPED EYES",
45                                                  "SMILING CAT FACE WITH HEART-SHAPED EYES", "SMILING FACE WITH OPEN MOUTH AND SMILING EYES",
46                                                  "SMILING FACE WITH OPEN MOUTH AND TIGHTLY-CLOSED EYES", "CAT FACE WITH WRY SMILE",
47                                                  "GRINNING CAT FACE WITH SMILING EYES", "GRINNING FACE WITH SMILING EYES",
48                                                  "KISSING FACE WITH SMILING EYES");
49       String message = strings.toString();
50       assertTrue(message, strings.containsAll(alwaysPresent));
51       List<String> other = new ArrayList<>(strings);
52       other.removeAll(alwaysPresent);
53       // Unicode 10.0
54       List<String> maybePresent = Arrays.asList("SMILING FACE WITH SMILING EYES AND HAND COVERING MOUTH", "SIGNWRITING MOUTH SMILE",
55                                                 "SIGNWRITING MOUTH SMILE OPEN", "SIGNWRITING MOUTH SMILE WRINKLED");
56       assertTrue(message, maybePresent.containsAll(other));
57     }
58
59     public void testBackSlashVariants() {
60         List<String> nameList =
61           new ArrayList<>(Arrays.asList("d", "D", "s", "S", "w", "W", "b", "B", "A", "G", "Z", "z", "Q", "E",
62                                         "t", "n", "r", "f", "a", "e", "h", "H", "v", "V", "R", "X", "b{g}"));
63         for (String[] stringArray : DefaultRegExpPropertiesProvider.getInstance().getAllKnownProperties()) {
64             nameList.add("p{" + stringArray[0] + "}");
65         }
66         myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList));
67     }
68
69     public void testPropertyVariants() {
70         List<String> nameList = new ArrayList<>();
71         for (String[] stringArray : DefaultRegExpPropertiesProvider.getInstance().getAllKnownProperties()) {
72             nameList.add("{" + stringArray[0] + "}");
73         }
74         myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), ArrayUtil.toStringArray(nameList));
75     }
76
77     public void testPropertyAlpha() {
78       myFixture.configureByText(RegExpFileType.INSTANCE, "\\P{Alp<caret>}");
79       myFixture.completeBasic();
80       myFixture.checkResult("\\P{Alpha<caret>}");
81     }
82
83     public void doTest() {
84         String inputDataFileName = getInputDataFileName(getTestName(true));
85         String expectedResultFileName = getExpectedResultFileName(getTestName(true));
86         myFixture.testCompletion(inputDataFileName, expectedResultFileName);
87     }
88
89     @Override
90     protected String getBasePath() {
91       String homePath = PathManager.getHomePath();
92       File candidate = new File(homePath, "community/RegExpSupport/testData/completion");
93       if (candidate.isDirectory()) {
94         return "/community/RegExpSupport/testData/completion";
95       }
96       return "/RegExpSupport/testData/completion";
97     }
98 }