Search in sources :

Example 31 with BRefValueArray

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

the class SystemTest method testFormatStringWithPadding.

@Test
public void testFormatStringWithPadding() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BString("Hello Ballerina"));
    BValue[] args = { new BString("%9.2s"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "       He");
}
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 32 with BRefValueArray

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

the class SystemTest method testFormatFloat.

@Test
public void testFormatFloat() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BFloat(3.25));
    BValue[] args = { new BString("%f"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "3.250000");
}
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 33 with BRefValueArray

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

the class SystemTest method testFormatDecimalWithPadding.

@Test
public void testFormatDecimalWithPadding() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BInteger(12345));
    BValue[] args = { new BString("%15d"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "          12345");
}
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 34 with BRefValueArray

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

the class SystemTest method testFormatString.

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

Example 35 with BRefValueArray

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

the class SystemTest method testFormatOctal.

@Test
public void testFormatOctal() {
    BRefValueArray fArgs = new BRefValueArray();
    fArgs.add(0, new BInteger(57005));
    BValue[] args = { new BString("%o"), fArgs };
    BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
    Assert.assertEquals(returns[0].stringValue(), "157255");
}
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)

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