Search in sources :

Example 66 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class DocumentationTest method testNestedInline.

@Test(description = "Test doc nested inline.")
public void testNestedInline() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/nested_inline.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangVariable constant = (BLangVariable) packageNode.getGlobalVariables().get(0);
    List<BLangDocumentation> docNodes = constant.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.getAttributes().size(), 0);
    Assert.assertEquals(dNode.documentationText, "\n" + "  Example of a string template:\n" + "  ``` This starts ends triple backtick  ``string s = string `hello {{name}}`;`` " + "ends triple backtick```\n" + "\n" + "  Example for an xml literal:\n" + "    ``xml x = xml `<{{tagName}}>hello</{{tagName}}>`;``\n");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Test(org.testng.annotations.Test)

Example 67 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class DocumentationTest method testDocService.

@Test(description = "Test doc service.", enabled = false)
public void testDocService() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/service.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangService service = (BLangService) packageNode.getServices().get(0);
    List<BLangDocumentation> docNodes = service.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
    dNode = service.getResources().get(0).docAttachments.get(0);
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.documentationText, "Check orderPizza resource. ");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
    dNode = service.getResources().get(1).docAttachments.get(0);
    Assert.assertEquals(dNode.documentationText, "Check status resource. ");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
}
Also used : BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 68 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class CustomFunctionTest method testDuplicateParameters.

@Test(description = "Test defining ballerina function with duplicate parameters")
public void testDuplicateParameters() {
    CompileResult compile = BCompileUtil.compile("test-src/functions/duplicate-parameters.bal");
    Assert.assertEquals(compile.getErrorCount(), 1);
    // Checking duplicate parameter definition in a function starting at 31st column
    BAssertUtil.validateError(compile, 0, "redeclared symbol 'param'", 1, 31);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 69 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class CustomFunctionTest method testDuplicateFunction.

@Test(description = "Test defining duplicate ballerina function")
public void testDuplicateFunction() {
    CompileResult compile = BCompileUtil.compile("test-src/functions/duplicate-function.bal");
    Assert.assertEquals(compile.getErrorCount(), 1);
    BAssertUtil.validateError(compile, 0, "redeclared symbol 'foobar'", 5, 1);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 70 with CompileResult

use of org.ballerinalang.launcher.util.CompileResult in project ballerina by ballerina-lang.

the class FunctionOverloadTest method testFunctionOverloadingSameArgCountTest.

@Test(description = "Test functino overloading which has same argument count")
public void testFunctionOverloadingSameArgCountTest() {
    CompileResult compile = BCompileUtil.compile("test-src/functions/function-overloading.bal");
    Assert.assertEquals(compile.getErrorCount(), 1);
    BAssertUtil.validateError(compile, 0, "redeclared symbol 'testOverloading'", 5, 1);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Aggregations

CompileResult (org.ballerinalang.launcher.util.CompileResult)291 Test (org.testng.annotations.Test)287 BValue (org.ballerinalang.model.values.BValue)60 PackageNode (org.ballerinalang.model.tree.PackageNode)16 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)14 BString (org.ballerinalang.model.values.BString)13 BInteger (org.ballerinalang.model.values.BInteger)12 Path (java.nio.file.Path)5 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 File (java.io.File)4 GrpcCmd (org.ballerinalang.protobuf.cmd.GrpcCmd)4 BStringArray (org.ballerinalang.model.values.BStringArray)3 BLangDeprecatedNode (org.wso2.ballerinalang.compiler.tree.BLangDeprecatedNode)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BFloat (org.ballerinalang.model.values.BFloat)2 BIntArray (org.ballerinalang.model.values.BIntArray)2 BMap (org.ballerinalang.model.values.BMap)2 BeforeTest (org.testng.annotations.BeforeTest)2 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)2