Search in sources :

Example 61 with BRefValueArray

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

the class SystemTest method testFormatLiteralPercentChar.

@Test
public void testFormatLiteralPercentChar() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BString("test"));
    BValue[] args = { new BString("%% %s"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "% test");
}
Also used : BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) Test(org.testng.annotations.Test)

Example 62 with BRefValueArray

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

the class SystemTest method testFormatFloatWithPadding.

@Test
public void testFormatFloatWithPadding() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BFloat(123456789.9876543));
    BValue[] args = { new BString("%5.4f"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "123456789.9877");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BFloat(org.ballerinalang.model.values.BFloat) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) Test(org.testng.annotations.Test)

Example 63 with BRefValueArray

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

the class SystemTest method testFormatHex.

@Test
public void testFormatHex() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BInteger(57005));
    BValue[] args = { new BString("%x"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "dead");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) Test(org.testng.annotations.Test)

Example 64 with BRefValueArray

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

the class SystemTest method testFormatBinary.

@Test
public void testFormatBinary() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BInteger(12345));
    BValue[] args = { new BString("%B"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "11000000111001");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) Test(org.testng.annotations.Test)

Example 65 with BRefValueArray

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

the class NativeConversionTest method testJsonToAnyArray.

@Test(description = "Test converting a JSON array to any array")
public void testJsonToAnyArray() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testJsonToAnyArray");
    Assert.assertTrue(returns[0] instanceof BStruct);
    BStruct anyArrayStruct = (BStruct) returns[0];
    BRefValueArray array = (BRefValueArray) anyArrayStruct.getRefField(0);
    Assert.assertEquals(((BInteger) array.get(0)).intValue(), 4);
    Assert.assertEquals(array.get(1).stringValue(), "Supun");
    Assert.assertEquals(((BFloat) array.get(2)).floatValue(), 5.36);
    Assert.assertEquals(((BBoolean) array.get(3)).booleanValue(), true);
    Assert.assertEquals(((BJSON) array.get(4)).stringValue(), "{\"lname\":\"Setunga\"}");
    Assert.assertEquals(((BJSON) array.get(5)).stringValue(), "[4,3,7]");
    Assert.assertEquals(array.get(6), null);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) Test(org.testng.annotations.Test)

Aggregations

BRefValueArray (org.ballerinalang.model.values.BRefValueArray)83 BValue (org.ballerinalang.model.values.BValue)45 Test (org.testng.annotations.Test)40 BStruct (org.ballerinalang.model.values.BStruct)37 BString (org.ballerinalang.model.values.BString)22 BInteger (org.ballerinalang.model.values.BInteger)18 BXMLSequence (org.ballerinalang.model.values.BXMLSequence)9 BeforeTest (org.testng.annotations.BeforeTest)9 BIntArray (org.ballerinalang.model.values.BIntArray)7 BMap (org.ballerinalang.model.values.BMap)7 BStringArray (org.ballerinalang.model.values.BStringArray)7 BXML (org.ballerinalang.model.values.BXML)7 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)7 HashMap (java.util.HashMap)6 BStructType (org.ballerinalang.model.types.BStructType)6 BRefType (org.ballerinalang.model.values.BRefType)5 SQLDatasource (org.ballerinalang.nativeimpl.actions.data.sql.SQLDatasource)5 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)4 BFloatArray (org.ballerinalang.model.values.BFloatArray)4 IOException (java.io.IOException)3