Search in sources :

Example 46 with CompileResult

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

the class GlobalVarFunctionTest method testChangeGlobalVarWithinFunction.

@Test(description = "Test change global var within functions")
public void testChangeGlobalVarWithinFunction() {
    BValue[] args = { new BInteger(88) };
    BValue[] returns = BRunUtil.invoke(result, "changeGlobalVar", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    Assert.assertEquals(((BFloat) returns[0]).floatValue(), 165.0);
    CompileResult resultGlobalVar = BCompileUtil.compile("test-src/statements/variabledef/global-var-function.bal");
    BValue[] returnsChanged = BRunUtil.invoke(resultGlobalVar, "getGlobalFloatVar");
    Assert.assertEquals(returnsChanged.length, 1);
    Assert.assertSame(returnsChanged[0].getClass(), BFloat.class);
    Assert.assertEquals(((BFloat) returnsChanged[0]).floatValue(), 80.0);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 47 with CompileResult

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

the class StructEquivalencyNegativeTest method testEquivalenceOfStructsInSamePackage.

@Test(description = "Test equivalence of structs that are in the same package", enabled = false)
public void testEquivalenceOfStructsInSamePackage() {
    CompileResult compileResult = BCompileUtil.compile("test-src/structs/struct-equivalency-01-negative.bal");
    BAssertUtil.validateError(compileResult, 0, "unsafe cast from 'employee01' to 'person01', use multi-return cast expression", 17, 18);
    BAssertUtil.validateError(compileResult, 1, "unsafe cast from 'employee02' to 'person02', use multi-return cast expression", 36, 18);
    BAssertUtil.validateError(compileResult, 2, "unsafe cast from 'employee03' to 'person03', use multi-return cast expression", 54, 18);
    BAssertUtil.validateError(compileResult, 3, "unsafe cast from 'employee04' to 'person04', use multi-return cast expression", 76, 18);
    BAssertUtil.validateError(compileResult, 4, "unsafe cast from 'employee05' to 'person05', use multi-return cast expression", 100, 18);
    BAssertUtil.validateError(compileResult, 5, "unsafe cast from 'employee06' to 'person06', use multi-return cast expression", 122, 18);
    BAssertUtil.validateError(compileResult, 6, "unsafe cast from 'employee07' to 'person07', use multi-return cast expression", 166, 18);
    BAssertUtil.validateError(compileResult, 7, "unsafe cast from 'employee08' to 'person08', use multi-return cast expression", 214, 18);
    BAssertUtil.validateError(compileResult, 8, "unsafe cast from 'employee09' to 'person09', use multi-return cast expression", 262, 18);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 48 with CompileResult

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

the class StructEquivalencyNegativeTest method testEquivalenceOfStructsInSamePackageFromDifferentPackage.

@Test(description = "Test equivalence of structs that are in the same package from a third package", enabled = false)
public void testEquivalenceOfStructsInSamePackageFromDifferentPackage() {
    CompileResult compileResult = BCompileUtil.compile("test-src/structs/struct-equivalency-02-negative.bal");
    BAssertUtil.validateError(compileResult, 0, "unsafe cast from 'org.foo.bar:userBar' to 'org.foo:userFoo', " + "use multi-return cast expression", 11, 23);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 49 with CompileResult

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

the class StructInitializerTest method testInvalidStructLiteralKey.

@Test(description = "Test negative structs initializers scenarios")
public void testInvalidStructLiteralKey() {
    CompileResult result = BCompileUtil.compile(this, "test-src/structs", "init.negative");
    Assert.assertEquals(2, result.getErrorCount());
    BAssertUtil.validateError(result, 0, "explicit invocation of 'init.negative:person' struct initializer is not allowed", 24, 5);
    BAssertUtil.validateError(result, 1, "attempt to create a struct with a non-public initializer ", 28, 21);
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) Test(org.testng.annotations.Test)

Example 50 with CompileResult

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

the class StructNegativeTest method testGetNonInitField.

@Test(description = "Test accessing an field of a noninitialized struct", expectedExceptions = { BLangRuntimeException.class }, expectedExceptionsMessageRegExp = ".*error:.*array index out of range.*")
public void testGetNonInitField() {
    CompileResult compileResult = BCompileUtil.compile("test-src/structs/struct.bal");
    Assert.assertEquals(compileResult.getWarnCount(), 0);
    Assert.assertEquals(compileResult.getErrorCount(), 0);
    BRunUtil.invoke(compileResult, "testGetNonInitAttribute");
}
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