Search in sources :

Example 81 with BInteger

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

the class ValueTypeCastExprTest method testStringToInt.

@Test
public void testStringToInt() {
    BValue[] args = { new BString("100") };
    BValue[] returns = BRunUtil.invoke(result, "stringToInt", args);
    Assert.assertTrue(returns[0] instanceof BInteger);
    final long expected = 100;
    Assert.assertEquals(((BInteger) returns[0]).intValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 82 with BInteger

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

the class LengthOfOperatorTest method testArrayLengthAccessJSONArrayNegativeNonArrayCase.

@Test(description = "Test lengthof unary expression when reference point to JSON Object.")
public void testArrayLengthAccessJSONArrayNegativeNonArrayCase() {
    BValue[] args = { new BInteger(100), new BInteger(5) };
    BValue[] returns = BRunUtil.invoke(result, "arrayLengthAccessTestJSONArrayNegativeNonArrayCase", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    int actual = (int) ((BInteger) returns[0]).intValue();
    int expected = -1;
    Assert.assertEquals(actual, expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 83 with BInteger

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

the class LengthOfOperatorTest method testArrayLengthAccessExprReturnExpressionCase.

@Test(description = "Test lengthof unary expression when present in Return statement.")
public void testArrayLengthAccessExprReturnExpressionCase() {
    BValue[] args = { new BInteger(100), new BInteger(5) };
    BValue[] returns = BRunUtil.invoke(result, "arrayLengthAccessTestReturnStatementCase", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    int actual = (int) ((BInteger) returns[0]).intValue();
    int expected = 3;
    Assert.assertEquals(actual, expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 84 with BInteger

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

the class LengthOfOperatorTest method testArrayLengthAccessExprMapInitializationCase.

@Test(description = "Test lengthof unary expression when present in Map initialization statement.")
public void testArrayLengthAccessExprMapInitializationCase() {
    BValue[] args = { new BInteger(100), new BInteger(5) };
    BValue[] returns = BRunUtil.invoke(result, "arrayLengthAccessTestMapInitializerCase", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    int actual = (int) ((BInteger) returns[0]).intValue();
    int expected = 3;
    Assert.assertEquals(actual, expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 85 with BInteger

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

the class LengthOfOperatorTest method testArrayLengthAccessExpArrayNullCase.

@Test(description = "Test lengthof unary expression when array is null.")
public void testArrayLengthAccessExpArrayNullCase() {
    BValue[] args = { new BInteger(100), new BInteger(5) };
    BRunUtil.invoke(resNegative, "arrayLengthAccessNullArrayCase", args);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Aggregations

BInteger (org.ballerinalang.model.values.BInteger)364 BValue (org.ballerinalang.model.values.BValue)324 Test (org.testng.annotations.Test)305 BString (org.ballerinalang.model.values.BString)91 BFloat (org.ballerinalang.model.values.BFloat)55 BStruct (org.ballerinalang.model.values.BStruct)33 BBoolean (org.ballerinalang.model.values.BBoolean)24 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)18 CompileResult (org.ballerinalang.launcher.util.CompileResult)12 BBlob (org.ballerinalang.model.values.BBlob)11 BeforeTest (org.testng.annotations.BeforeTest)11 BIntArray (org.ballerinalang.model.values.BIntArray)9 BMap (org.ballerinalang.model.values.BMap)9 BRefType (org.ballerinalang.model.values.BRefType)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)8 BType (org.ballerinalang.model.types.BType)6 BStructType (org.ballerinalang.model.types.BStructType)4 BJSON (org.ballerinalang.model.values.BJSON)4 UnsupportedFieldTypeException (org.ballerinalang.net.grpc.exception.UnsupportedFieldTypeException)4