diff --git a/src/test/java/org/ballerinalang/completion/BallerinaCompletionTest.java b/src/test/java/org/ballerinalang/completion/BallerinaCompletionTest.java index 370ea8dc..98164e4b 100644 --- a/src/test/java/org/ballerinalang/completion/BallerinaCompletionTest.java +++ b/src/test/java/org/ballerinalang/completion/BallerinaCompletionTest.java @@ -25,204 +25,10 @@ public class BallerinaCompletionTest extends BallerinaCompletionTestBase { - private static final List FILE_LEVEL_KEYWORDS = Arrays.asList("public", "package", "import", "const", - "service", "function", "connector", "struct", "typemapper", "annotation", "enum"); - private static final List DATA_TYPES = Arrays.asList("boolean", "int", "float", "string", "blob"); - private static final List REFERENCE_TYPES = Arrays.asList("message", "map", "xml", "json", "datatable"); - private static final List XMLNS_TYPE = Collections.singletonList("xmlns"); - private static final List OTHER_TYPES = Arrays.asList("any", "type", "var"); - private static final List COMMON_KEYWORDS = Arrays.asList("if", "else", "fork", "join", "timeout", - "worker", "transform", "transaction", "failed", "aborted", "committed", "abort", "try", "catch", "finally", - "iterate", "while", "next", "break", "throw"); - private static final List VALUE_KEYWORDS = Arrays.asList("true", "false", "null"); - private static final List FUNCTION_LEVEL_KEYWORDS = Collections.singletonList("return"); - private static final String UTILS_PACKAGE_NAME = "org/test/utils.bal"; private static final String SAMPLE_UTIL_FUNCTIONS = "package org.test; public function getA(){} public function " + "getB(){}"; - @Override - protected String getTestDataPath() { - return getTestDataPath("completion"); - } - - /** - * Test file level lookups. - */ - public void testEmptyFile() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(FILE_LEVEL_KEYWORDS); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testEmptyFilePackageKeyword() { - doTest("p", "public", "import", "package", "typemapper", "map", "type"); - } - - public void testEmptyFileImportKeyword() { - doTest("i", "public", "annotation", "function", "import", "service", "int", "string"); - } - - public void testEmptyFileWithSpaceBeforeCaret() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(FILE_LEVEL_KEYWORDS); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("\n", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testEmptyFileWithSpaceBeforeCaretPackageKeyword() { - doTest("\np", "public", "import", "package", "typemapper", "map", "type"); - } - - public void testEmptyFileWithSpaceBeforeCaretImportKeyword() { - doTest("\ni", "public", "annotation", "function", "import", "service", "int", "string"); - } - - public void testEmptyFileWithSpaceAfterCaret() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(FILE_LEVEL_KEYWORDS); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("\n", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testEmptyFileWithSpaceAfterCaretPackageKeyword() { - doTest("p\n", "public", "import", "package", "typemapper", "map", "type"); - } - - public void testEmptyFileWithSpaceAfterCaretImportKeyword() { - doTest("i\n", "public", "annotation", "function", "import", "service", "int", "string"); - } - - public void testEmptyFileWithSpaces() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(FILE_LEVEL_KEYWORDS); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("\n\n", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testEmptyFileWithSpacesPackageKeyword() { - doTest("\np\n", "public", "import", "package", "typemapper", "map", "type"); - } - - public void testEmptyFileWithSpacesImportKeyword() { - doTest("\ni\n", "public", "annotation", "function", "import", "service", "int", "string"); - } - - public void testImportAfterPackage() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.add("public"); - expectedLookups.add("import"); - expectedLookups.add("const"); - expectedLookups.add("service"); - expectedLookups.add("function"); - expectedLookups.add("connector"); - expectedLookups.add("struct"); - expectedLookups.add("typemapper"); - expectedLookups.add("annotation"); - expectedLookups.add("enum"); - doTest("package test; \n\n", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testImportAfterPackagePartialIdentifier() { - doTest("package test; \ni\n", "public", "annotation", "function", "import", "service", "int", "string"); - } - - public void testImportAfterPackageBeforeFunction() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.add("public"); - expectedLookups.add("import"); - expectedLookups.add("const"); - expectedLookups.add("service"); - expectedLookups.add("function"); - expectedLookups.add("connector"); - expectedLookups.add("struct"); - expectedLookups.add("typemapper"); - expectedLookups.add("annotation"); - expectedLookups.add("enum"); - doTest("package test; \n\nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testImportAfterPackageBeforeFunctionPartialIdentifier() { - doTest("package test; \ni\nfunction A(){}", "public", "annotation", "function", "import", "service", - "int", "string"); - } - - public void testPackageBeforeImport() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(FILE_LEVEL_KEYWORDS); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("\nimport test; \nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testPackageBeforeImportPartialIdentifier() { - doTest("p\nimport test; \nfunction A(){}", "public", "import", "package", "typemapper", "map", "type"); - } - - public void testImportBeforeImport() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(FILE_LEVEL_KEYWORDS); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("\nimport test; \nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testImportBeforeImportPartialIdentifier() { - doTest("i\nimport test; \nfunction A(){}", "public", "annotation", "function", "import", "service", - "int", "string"); - } - - public void testImportAfterImport() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.add("public"); - expectedLookups.add("import"); - expectedLookups.add("const"); - expectedLookups.add("service"); - expectedLookups.add("function"); - expectedLookups.add("connector"); - expectedLookups.add("struct"); - expectedLookups.add("typemapper"); - expectedLookups.add("annotation"); - expectedLookups.add("enum"); - expectedLookups.add("test"); - myFixture.addFileToProject("test/file.bal", "string s = \"\";"); - doTest("import test; \n \nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testImportAfterImportPartialIdentifier() { - doTest("import test; \ni \nfunction A(){}", "public", "annotation", "function", "import", "service", - "int", "string"); - } - /** * Test package declaration level lookups. */ @@ -269,86 +75,6 @@ public void testLastLevelImportAutoCompletion() { doCheckResult("test.bal", "import org.t", "import org.test;", null); } - /** - * Test constant declaration level lookups. - */ - public void testConstTypes() { - doTest("const ", DATA_TYPES.toArray(new String[DATA_TYPES.size()])); - } - - public void testConstIdentifier() { - doTest("const boolean "); - } - - public void testConstValues() { - doTest("const string NAME = ", "true", "false", "null"); - } - - public void testConstantAnnotation() { - doCheckResult("test.bal", "@ const string S=\"\";", null, '@'); - } - - public void testConstantAnnotationWithImports() { - myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); - doCheckResult("test.bal", "import org.test; const string S=\"\";", null, '@', "test"); - } - - public void testConstantAnnotationWithImportsNoAnnotationDefinitions() { - myFixture.addFileToProject("org/test/file.bal", "function test(){}"); - doCheckResult("test.bal", "import org.test; @test const string S=\"\";", null, ':'); - } - - public void testConstantAnnotationWithImportsWithNoMatchingAnnotationDefinitions() { - myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach service {}"); - doCheckResult("test.bal", "import org.test; @test: const string S=\"\";", null, null); - } - - public void testConstantAnnotationWithImportsWithMatchingAnnotationDefinitions() { - myFixture.addFileToProject("org/test/file.bal", "package org.test; public annotation TEST attach const {} " + - "annotation TEST2 attach resource {}"); - doCheckResult("test.bal", "import org.test; @test: const string S=\"\";", null, null, "TEST"); - } - - public void testConstantAnnotationWithImportsWithMatchingAnnotationDefinitionsAutoCompletion() { - myFixture.addFileToProject("org/test/file.bal", "package org.test; public annotation TEST attach const {}"); - doCheckResult("test.bal", "import org.test; @test:T const string S=\"\";", - "import org.test; @test:TEST {} const string S=\"\";", null); - } - - public void testConstantAnnotationInCurrentPackageSameFile() { - doCheckResult("test.bal", "annotation TEST attach const {} const string S=\"\";", null, '@', - "TEST"); - } - - public void testConstantAnnotationInCurrentPackageSameFileAutoComplete() { - doCheckResult("test.bal", "annotation TEST attach const {} @T const string S=\"\";", - "annotation TEST attach const {} @TEST {} const string S=\"\";", null); - } - - public void testConstantAnnotationInCurrentPackageDifferentFile() { - myFixture.addFileToProject("file.bal", "annotation TEST attach const {}"); - doCheckResult("test.bal", " const string S=\"\";", null, '@', "TEST"); - } - - public void testConstantAnnotationInCurrentPackageDifferentFileAutoComplete() { - myFixture.addFileToProject("file.bal", "annotation TEST attach function {}"); - doCheckResult("test.bal", "@T function A(){}", "@TEST {} function A(){}", null); - } - - public void testConstantAnnotationInCurrentPackageDifferentFileHasMoreDefinitionsAfter() { - myFixture.addFileToProject("file.bal", "annotation TEST attach const {}"); - doCheckResult("test.bal", " const string S=\"\"; service R{}", null, '@', "TEST"); - } - - public void testConstantAnnotationInCurrentPackageSameFileHasMoreDefinitionsAfter() { - doCheckResult("test.bal", "annotation TEST attach const {} const string S=\"\"; service R{}", null, '@', - "TEST"); - } - - public void testConstantTypesBeforeGlobalVarDef() { - doTest("const \n string test =\"\";", DATA_TYPES.toArray(new String[DATA_TYPES.size()])); - } - /** * Test annotation level lookups. */ @@ -407,82 +133,6 @@ public void testAnnotationFieldValuesFromDifferentPackage() { doTest("import org.test; @test:TEST{key:} function A(){}", "true", "false", "null"); } - /** - * Test global variables. - */ - public void testGlobalVariableIdentifier() { - doTest("string "); - } - - public void testGlobalVariableFunctionValue() { - doCheckResult("test.bal", "string test = g function getValue()(string){return \"\";}", - "string test = getValue() function getValue()(string){return \"\";}", null); - } - - public void testGlobalVariablePackageValue() { - myFixture.addFileToProject("org/test/file.bal", "function getValue()(string){return \"\";}"); - doTest("import org.test; string s = ", "test", "true", "false", "null"); - } - - public void testGlobalVariablePackageValueCompletion() { - myFixture.addFileToProject("org/test/file.bal", "function getValue()(string){return \"\";}"); - doCheckResult("test.bal", "import org.test; string s = te ", "import org.test; string s = test: ", - null); - } - - public void testGlobalVariablePackageValueDifferentPackage() { - myFixture.addFileToProject("org/test/file.bal", "public function getValue()(string){return \"\";}"); - doTest("import org.test; string s = test: ", "getValue"); - } - - public void testGlobalVariablePackageValueCompletionDifferentPackage() { - myFixture.addFileToProject("org/test/file.bal", "public function getValue()(string){return \"\";}"); - doCheckResult("test.bal", "import org.test; string s = test:g ", - "import org.test; string s = test:getValue() ", null); - } - - public void testGlobalVariablePackageValueDifferentFile() { - myFixture.addFileToProject("file.bal", "function getValue()(string){return \"\";}"); - doTest("string s = ", "getValue", "true", "false", "null"); - } - - public void testGlobalVariablePackageValueDifferentFileCompletion() { - myFixture.addFileToProject("file.bal", "function getValue()(string){return \"\";}"); - doCheckResult("test.bal", "string s = g", "string s = getValue()", null); - } - - public void testGlobalVariableInSamePackageSameFile() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.addAll(COMMON_KEYWORDS); - expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS); - expectedLookups.add("S"); - expectedLookups.add("F"); - doTest("string S=\"\"; function F(){ }", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testGlobalVariableInSamePackageDifferentFile() { - myFixture.addFileToProject("file.bal", "string S=\"\";"); - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.addAll(COMMON_KEYWORDS); - expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS); - expectedLookups.add("S"); - expectedLookups.add("F"); - doTest("function F(){ }", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testGlobalVariableInDifferentPackage() { - myFixture.addFileToProject("org/test/file.bal", "string S=\"\";"); - doTest("import org.test; function F(){ test: }", "S"); - } - /** * Test function level lookups. */ @@ -1044,120 +694,6 @@ public void testStrings() { doTest("function test() { int a; system:println(\"\") }"); } - /** - * Test function parameter level lookups. - */ - public void testFunctionParamIdentifier() { - doTest("function test(string )"); - } - - public void testFunctionParamWithoutImports() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("function test()", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testFunctionParamWithImports() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.add("test"); - myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); - doTest("import org.test; function B()", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testFunctionParamWithoutImportsAutoCompletion() { - doCheckResult("test.bal", "function test(st)", "function test(string )", null); - } - - public void testFunctionParamWithImportsAutoCompletion() { - myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); - doCheckResult("test.bal", "import org.test; function B(te)", - "import org.test; function B(test:)", null); - } - - public void testCaretAfterFunctionParamWithoutImports() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("function test(string s,)", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testCaretBeforeFunctionParamWithoutImports() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - doTest("function test(string s)", expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testCaretAfterFunctionParamWithImports() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.add("test"); - myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); - doTest("import org.test; function test(string s,)", - expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testCaretBeforeFunctionParamWithImports() { - List expectedLookups = new LinkedList<>(); - expectedLookups.addAll(DATA_TYPES); - expectedLookups.addAll(OTHER_TYPES); - expectedLookups.addAll(XMLNS_TYPE); - expectedLookups.addAll(REFERENCE_TYPES); - expectedLookups.add("test"); - myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); - doTest("import org.test; function test(string s)", - expectedLookups.toArray(new String[expectedLookups.size()])); - } - - public void testParamAnnotationsPackage() { - myFixture.addFileToProject("org/test/file.bal", "annotation TEST attach parameter {}"); - doTest("import org.test; function A(@)", "test"); - } - - public void testParamAnnotationsPackageAutoCompletion() { - myFixture.addFileToProject("org/test/file.bal", "annotation TEST attach parameter {}"); - doCheckResult("test.bal", "import org.test; function A(@te)", - "import org.test; function A(@test:)", null); - } - - public void testParamAnnotationsFromAPackage() { - myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach parameter {}"); - doTest("import org.test; function A(@test:)", "TEST"); - } - - public void testParamAnnotationsFromAPackageAutoCompletion() { - myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach parameter {}"); - doCheckResult("test.bal", "import org.test; function A(@test:T)", - "import org.test; function A(@test:TEST {})", null); - } - - public void testPackageInvocationInParameter() { - myFixture.addFileToProject("org/test/file.bal", "public struct test {}"); - doTest("import org.test; function A(test:)", "test"); - } - - public void testPackageInvocationInParameterAutoCompletion() { - myFixture.addFileToProject("org/test/file.bal", "public struct test {}"); - doCheckResult("test.bal", "import org.test; function A(test:t)", - "import org.test; function A(test:test )", null); - } - - // todo - query param annotations - /** * Test service level lookups. */ @@ -1761,98 +1297,6 @@ public void testTypeMapperAnnotationInCurrentPackageSameFileHasMoreDefinitionsAf "service R{}", null, '@', "TEST"); } - /** - * Hidden templates. - */ - public void testPackageKeyword() { - doCheckResult("test.bal", "package", "package ", null); - } - - public void testImportKeyword() { - doCheckResult("test.bal", "import", "import ", null); - } - - public void testIfKeyword() { - doCheckResult("test.bal", "function test(){ if }", "function test(){ if () {\n \n} }", null); - } - - public void testElseKeyword() { - doCheckResult("test.bal", "function test(){ else }", "function test(){ else {\n \n} }", null); - } - - public void testForkKeyword() { - doCheckResult("test.bal", "function test(){ fork }", "function test(){ fork {\n \n} }", null); - } - - public void testJoinKeyword() { - doCheckResult("test.bal", "function test(){ join }", "function test(){ join () () {\n \n}" + - " }", null); - } - - public void testTimeoutKeyword() { - doCheckResult("test.bal", "function test(){ timeout }", "function test(){ timeout () () " + - "{\n \n} }", null); - } - - public void testWorkerKeyword() { - doCheckResult("test.bal", "function test(){ worker }", "function test(){ worker {\n \n} }", - null); - } - - public void testTransformKeyword() { - doCheckResult("test.bal", "function test(){ transform }", "function test(){ transform {\n \n} }", - null); - } - - public void testTransactionKeyword() { - doCheckResult("test.bal", "function test(){ transaction }", "function test(){ transaction {\n \n} " + - "}", null); - } - - public void testAbortedKeyword() { - doCheckResult("test.bal", "function test(){ aborted }", "function test(){ aborted {\n \n} }", null); - } - - public void testCommittedKeyword() { - doCheckResult("test.bal", "function test(){ committed }", "function test(){ committed {\n \n} }", - null); - } - - public void testTryKeyword() { - doCheckResult("test.bal", "function test(){ try }", "function test(){ try {\n \n} }", null); - } - - public void testCatchKeyword() { - doCheckResult("test.bal", "function test(){ catch }", "function test(){ catch () {\n \n} }", - null); - } - - public void testFinallyKeyword() { - doCheckResult("test.bal", "function test(){ finally }", "function test(){ finally {\n \n} }", null); - } - - public void testIterateKeyword() { - doCheckResult("test.bal", "function test(){ iterate }", "function test(){ iterate ( : ) {\n \n} }", - null); - } - - public void testWhileKeyword() { - doCheckResult("test.bal", "function test(){ while }", "function test(){ while () {\n \n} }", - null); - } - - public void testContinueKeyword() { - doCheckResult("test.bal", "function test(){ next }", "function test(){ next; }", null); - } - - public void testBreakKeyword() { - doCheckResult("test.bal", "function test(){ break }", "function test(){ break; }", null); - } - - public void testThrowKeyword() { - doCheckResult("test.bal", "function test(){ throw }", "function test(){ throw ; }", null); - } - /** * Keywords in statements. */ diff --git a/src/test/java/org/ballerinalang/completion/BallerinaCompletionTestBase.java b/src/test/java/org/ballerinalang/completion/BallerinaCompletionTestBase.java index 4af3e14b..8511098c 100644 --- a/src/test/java/org/ballerinalang/completion/BallerinaCompletionTestBase.java +++ b/src/test/java/org/ballerinalang/completion/BallerinaCompletionTestBase.java @@ -22,10 +22,33 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; +import java.util.Collections; import java.util.List; public abstract class BallerinaCompletionTestBase extends BallerinaCodeInsightFixtureTestCase { + static final List FILE_LEVEL_KEYWORDS = Arrays.asList("public", "package", "import", "const", + "service", "function", "connector", "struct", "typemapper", "annotation", "enum"); + static final List DATA_TYPES = Arrays.asList("boolean", "int", "float", "string", "blob"); + static final List REFERENCE_TYPES = Arrays.asList("message", "map", "xml", "json", "datatable"); + static final List XMLNS_TYPE = Collections.singletonList("xmlns"); + static final List OTHER_TYPES = Arrays.asList("any", "type", "var"); + static final List COMMON_KEYWORDS = Arrays.asList("if", "else", "fork", "join", "timeout", + "worker", "transform", "transaction", "failed", "aborted", "committed", "abort", "try", "catch", "finally", + "iterate", "while", "next", "break", "throw"); + static final List VALUE_KEYWORDS = Arrays.asList("true", "false", "null"); + static final List FUNCTION_LEVEL_KEYWORDS = Collections.singletonList("return"); + + void doTestFile(String... expectedLookups) { + String testName = getTestName(false); + myFixture.configureByFile(testName + ".bal"); + myFixture.complete(CompletionType.BASIC, 1); + List lookupElementStrings = myFixture.getLookupElementStrings(); + assertNotNull(lookupElementStrings); + assertSameElements(lookupElementStrings, expectedLookups); + } + void doTest(String fileContent, String... expectedLookups) { if (fileContent != null) { myFixture.configureByText("test.bal", fileContent); diff --git a/src/test/java/org/ballerinalang/completion/BallerinaConstantCompletionTest.java b/src/test/java/org/ballerinalang/completion/BallerinaConstantCompletionTest.java new file mode 100644 index 00000000..2652fc07 --- /dev/null +++ b/src/test/java/org/ballerinalang/completion/BallerinaConstantCompletionTest.java @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.ballerinalang.completion; + +import java.util.LinkedList; +import java.util.List; + +public class BallerinaConstantCompletionTest extends BallerinaCompletionTestBase { + + /** + * Test constants. + */ + public void testConstTypes() { + doTest("const ", DATA_TYPES.toArray(new String[DATA_TYPES.size()])); + } + + public void testConstIdentifier() { + doTest("const boolean "); + } + + public void testConstValues() { + doTest("const string NAME = ", "true", "false", "null"); + } + + public void testConstantAnnotation() { + doCheckResult("test.bal", "@ const string S=\"\";", null, '@'); + } + + public void testConstantAnnotationWithImports() { + myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); + doCheckResult("test.bal", "import org.test; const string S=\"\";", null, '@', "test"); + } + + public void testConstantAnnotationWithImportsNoAnnotationDefinitions() { + myFixture.addFileToProject("org/test/file.bal", "function test(){}"); + doCheckResult("test.bal", "import org.test; @test const string S=\"\";", null, ':'); + } + + public void testConstantAnnotationWithImportsWithNoMatchingAnnotationDefinitions() { + myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach service {}"); + doCheckResult("test.bal", "import org.test; @test: const string S=\"\";", null, null); + } + + public void testConstantAnnotationWithImportsWithMatchingAnnotationDefinitions() { + myFixture.addFileToProject("org/test/file.bal", "package org.test; public annotation TEST attach const {} " + + "annotation TEST2 attach resource {}"); + doCheckResult("test.bal", "import org.test; @test: const string S=\"\";", null, null, "TEST"); + } + + public void testConstantAnnotationWithImportsWithMatchingAnnotationDefinitionsAutoCompletion() { + myFixture.addFileToProject("org/test/file.bal", "package org.test; public annotation TEST attach const {}"); + doCheckResult("test.bal", "import org.test; @test:T const string S=\"\";", + "import org.test; @test:TEST {} const string S=\"\";", null); + } + + public void testConstantAnnotationInCurrentPackageSameFile() { + doCheckResult("test.bal", "annotation TEST attach const {} const string S=\"\";", null, '@', + "TEST"); + } + + public void testConstantAnnotationInCurrentPackageSameFileAutoComplete() { + doCheckResult("test.bal", "annotation TEST attach const {} @T const string S=\"\";", + "annotation TEST attach const {} @TEST {} const string S=\"\";", null); + } + + public void testConstantAnnotationInCurrentPackageDifferentFile() { + myFixture.addFileToProject("file.bal", "annotation TEST attach const {}"); + doCheckResult("test.bal", " const string S=\"\";", null, '@', "TEST"); + } + + public void testConstantAnnotationInCurrentPackageDifferentFileAutoComplete() { + myFixture.addFileToProject("file.bal", "annotation TEST attach function {}"); + doCheckResult("test.bal", "@T function A(){}", "@TEST {} function A(){}", null); + } + + public void testConstantAnnotationInCurrentPackageDifferentFileHasMoreDefinitionsAfter() { + myFixture.addFileToProject("file.bal", "annotation TEST attach const {}"); + doCheckResult("test.bal", " const string S=\"\"; service R{}", null, '@', "TEST"); + } + + public void testConstantAnnotationInCurrentPackageSameFileHasMoreDefinitionsAfter() { + doCheckResult("test.bal", "annotation TEST attach const {} const string S=\"\"; service R{}", null, '@', + "TEST"); + } + + public void testConstantTypesBeforeGlobalVarDef() { + doTest("const \n string test =\"\";", DATA_TYPES.toArray(new String[DATA_TYPES.size()])); + } + + public void testConstantInSamePackageSameFile() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.addAll(COMMON_KEYWORDS); + expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS); + expectedLookups.add("S"); + expectedLookups.add("F"); + doTest("string S=\"\"; function F(){ }", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testConstantInSamePackageDifferentFile() { + myFixture.addFileToProject("file.bal", "const string S=\"\";"); + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.addAll(COMMON_KEYWORDS); + expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS); + expectedLookups.add("S"); + expectedLookups.add("F"); + doTest("function F(){ }", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testConstantInDifferentPackage() { + myFixture.addFileToProject("org/test/file.bal", "public const string S=\"\";"); + doTest("import org.test; function F(){ test: }", "S"); + } + + public void testConstantInDifferentPackageImportedAsAlias() { + myFixture.addFileToProject("org/test/file.bal", "cont string S=\"\";"); + doTest("import org.test as utils; function F(){ utils: }", "S"); + } +} diff --git a/src/test/java/org/ballerinalang/completion/BallerinaFileLevelCompletionTest.java b/src/test/java/org/ballerinalang/completion/BallerinaFileLevelCompletionTest.java new file mode 100644 index 00000000..183219f6 --- /dev/null +++ b/src/test/java/org/ballerinalang/completion/BallerinaFileLevelCompletionTest.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.ballerinalang.completion; + +import java.util.LinkedList; +import java.util.List; + +public class BallerinaFileLevelCompletionTest extends BallerinaCompletionTestBase { + + /** + * Test file level lookups. + */ + public void testEmptyFile() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(FILE_LEVEL_KEYWORDS); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testEmptyFilePackageKeyword() { + doTest("p", "public", "import", "package", "typemapper", "map", "type"); + } + + public void testEmptyFileImportKeyword() { + doTest("i", "public", "annotation", "function", "import", "service", "int", "string"); + } + + public void testEmptyFileWithSpaceBeforeCaret() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(FILE_LEVEL_KEYWORDS); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("\n", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testEmptyFileWithSpaceBeforeCaretPackageKeyword() { + doTest("\np", "public", "import", "package", "typemapper", "map", "type"); + } + + public void testEmptyFileWithSpaceBeforeCaretImportKeyword() { + doTest("\ni", "public", "annotation", "function", "import", "service", "int", "string"); + } + + public void testEmptyFileWithSpaceAfterCaret() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(FILE_LEVEL_KEYWORDS); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("\n", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testEmptyFileWithSpaceAfterCaretPackageKeyword() { + doTest("p\n", "public", "import", "package", "typemapper", "map", "type"); + } + + public void testEmptyFileWithSpaceAfterCaretImportKeyword() { + doTest("i\n", "public", "annotation", "function", "import", "service", "int", "string"); + } + + public void testEmptyFileWithSpaces() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(FILE_LEVEL_KEYWORDS); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("\n\n", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testEmptyFileWithSpacesPackageKeyword() { + doTest("\np\n", "public", "import", "package", "typemapper", "map", "type"); + } + + public void testEmptyFileWithSpacesImportKeyword() { + doTest("\ni\n", "public", "annotation", "function", "import", "service", "int", "string"); + } + + public void testImportAfterPackage() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.add("public"); + expectedLookups.add("import"); + expectedLookups.add("const"); + expectedLookups.add("service"); + expectedLookups.add("function"); + expectedLookups.add("connector"); + expectedLookups.add("struct"); + expectedLookups.add("typemapper"); + expectedLookups.add("annotation"); + expectedLookups.add("enum"); + doTest("package test; \n\n", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testImportAfterPackagePartialIdentifier() { + doTest("package test; \ni\n", "public", "annotation", "function", "import", "service", "int", "string"); + } + + public void testImportAfterPackageBeforeFunction() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.add("public"); + expectedLookups.add("import"); + expectedLookups.add("const"); + expectedLookups.add("service"); + expectedLookups.add("function"); + expectedLookups.add("connector"); + expectedLookups.add("struct"); + expectedLookups.add("typemapper"); + expectedLookups.add("annotation"); + expectedLookups.add("enum"); + doTest("package test; \n\nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testImportAfterPackageBeforeFunctionPartialIdentifier() { + doTest("package test; \ni\nfunction A(){}", "public", "annotation", "function", "import", "service", + "int", "string"); + } + + public void testPackageBeforeImport() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(FILE_LEVEL_KEYWORDS); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("\nimport test; \nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testPackageBeforeImportPartialIdentifier() { + doTest("p\nimport test; \nfunction A(){}", "public", "import", "package", "typemapper", "map", "type"); + } + + public void testImportBeforeImport() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(FILE_LEVEL_KEYWORDS); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("\nimport test; \nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testImportBeforeImportPartialIdentifier() { + doTest("i\nimport test; \nfunction A(){}", "public", "annotation", "function", "import", "service", + "int", "string"); + } + + public void testImportAfterImport() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.add("public"); + expectedLookups.add("import"); + expectedLookups.add("const"); + expectedLookups.add("service"); + expectedLookups.add("function"); + expectedLookups.add("connector"); + expectedLookups.add("struct"); + expectedLookups.add("typemapper"); + expectedLookups.add("annotation"); + expectedLookups.add("enum"); + expectedLookups.add("test"); + myFixture.addFileToProject("test/file.bal", "string s = \"\";"); + doTest("import test; \n \nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testImportAfterImportPartialIdentifier() { + doTest("import test; \ni \nfunction A(){}", "public", "annotation", "function", "import", "service", + "int", "string"); + } +} diff --git a/src/test/java/org/ballerinalang/completion/BallerinaGlobalVariableCompletionTest.java b/src/test/java/org/ballerinalang/completion/BallerinaGlobalVariableCompletionTest.java new file mode 100644 index 00000000..748bfb5b --- /dev/null +++ b/src/test/java/org/ballerinalang/completion/BallerinaGlobalVariableCompletionTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.ballerinalang.completion; + +import java.util.LinkedList; +import java.util.List; + +public class BallerinaGlobalVariableCompletionTest extends BallerinaCompletionTestBase { + + /** + * Test global variables. + */ + public void testGlobalVariableIdentifier() { + doTest("string "); + } + + public void testGlobalVariableFunctionValue() { + doCheckResult("test.bal", "string test = g function getValue()(string){return \"\";}", + "string test = getValue() function getValue()(string){return \"\";}", null); + } + + public void testGlobalVariablePackageValue() { + myFixture.addFileToProject("org/test/file.bal", "function getValue()(string){return \"\";}"); + doTest("import org.test; string s = ", "test", "true", "false", "null"); + } + + public void testGlobalVariablePackageValueCompletion() { + myFixture.addFileToProject("org/test/file.bal", "function getValue()(string){return \"\";}"); + doCheckResult("test.bal", "import org.test; string s = te ", "import org.test; string s = test: ", + null); + } + + public void testGlobalVariablePackageValueDifferentPackage() { + myFixture.addFileToProject("org/test/file.bal", "public function getValue()(string){return \"\";}"); + doTest("import org.test; string s = test: ", "getValue"); + } + + public void testGlobalVariablePackageValueCompletionDifferentPackage() { + myFixture.addFileToProject("org/test/file.bal", "public function getValue()(string){return \"\";}"); + doCheckResult("test.bal", "import org.test; string s = test:g ", + "import org.test; string s = test:getValue() ", null); + } + + public void testGlobalVariablePackageValueDifferentFile() { + myFixture.addFileToProject("file.bal", "function getValue()(string){return \"\";}"); + doTest("string s = ", "getValue", "true", "false", "null"); + } + + public void testGlobalVariablePackageValueDifferentFileCompletion() { + myFixture.addFileToProject("file.bal", "function getValue()(string){return \"\";}"); + doCheckResult("test.bal", "string s = g", "string s = getValue()", null); + } + + public void testGlobalVariableInSamePackageSameFile() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.addAll(COMMON_KEYWORDS); + expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS); + expectedLookups.add("S"); + expectedLookups.add("F"); + doTest("string S=\"\"; function F(){ }", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testGlobalVariableInSamePackageDifferentFile() { + myFixture.addFileToProject("file.bal", "string S=\"\";"); + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.addAll(COMMON_KEYWORDS); + expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS); + expectedLookups.add("S"); + expectedLookups.add("F"); + doTest("function F(){ }", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testGlobalVariableInDifferentPackage() { + myFixture.addFileToProject("org/test/file.bal", "string S=\"\";"); + doTest("import org.test; function F(){ test: }", "S"); + } + + public void testGlobalVariableInDifferentPackageImportedAsAlias() { + myFixture.addFileToProject("org/test/file.bal", "string S=\"\";"); + doTest("import org.test as utils; function F(){ utils: }", "S"); + } +} diff --git a/src/test/java/org/ballerinalang/completion/BallerinaHiddenTemplateCompletionTest.java b/src/test/java/org/ballerinalang/completion/BallerinaHiddenTemplateCompletionTest.java new file mode 100644 index 00000000..d5539e68 --- /dev/null +++ b/src/test/java/org/ballerinalang/completion/BallerinaHiddenTemplateCompletionTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.ballerinalang.completion; + +public class BallerinaHiddenTemplateCompletionTest extends BallerinaCompletionTestBase { + + /** + * Hidden templates. + */ + public void testPackageKeyword() { + doCheckResult("test.bal", "package", "package ", null); + } + + public void testImportKeyword() { + doCheckResult("test.bal", "import", "import ", null); + } + + public void testIfKeyword() { + doCheckResult("test.bal", "function test(){ if }", "function test(){ if () {\n \n} }", null); + } + + public void testElseKeyword() { + doCheckResult("test.bal", "function test(){ else }", "function test(){ else {\n \n} }", null); + } + + public void testForkKeyword() { + doCheckResult("test.bal", "function test(){ fork }", "function test(){ fork {\n \n} }", null); + } + + public void testJoinKeyword() { + doCheckResult("test.bal", "function test(){ join }", "function test(){ join () () {\n \n}" + + " }", null); + } + + public void testTimeoutKeyword() { + doCheckResult("test.bal", "function test(){ timeout }", "function test(){ timeout () () " + + "{\n \n} }", null); + } + + public void testWorkerKeyword() { + doCheckResult("test.bal", "function test(){ worker }", "function test(){ worker {\n \n} }", + null); + } + + public void testTransformKeyword() { + doCheckResult("test.bal", "function test(){ transform }", "function test(){ transform {\n \n} }", + null); + } + + public void testTransactionKeyword() { + doCheckResult("test.bal", "function test(){ transaction }", "function test(){ transaction {\n \n} " + + "}", null); + } + + public void testAbortedKeyword() { + doCheckResult("test.bal", "function test(){ aborted }", "function test(){ aborted {\n \n} }", null); + } + + public void testCommittedKeyword() { + doCheckResult("test.bal", "function test(){ committed }", "function test(){ committed {\n \n} }", + null); + } + + public void testTryKeyword() { + doCheckResult("test.bal", "function test(){ try }", "function test(){ try {\n \n} }", null); + } + + public void testCatchKeyword() { + doCheckResult("test.bal", "function test(){ catch }", "function test(){ catch () {\n \n} }", + null); + } + + public void testFinallyKeyword() { + doCheckResult("test.bal", "function test(){ finally }", "function test(){ finally {\n \n} }", null); + } + + public void testIterateKeyword() { + doCheckResult("test.bal", "function test(){ iterate }", "function test(){ iterate ( : ) {\n \n} }", + null); + } + + public void testWhileKeyword() { + doCheckResult("test.bal", "function test(){ while }", "function test(){ while () {\n \n} }", + null); + } + + public void testContinueKeyword() { + doCheckResult("test.bal", "function test(){ next }", "function test(){ next; }", null); + } + + public void testBreakKeyword() { + doCheckResult("test.bal", "function test(){ break }", "function test(){ break; }", null); + } + + public void testThrowKeyword() { + doCheckResult("test.bal", "function test(){ throw }", "function test(){ throw ; }", null); + } +} diff --git a/src/test/java/org/ballerinalang/completion/BallerinaParameterCompletionTest.java b/src/test/java/org/ballerinalang/completion/BallerinaParameterCompletionTest.java new file mode 100644 index 00000000..c265b025 --- /dev/null +++ b/src/test/java/org/ballerinalang/completion/BallerinaParameterCompletionTest.java @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.ballerinalang.completion; + +import java.util.LinkedList; +import java.util.List; + +public class BallerinaParameterCompletionTest extends BallerinaCompletionTestBase { + + /** + * Test parameters. + */ + public void testFunctionParamIdentifier() { + doTest("function test(string )"); + } + + public void testFunctionParamWithoutImports() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("function test()", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testFunctionParamWithImports() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.add("test"); + myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); + doTest("import org.test; function B()", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testFunctionParamWithoutImportsAutoCompletion() { + doCheckResult("test.bal", "function test(st)", "function test(string )", null); + } + + public void testFunctionParamWithImportsAutoCompletion() { + myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); + doCheckResult("test.bal", "import org.test; function B(te)", + "import org.test; function B(test:)", null); + } + + public void testCaretAfterFunctionParamWithoutImports() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("function test(string s,)", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testCaretBeforeFunctionParamWithoutImports() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + doTest("function test(string s)", expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testCaretAfterFunctionParamWithImports() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.add("test"); + myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); + doTest("import org.test; function test(string s,)", + expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testCaretBeforeFunctionParamWithImports() { + List expectedLookups = new LinkedList<>(); + expectedLookups.addAll(DATA_TYPES); + expectedLookups.addAll(OTHER_TYPES); + expectedLookups.addAll(XMLNS_TYPE); + expectedLookups.addAll(REFERENCE_TYPES); + expectedLookups.add("test"); + myFixture.addFileToProject("org/test/file.bal", "string s = \"\";"); + doTest("import org.test; function test(string s)", + expectedLookups.toArray(new String[expectedLookups.size()])); + } + + public void testParamAnnotationsPackage() { + myFixture.addFileToProject("org/test/file.bal", "annotation TEST attach parameter {}"); + doTest("import org.test; function A(@)", "test"); + } + + public void testParamAnnotationsPackageAutoCompletion() { + myFixture.addFileToProject("org/test/file.bal", "annotation TEST attach parameter {}"); + doCheckResult("test.bal", "import org.test; function A(@te)", + "import org.test; function A(@test:)", null); + } + + public void testParamAnnotationsFromAPackage() { + myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach parameter {}"); + doTest("import org.test; function A(@test:)", "TEST"); + } + + public void testParamAnnotationsFromAPackageAutoCompletion() { + myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach parameter {}"); + doCheckResult("test.bal", "import org.test; function A(@test:T)", + "import org.test; function A(@test:TEST {})", null); + } + + public void testPackageInvocationInParameter() { + myFixture.addFileToProject("org/test/file.bal", "public struct test {}"); + doTest("import org.test; function A(test:)", "test"); + } + + public void testPackageInvocationInParameterAutoCompletion() { + myFixture.addFileToProject("org/test/file.bal", "public struct test {}"); + doCheckResult("test.bal", "import org.test; function A(test:t)", + "import org.test; function A(test:test )", null); + } +} diff --git a/src/test/java/org/ballerinalang/completion/BallerinaStructFieldCompletionTest.java b/src/test/java/org/ballerinalang/completion/BallerinaStructFieldCompletionTest.java new file mode 100644 index 00000000..ec9e59f1 --- /dev/null +++ b/src/test/java/org/ballerinalang/completion/BallerinaStructFieldCompletionTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.ballerinalang.completion; + +public class BallerinaStructFieldCompletionTest extends BallerinaCompletionTestBase { + + @Override + protected String getTestDataPath() { + return getTestDataPath("completion/structFields"); + } + + public void testStructAsFunctionNamedReturn() { + doTestFile("name", "age"); + } + + public void testStructAsFunctionNamedReturnVarAssignment() { + doTestFile("name", "age"); + } + + public void testStructAsFunctionReturnParam() { + doTestFile("name", "age"); + } + + public void testStructAsFunctionReturnParamVarAssignment() { + doTestFile("name", "age"); + } + + public void testStructAsNamedReturn() { + doTestFile("name", "age"); + } + + public void testStructAsNamedReturn2() { + doTestFile("name", "age"); + } + + public void testStructAsNamedReturnPartialField() { + doTestFile("name", "age"); + } + + public void testStructAsParam() { + doTestFile("name", "age"); + } + + public void testStructAsParam2() { + doTestFile("name", "age"); + } + + public void testStructDeclarationReassigningAsVar() { + doTestFile("name", "age"); + } + + public void testStructDeclarationReassigningAsVar2() { + doTestFile("name", "age"); + } + + public void testStructVarReassigningAsVar() { + doTestFile("name", "age"); + } + + public void testStructVarReassigningAsVar2() { + doTestFile("name", "age"); + } +} diff --git a/src/test/resources/testData/completion/structFields/StructAsFunctionNamedReturn.bal b/src/test/resources/testData/completion/structFields/StructAsFunctionNamedReturn.bal new file mode 100644 index 00000000..d564b951 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsFunctionNamedReturn.bal @@ -0,0 +1,14 @@ +struct User { + string name; + int age; +} + +function getUser (string name, int age) (User user) { + user = {name:name, age:age}; + return; +} + +function main (string[] args) { + User user = getUser("Ballerina", 1); + user. +} diff --git a/src/test/resources/testData/completion/structFields/StructAsFunctionNamedReturnVarAssignment.bal b/src/test/resources/testData/completion/structFields/StructAsFunctionNamedReturnVarAssignment.bal new file mode 100644 index 00000000..afca3e1b --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsFunctionNamedReturnVarAssignment.bal @@ -0,0 +1,14 @@ +struct User { + string name; + int age; +} + +function getUser (string name, int age) (User user) { + user = {name:name, age:age}; + return; +} + +function main (string[] args) { + var user = getUser("Ballerina", 1); + user. +} diff --git a/src/test/resources/testData/completion/structFields/StructAsFunctionReturnParam.bal b/src/test/resources/testData/completion/structFields/StructAsFunctionReturnParam.bal new file mode 100644 index 00000000..ff7acc39 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsFunctionReturnParam.bal @@ -0,0 +1,14 @@ +struct User { + string name; + int age; +} + +function getUser (string name, int age) (User) { + User user = {name:name, age:age}; + return user; +} + +function main (string[] args) { + User user = getUser("Ballerina", 1); + user. +} diff --git a/src/test/resources/testData/completion/structFields/StructAsFunctionReturnParamVarAssignment.bal b/src/test/resources/testData/completion/structFields/StructAsFunctionReturnParamVarAssignment.bal new file mode 100644 index 00000000..a02d5153 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsFunctionReturnParamVarAssignment.bal @@ -0,0 +1,14 @@ +struct User { + string name; + int age; +} + +function getUser (string name, int age) (User) { + User user = {name:name, age:age}; + return user; +} + +function main (string[] args) { + var user = getUser("Ballerina", 1); + user. +} diff --git a/src/test/resources/testData/completion/structFields/StructAsNamedReturn.bal b/src/test/resources/testData/completion/structFields/StructAsNamedReturn.bal new file mode 100644 index 00000000..bd186df6 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsNamedReturn.bal @@ -0,0 +1,8 @@ +struct User { + string name; + int age; +} + +function test () (User user) { + user. +} diff --git a/src/test/resources/testData/completion/structFields/StructAsNamedReturn2.bal b/src/test/resources/testData/completion/structFields/StructAsNamedReturn2.bal new file mode 100644 index 00000000..5762dbc1 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsNamedReturn2.bal @@ -0,0 +1,8 @@ +struct User { + string name; + int age; +} + +function test () (User user) { + user = {}; +} diff --git a/src/test/resources/testData/completion/structFields/StructAsNamedReturnPartialField.bal b/src/test/resources/testData/completion/structFields/StructAsNamedReturnPartialField.bal new file mode 100644 index 00000000..4159c8ea --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsNamedReturnPartialField.bal @@ -0,0 +1,8 @@ +struct User { + string name; + int age; +} + +function test () (User user) { + user.a +} diff --git a/src/test/resources/testData/completion/structFields/StructAsParam.bal b/src/test/resources/testData/completion/structFields/StructAsParam.bal new file mode 100644 index 00000000..7e8a5d88 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsParam.bal @@ -0,0 +1,8 @@ +struct User { + string name; + int age; +} + +function test (User user) { + user. +} diff --git a/src/test/resources/testData/completion/structFields/StructAsParam2.bal b/src/test/resources/testData/completion/structFields/StructAsParam2.bal new file mode 100644 index 00000000..08004efb --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructAsParam2.bal @@ -0,0 +1,8 @@ +struct User { + string name; + int age; +} + +function test (User user) { + user = {}; +} diff --git a/src/test/resources/testData/completion/structFields/StructDeclarationReassigningAsVar.bal b/src/test/resources/testData/completion/structFields/StructDeclarationReassigningAsVar.bal new file mode 100644 index 00000000..f9286dcd --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructDeclarationReassigningAsVar.bal @@ -0,0 +1,10 @@ +struct User { + string name; + int age; +} + +function main (string[] args) { + User user = {}; + var temp = user; + temp. +} diff --git a/src/test/resources/testData/completion/structFields/StructDeclarationReassigningAsVar2.bal b/src/test/resources/testData/completion/structFields/StructDeclarationReassigningAsVar2.bal new file mode 100644 index 00000000..3e93d939 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructDeclarationReassigningAsVar2.bal @@ -0,0 +1,11 @@ +struct User { + string name; + int age; +} + +function main (string[] args) { + User user = {}; + var temp = user; + var temp2 = temp; + temp2. +} diff --git a/src/test/resources/testData/completion/structFields/StructVarReassigningAsVar.bal b/src/test/resources/testData/completion/structFields/StructVarReassigningAsVar.bal new file mode 100644 index 00000000..2bbee927 --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructVarReassigningAsVar.bal @@ -0,0 +1,15 @@ +struct User { + string name; + int age; +} + +function getUser (string name, int age) (User user) { + user = {name:name, age:age}; + return; +} + +function main (string[] args) { + var user = getUser("Ballerina", 1); + var temp = user; + temp. +} diff --git a/src/test/resources/testData/completion/structFields/StructVarReassigningAsVar2.bal b/src/test/resources/testData/completion/structFields/StructVarReassigningAsVar2.bal new file mode 100644 index 00000000..f7986e1a --- /dev/null +++ b/src/test/resources/testData/completion/structFields/StructVarReassigningAsVar2.bal @@ -0,0 +1,16 @@ +struct User { + string name; + int age; +} + +function getUser (string name, int age) (User user) { + user = {name:name, age:age}; + return; +} + +function main (string[] args) { + var user = getUser("Ballerina", 1); + var temp = user; + var temp2 = temp; + temp2. +}