Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shan1024 committed Oct 18, 2017
1 parent bcbc35c commit 32c9c1a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@

public abstract class BallerinaCompletionTestBase extends BallerinaCodeInsightFixtureTestCase {

static final List<String> FILE_LEVEL_KEYWORDS = Arrays.asList("package", "import", "const", "service",
"function", "connector", "struct", "typemapper", "annotation");
static final List<String> FILE_LEVEL_KEYWORDS = Arrays.asList("public", "package", "import", "const",
"service", "function", "connector", "struct", "typemapper", "annotation", "enum");
static final List<String> DATA_TYPES = Arrays.asList("boolean", "int", "float", "string", "blob");
static final List<String> REFERENCE_TYPES = Arrays.asList("message", "map", "xml", "json", "datatable");
static final List<String> XMLNS_TYPE = Collections.singletonList("xmlns");
static final List<String> OTHER_TYPES = Arrays.asList("any", "type", "var");
static final List<String> COMMON_KEYWORDS = Arrays.asList("if", "else", "fork", "join", "timeout",
"worker", "transform", "transaction", "failed", "aborted", "committed", "abort", "try", "catch", "finally",
"iterate", "while", "continue", "break", "throw");
"iterate", "while", "next", "break", "throw");
static final List<String> VALUE_KEYWORDS = Arrays.asList("true", "false", "null");

static final List<String> FUNCTION_LEVEL_KEYWORDS = Collections.singletonList("return");

void doTestFile(String... expectedLookups) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ public void testConstantAnnotationWithImportsNoAnnotationDefinitions() {
}

public void testConstantAnnotationWithImportsWithNoMatchingAnnotationDefinitions() {
myFixture.addFileToProject("org/test/file.bal", "annotation TEST attach service {}");
myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach service {}");
doCheckResult("test.bal", "import org.test; @test:<caret> const string S=\"\";", null, null);
}

public void testConstantAnnotationWithImportsWithMatchingAnnotationDefinitions() {
myFixture.addFileToProject("org/test/file.bal", "package org.test; annotation TEST attach const {} " +
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:<caret> const string S=\"\";", null, null, "TEST");
}

public void testConstantAnnotationWithImportsWithMatchingAnnotationDefinitionsAutoCompletion() {
myFixture.addFileToProject("org/test/file.bal", "package org.test; annotation TEST attach const {}");
myFixture.addFileToProject("org/test/file.bal", "package org.test; public annotation TEST attach const {}");
doCheckResult("test.bal", "import org.test; @test:T<caret> const string S=\"\";",
"import org.test; @test:TEST {} const string S=\"\";", null);
}
Expand Down Expand Up @@ -108,12 +108,10 @@ public void testConstantInSamePackageSameFile() {
expectedLookups.addAll(XMLNS_TYPE);
expectedLookups.addAll(REFERENCE_TYPES);
expectedLookups.addAll(COMMON_KEYWORDS);
expectedLookups.addAll(VALUE_KEYWORDS);
expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS);
expectedLookups.add("S");
expectedLookups.add("F");
doTest("const string S=\"\"; function F(){ <caret> }",
expectedLookups.toArray(new String[expectedLookups.size()]));
doTest("string S=\"\"; function F(){ <caret> }", expectedLookups.toArray(new String[expectedLookups.size()]));
}

public void testConstantInSamePackageDifferentFile() {
Expand All @@ -124,15 +122,14 @@ public void testConstantInSamePackageDifferentFile() {
expectedLookups.addAll(XMLNS_TYPE);
expectedLookups.addAll(REFERENCE_TYPES);
expectedLookups.addAll(COMMON_KEYWORDS);
expectedLookups.addAll(VALUE_KEYWORDS);
expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS);
expectedLookups.add("S");
expectedLookups.add("F");
doTest("function F(){ <caret> }", expectedLookups.toArray(new String[expectedLookups.size()]));
}

public void testConstantInDifferentPackage() {
myFixture.addFileToProject("org/test/file.bal", "const string S=\"\";");
myFixture.addFileToProject("org/test/file.bal", "public const string S=\"\";");
doTest("import org.test; function F(){ test:<caret> }", "S");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public void testEmptyFile() {
}

public void testEmptyFilePackageKeyword() {
doTest("p<caret>", "import", "package", "typemapper", "map", "type");
doTest("p<caret>", "public", "import", "package", "typemapper", "map", "type");
}

public void testEmptyFileImportKeyword() {
doTest("i<caret>", "annotation", "function", "import", "service", "int", "string");
doTest("i<caret>", "public", "annotation", "function", "import", "service", "int", "string");
}

public void testEmptyFileWithSpaceBeforeCaret() {
Expand All @@ -53,11 +53,11 @@ public void testEmptyFileWithSpaceBeforeCaret() {
}

public void testEmptyFileWithSpaceBeforeCaretPackageKeyword() {
doTest("\np<caret>", "import", "package", "typemapper", "map", "type");
doTest("\np<caret>", "public", "import", "package", "typemapper", "map", "type");
}

public void testEmptyFileWithSpaceBeforeCaretImportKeyword() {
doTest("\ni<caret>", "annotation", "function", "import", "service", "int", "string");
doTest("\ni<caret>", "public", "annotation", "function", "import", "service", "int", "string");
}

public void testEmptyFileWithSpaceAfterCaret() {
Expand All @@ -71,11 +71,11 @@ public void testEmptyFileWithSpaceAfterCaret() {
}

public void testEmptyFileWithSpaceAfterCaretPackageKeyword() {
doTest("p<caret>\n", "import", "package", "typemapper", "map", "type");
doTest("p<caret>\n", "public", "import", "package", "typemapper", "map", "type");
}

public void testEmptyFileWithSpaceAfterCaretImportKeyword() {
doTest("i<caret>\n", "annotation", "function", "import", "service", "int", "string");
doTest("i<caret>\n", "public", "annotation", "function", "import", "service", "int", "string");
}

public void testEmptyFileWithSpaces() {
Expand All @@ -89,11 +89,11 @@ public void testEmptyFileWithSpaces() {
}

public void testEmptyFileWithSpacesPackageKeyword() {
doTest("\np<caret>\n", "import", "package", "typemapper", "map", "type");
doTest("\np<caret>\n", "public", "import", "package", "typemapper", "map", "type");
}

public void testEmptyFileWithSpacesImportKeyword() {
doTest("\ni<caret>\n", "annotation", "function", "import", "service", "int", "string");
doTest("\ni<caret>\n", "public", "annotation", "function", "import", "service", "int", "string");
}

public void testImportAfterPackage() {
Expand All @@ -102,6 +102,7 @@ public void testImportAfterPackage() {
expectedLookups.addAll(XMLNS_TYPE);
expectedLookups.addAll(DATA_TYPES);
expectedLookups.addAll(REFERENCE_TYPES);
expectedLookups.add("public");
expectedLookups.add("import");
expectedLookups.add("const");
expectedLookups.add("service");
Expand All @@ -110,11 +111,12 @@ public void testImportAfterPackage() {
expectedLookups.add("struct");
expectedLookups.add("typemapper");
expectedLookups.add("annotation");
expectedLookups.add("enum");
doTest("package test; \n<caret>\n", expectedLookups.toArray(new String[expectedLookups.size()]));
}

public void testImportAfterPackagePartialIdentifier() {
doTest("package test; \ni<caret>\n", "annotation", "function", "import", "service", "int", "string");
doTest("package test; \ni<caret>\n", "public", "annotation", "function", "import", "service", "int", "string");
}

public void testImportAfterPackageBeforeFunction() {
Expand All @@ -123,6 +125,7 @@ public void testImportAfterPackageBeforeFunction() {
expectedLookups.addAll(XMLNS_TYPE);
expectedLookups.addAll(DATA_TYPES);
expectedLookups.addAll(REFERENCE_TYPES);
expectedLookups.add("public");
expectedLookups.add("import");
expectedLookups.add("const");
expectedLookups.add("service");
Expand All @@ -131,12 +134,13 @@ public void testImportAfterPackageBeforeFunction() {
expectedLookups.add("struct");
expectedLookups.add("typemapper");
expectedLookups.add("annotation");
expectedLookups.add("enum");
doTest("package test; \n<caret>\nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()]));
}

public void testImportAfterPackageBeforeFunctionPartialIdentifier() {
doTest("package test; \ni<caret>\nfunction A(){}", "annotation", "function", "import", "service", "int",
"string");
doTest("package test; \ni<caret>\nfunction A(){}", "public", "annotation", "function", "import", "service",
"int", "string");
}

public void testPackageBeforeImport() {
Expand All @@ -150,7 +154,7 @@ public void testPackageBeforeImport() {
}

public void testPackageBeforeImportPartialIdentifier() {
doTest("p<caret>\nimport test; \nfunction A(){}", "import", "package", "typemapper", "map", "type");
doTest("p<caret>\nimport test; \nfunction A(){}", "public", "import", "package", "typemapper", "map", "type");
}

public void testImportBeforeImport() {
Expand All @@ -164,8 +168,8 @@ public void testImportBeforeImport() {
}

public void testImportBeforeImportPartialIdentifier() {
doTest("i<caret>\nimport test; \nfunction A(){}", "annotation", "function", "import", "service", "int",
"string");
doTest("i<caret>\nimport test; \nfunction A(){}", "public", "annotation", "function", "import", "service",
"int", "string");
}

public void testImportAfterImport() {
Expand All @@ -174,6 +178,7 @@ public void testImportAfterImport() {
expectedLookups.addAll(XMLNS_TYPE);
expectedLookups.addAll(DATA_TYPES);
expectedLookups.addAll(REFERENCE_TYPES);
expectedLookups.add("public");
expectedLookups.add("import");
expectedLookups.add("const");
expectedLookups.add("service");
Expand All @@ -182,13 +187,14 @@ public void testImportAfterImport() {
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<caret> \nfunction A(){}", expectedLookups.toArray(new String[expectedLookups.size()]));
}

public void testImportAfterImportPartialIdentifier() {
doTest("import test; \ni<caret> \nfunction A(){}", "annotation", "function", "import", "service", "int",
"string");
doTest("import test; \ni<caret> \nfunction A(){}", "public", "annotation", "function", "import", "service",
"int", "string");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public void testGlobalVariablePackageValueCompletion() {
}

public void testGlobalVariablePackageValueDifferentPackage() {
myFixture.addFileToProject("org/test/file.bal", "function getValue()(string){return \"\";}");
myFixture.addFileToProject("org/test/file.bal", "public function getValue()(string){return \"\";}");
doTest("import org.test; string s = test:<caret> ", "getValue");
}

public void testGlobalVariablePackageValueCompletionDifferentPackage() {
myFixture.addFileToProject("org/test/file.bal", "function getValue()(string){return \"\";}");
myFixture.addFileToProject("org/test/file.bal", "public function getValue()(string){return \"\";}");
doCheckResult("test.bal", "import org.test; string s = test:g<caret> ",
"import org.test; string s = test:getValue() ", null);
}
Expand All @@ -72,7 +72,6 @@ public void testGlobalVariableInSamePackageSameFile() {
expectedLookups.addAll(XMLNS_TYPE);
expectedLookups.addAll(REFERENCE_TYPES);
expectedLookups.addAll(COMMON_KEYWORDS);
expectedLookups.addAll(VALUE_KEYWORDS);
expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS);
expectedLookups.add("S");
expectedLookups.add("F");
Expand All @@ -87,7 +86,6 @@ public void testGlobalVariableInSamePackageDifferentFile() {
expectedLookups.addAll(XMLNS_TYPE);
expectedLookups.addAll(REFERENCE_TYPES);
expectedLookups.addAll(COMMON_KEYWORDS);
expectedLookups.addAll(VALUE_KEYWORDS);
expectedLookups.addAll(FUNCTION_LEVEL_KEYWORDS);
expectedLookups.add("S");
expectedLookups.add("F");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package org.ballerinalang.completion;

import java.util.LinkedList;
import java.util.List;

public class BallerinaHiddenTemplateCompletionTest extends BallerinaCompletionTestBase {

/**
Expand All @@ -45,12 +42,12 @@ public void testForkKeyword() {
}

public void testJoinKeyword() {
doCheckResult("test.bal", "function test(){ join<caret> }", "function test(){ join () (message[] ) {\n \n}" +
doCheckResult("test.bal", "function test(){ join<caret> }", "function test(){ join () () {\n \n}" +
" }", null);
}

public void testTimeoutKeyword() {
doCheckResult("test.bal", "function test(){ timeout<caret> }", "function test(){ timeout () (message[] ) " +
doCheckResult("test.bal", "function test(){ timeout<caret> }", "function test(){ timeout () () " +
"{\n \n} }", null);
}

Expand Down Expand Up @@ -102,7 +99,7 @@ public void testWhileKeyword() {
}

public void testContinueKeyword() {
doCheckResult("test.bal", "function test(){ continue<caret> }", "function test(){ continue; }", null);
doCheckResult("test.bal", "function test(){ next<caret> }", "function test(){ next; }", null);
}

public void testBreakKeyword() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ public void testParamAnnotationsPackageAutoCompletion() {
}

public void testParamAnnotationsFromAPackage() {
myFixture.addFileToProject("org/test/file.bal", "annotation TEST attach parameter {}");
myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach parameter {}");
doTest("import org.test; function A(@test:<caret>)", "TEST");
}

public void testParamAnnotationsFromAPackageAutoCompletion() {
myFixture.addFileToProject("org/test/file.bal", "annotation TEST attach parameter {}");
myFixture.addFileToProject("org/test/file.bal", "public annotation TEST attach parameter {}");
doCheckResult("test.bal", "import org.test; function A(@test:T<caret>)",
"import org.test; function A(@test:TEST {})", null);
}

public void testPackageInvocationInParameter() {
myFixture.addFileToProject("org/test/file.bal", "struct test {}");
myFixture.addFileToProject("org/test/file.bal", "public struct test {}");
doTest("import org.test; function A(test:<caret>)", "test");
}

public void testPackageInvocationInParameterAutoCompletion() {
myFixture.addFileToProject("org/test/file.bal", "struct test {}");
myFixture.addFileToProject("org/test/file.bal", "public struct test {}");
doCheckResult("test.bal", "import org.test; function A(test:t<caret>)",
"import org.test; function A(test:test )", null);
}
Expand Down

0 comments on commit 32c9c1a

Please sign in to comment.