Search in sources :

Example 1 with BValueType

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

the class SystemTest method testBooleanPrintAndPrintln.

@Test
public void testBooleanPrintAndPrintln() throws IOException {
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(outContent));
        final boolean v1 = false;
        final boolean v2 = true;
        final String expected = v1 + "\n" + v2;
        BValueType[] args = { new BBoolean(v1), new BBoolean(v2) };
        BRunUtil.invoke(compileResult, printFuncName + "Boolean", args);
        Assert.assertEquals(outContent.toString().replace("\r", ""), expected);
    } finally {
        outContent.close();
        System.setOut(original);
    }
}
Also used : PrintStream(java.io.PrintStream) BValueType(org.ballerinalang.model.values.BValueType) BBoolean(org.ballerinalang.model.values.BBoolean) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 2 with BValueType

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

the class SystemTest method testFloatPrintAndPrintln.

@Test
public void testFloatPrintAndPrintln() throws IOException {
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(outContent));
        final float v1 = 1000;
        final float v2 = 1;
        final String expected = v1 + "\n" + v2;
        BValueType[] args = { new BFloat(v1), new BFloat(v2) };
        BRunUtil.invoke(compileResult, printFuncName + "Float", args);
        Assert.assertEquals(outContent.toString().replace("\r", ""), expected);
    } finally {
        outContent.close();
        System.setOut(original);
    }
}
Also used : PrintStream(java.io.PrintStream) BValueType(org.ballerinalang.model.values.BValueType) BFloat(org.ballerinalang.model.values.BFloat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 3 with BValueType

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

the class VariableDTO method getStringValue.

private String getStringValue(BValue bValue) {
    String bValueString;
    if (bValue instanceof BValueType || bValue instanceof BXML || bValue instanceof BJSON) {
        bValueString = bValue.stringValue();
    } else if (bValue instanceof BNewArray) {
        BNewArray bArray = (BNewArray) bValue;
        bValueString = "Array[" + bArray.size() + "] ";
        bValueString = bValueString + bArray.stringValue();
    } else if (bValue instanceof BMap) {
        BMap bmap = (BMap) bValue;
        bValueString = "Map[" + bmap.size() + "] ";
        bValueString = bValueString + bmap.stringValue();
    } else if (bValue instanceof BStruct) {
        BStruct bStruct = (BStruct) bValue;
        bValueString = "struct " + bStruct.getType().getName() + " ";
        bValueString = bValueString + bStruct.stringValue();
    } else {
        bValueString = "<Complex_Value>";
    }
    return bValueString;
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValueType(org.ballerinalang.model.values.BValueType) BNewArray(org.ballerinalang.model.values.BNewArray) BMap(org.ballerinalang.model.values.BMap) BXML(org.ballerinalang.model.values.BXML) BJSON(org.ballerinalang.model.values.BJSON)

Example 4 with BValueType

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

the class SystemTest method testIntPrintAndPrintln.

@Test
public void testIntPrintAndPrintln() throws IOException {
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(outContent));
        final int v1 = 1000;
        final int v2 = 1;
        final String expected = v1 + "\n" + v2;
        BValueType[] args = { new BInteger(v1), new BInteger(v2) };
        BRunUtil.invoke(compileResult, printFuncName + "Int", args);
        Assert.assertEquals(outContent.toString().replace("\r", ""), expected);
    } finally {
        outContent.close();
        System.setOut(original);
    }
}
Also used : PrintStream(java.io.PrintStream) BValueType(org.ballerinalang.model.values.BValueType) BInteger(org.ballerinalang.model.values.BInteger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 5 with BValueType

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

the class SystemTest method testStringPrintAndPrintln.

@Test
public void testStringPrintAndPrintln() throws IOException {
    ByteArrayOutputStream outContent = new ByteArrayOutputStream();
    try {
        System.setOut(new PrintStream(outContent));
        final String s1 = "Hello World...!!!";
        final String s2 = "A Greeting from Ballerina...!!!";
        final String expected = s1 + "\n" + s2;
        BValueType[] args = { new BString(s1), new BString(s2) };
        BRunUtil.invoke(compileResult, printFuncName + "String", args);
        Assert.assertEquals(outContent.toString().replace("\r", ""), expected);
    } finally {
        outContent.close();
        System.setOut(original);
    }
}
Also used : PrintStream(java.io.PrintStream) BValueType(org.ballerinalang.model.values.BValueType) BString(org.ballerinalang.model.values.BString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Aggregations

BValueType (org.ballerinalang.model.values.BValueType)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 PrintStream (java.io.PrintStream)4 BString (org.ballerinalang.model.values.BString)4 Test (org.testng.annotations.Test)4 BBoolean (org.ballerinalang.model.values.BBoolean)1 BFloat (org.ballerinalang.model.values.BFloat)1 BInteger (org.ballerinalang.model.values.BInteger)1 BJSON (org.ballerinalang.model.values.BJSON)1 BMap (org.ballerinalang.model.values.BMap)1 BNewArray (org.ballerinalang.model.values.BNewArray)1 BStruct (org.ballerinalang.model.values.BStruct)1 BXML (org.ballerinalang.model.values.BXML)1