Search in sources :

Example 26 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class SQLActionsTest method testBatchUpdateWithFailure.

@Test(groups = "ConnectorTest")
public void testBatchUpdateWithFailure() {
    BValue[] returns = BRunUtil.invoke(result, "testBatchUpdateWithFailure");
    BIntArray retValue = (BIntArray) returns[0];
    Assert.assertEquals(retValue.get(0), 1);
    Assert.assertEquals(retValue.get(1), 1);
    Assert.assertEquals(retValue.get(2), -3);
    Assert.assertEquals(retValue.get(3), -3);
    Assert.assertEquals(((BInteger) returns[1]).intValue(), 2);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 27 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class FunctionSignatureTest method testOptionalArgsInNativeFunc.

@Test(enabled = false)
public void testOptionalArgsInNativeFunc() {
    NativeElementRepository repo = NativeUnitLoader.getInstance().getNativeElementRepository();
    StandardNativeElementProvider provider = new StandardNativeElementProvider();
    provider.populateNatives(repo);
    CompileResult result = BCompileUtil.compile(this, "test-src/functions/", "foo.bar");
    BValue[] returns = BRunUtil.invoke(result, "testOptionalArgsInNativeFunc");
    Assert.assertTrue(returns[0] instanceof BInteger);
    Assert.assertEquals(((BInteger) returns[0]).intValue(), 78);
    Assert.assertTrue(returns[1] instanceof BFloat);
    Assert.assertEquals(((BFloat) returns[1]).floatValue(), 89.0);
    Assert.assertTrue(returns[2] instanceof BString);
    Assert.assertEquals(returns[2].stringValue(), "John");
    Assert.assertTrue(returns[3] instanceof BInteger);
    Assert.assertEquals(((BInteger) returns[3]).intValue(), 5);
    Assert.assertTrue(returns[4] instanceof BString);
    Assert.assertEquals(returns[4].stringValue(), "Doe");
    Assert.assertTrue(returns[5] instanceof BIntArray);
    Assert.assertEquals(returns[5].stringValue(), "[4, 5, 6]");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) StandardNativeElementProvider(org.ballerinalang.test.utils.mock.StandardNativeElementProvider) CompileResult(org.ballerinalang.launcher.util.CompileResult) NativeElementRepository(org.ballerinalang.natives.NativeElementRepository) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 28 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class NativeConversionTest method testJsonToIntArray.

@Test(description = "Test converting a JSON array to int array")
public void testJsonToIntArray() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testJsonToIntArray");
    Assert.assertTrue(returns[0] instanceof BStruct);
    BStruct anyArrayStruct = (BStruct) returns[0];
    BIntArray array = (BIntArray) anyArrayStruct.getRefField(0);
    Assert.assertEquals(array.getType().toString(), "int[]");
    Assert.assertEquals(array.get(0), 4);
    Assert.assertEquals(array.get(1), 3);
    Assert.assertEquals(array.get(2), 9);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 29 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class ArrayAccessExprTest method testArrayReturnValue.

@Test(description = "Test arrays return value")
public void testArrayReturnValue() {
    BValue[] args = { new BInteger(100), new BInteger(5) };
    BValue[] returns = BRunUtil.invoke(compileResult, "arrayReturnTest", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BIntArray.class);
    BIntArray arrayValue = (BIntArray) returns[0];
    Assert.assertEquals(arrayValue.size(), 106);
    Assert.assertEquals(arrayValue.get(0), 100);
    Assert.assertEquals(arrayValue.get(1), 5);
    Assert.assertEquals(arrayValue.get(105), 105);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 30 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class ArrayAccessExprTest method testArrayArgValue.

@Test(description = "Test arrays arg value")
public void testArrayArgValue() {
    BIntArray arrayValue = new BIntArray();
    arrayValue.add(0, 10);
    arrayValue.add(1, 1);
    BValue[] args = { arrayValue };
    BValue[] returns = BRunUtil.invoke(compileResult, "arrayArgTest", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    long actual = ((BInteger) returns[0]).intValue();
    long expected = 11;
    Assert.assertEquals(actual, expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Aggregations

BIntArray (org.ballerinalang.model.values.BIntArray)33 BValue (org.ballerinalang.model.values.BValue)25 Test (org.testng.annotations.Test)25 BString (org.ballerinalang.model.values.BString)14 BInteger (org.ballerinalang.model.values.BInteger)9 BStruct (org.ballerinalang.model.values.BStruct)9 BFloatArray (org.ballerinalang.model.values.BFloatArray)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)7 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)7 BJSON (org.ballerinalang.model.values.BJSON)6 BMap (org.ballerinalang.model.values.BMap)6 BBlobArray (org.ballerinalang.model.values.BBlobArray)4 BFloat (org.ballerinalang.model.values.BFloat)4 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 BRefType (org.ballerinalang.model.values.BRefType)3 CompileResult (org.ballerinalang.launcher.util.CompileResult)2 BMapType (org.ballerinalang.model.types.BMapType)2 BBoolean (org.ballerinalang.model.values.BBoolean)2 StructureType (org.ballerinalang.model.values.StructureType)2