Search in sources :

Example 56 with CompileResult

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

the class TypeCastExprTest method testIncompatibleStructToStructCast.

@Test
public void testIncompatibleStructToStructCast() {
    CompileResult res = BCompileUtil.compile("test-src/expressions/typecast/incompatible-struct-cast-negative.bal");
    Assert.assertEquals(res.getErrorCount(), 1);
    BAssertUtil.validateError(res, 0, "incompatible types: expected 'Person', found 'Student'", 24, 16);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 57 with CompileResult

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

the class TypeCastExprTest method testCastingWithTooManyReturns.

@Test(description = "Test casting with too many returns")
public void testCastingWithTooManyReturns() {
    CompileResult res = BCompileUtil.compile("test-src/expressions/typecast/cast-too-many-returns-negative.bal");
    Assert.assertEquals(res.getErrorCount(), 1);
    BAssertUtil.validateError(res, 0, "invalid token '=?'", 15, 15);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 58 with CompileResult

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

the class IdentifierLiteralPackageTest method testAccessingVarsInOtherPackage.

@Test(description = "Test accessing variable in other packages defined with identifier literal")
public void testAccessingVarsInOtherPackage() {
    CompileResult result = BCompileUtil.compile(this, "test-src/expressions/identifierliteral", "pkg.main");
    BValue[] returns = BRunUtil.invoke(result, "pkg.main", "getVarsInOtherPkg");
    Assert.assertEquals(returns.length, 4);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    Assert.assertSame(returns[1].getClass(), BString.class);
    Assert.assertSame(returns[2].getClass(), BFloat.class);
    Assert.assertSame(returns[3].getClass(), BInteger.class);
    Assert.assertEquals(((BInteger) returns[0]).intValue(), 800);
    Assert.assertEquals(((BString) returns[1]).stringValue(), "value");
    Assert.assertEquals(((BFloat) returns[2]).floatValue(), 99.34323);
    Assert.assertEquals(((BInteger) returns[3]).intValue(), 88343);
}
Also used : BValue(org.ballerinalang.model.values.BValue) CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 59 with CompileResult

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

the class BuiltinLoadingTest method testRedeclaredSymbols.

@Test
public void testRedeclaredSymbols() {
    CompileResult result = BCompileUtil.compile("test-src/natives/builtin-symbol-negative.bal");
    BAssertUtil.validateError(result, 0, "redeclared builtin symbol 'error'", 5, 1);
    BAssertUtil.validateError(result, 1, "function 'getMessage' defined on non-local type 'error'", 13, 11);
    BAssertUtil.validateError(result, 2, "redeclared builtin symbol 'error'", 10, 5);
    BAssertUtil.validateError(result, 3, "break cannot be used outside of a loop", 2, 5);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 60 with CompileResult

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

the class DocumentationTest method testDocConstant.

@Test(description = "Test doc constant.")
public void testDocConstant() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/constant.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangVariable) packageNode.getGlobalVariables().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for testConst constant\n");
    Assert.assertEquals(dNode.getAttributes().size(), 1);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "testConst");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " constant variable `testConst`");
}
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)

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