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");
}
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");
}
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");
}
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");
}
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);
}
Aggregations