Search in sources :

Example 71 with BInteger

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

the class IOTest method testWriteCharacters.

@Test(description = "Test 'writeCharacters' function in ballerina.io package")
public void testWriteCharacters() {
    String content = "The quick brown fox jumps over the lazy dog";
    String sourceToWrite = currentDirectoryPath + "/characterFile.txt";
    // Will initialize the channel
    BValue[] args = { new BString(sourceToWrite), new BString("w"), new BString("UTF-8") };
    BRunUtil.invoke(characterInputOutputProgramFile, "initCharacterChannel", args);
    args = new BValue[] { new BString(content), new BInteger(0) };
    BRunUtil.invoke(characterInputOutputProgramFile, "writeCharacters", args);
    BRunUtil.invoke(characterInputOutputProgramFile, "close");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 72 with BInteger

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

the class IOTest method testReadBytes.

@Test(description = "Test 'readBytes' function in ballerina.io package")
public void testReadBytes() throws URISyntaxException {
    int numberOfBytesToRead = 3;
    String resourceToRead = "datafiles/io/text/6charfile.txt";
    BBlob readBytes;
    // Will initialize the channel
    BValue[] args = { new BString(getAbsoluteFilePath(resourceToRead)), new BString("r") };
    BRunUtil.invoke(bytesInputOutputProgramFile, "initFileChannel", args);
    // Reads the 1st three bytes "123"
    byte[] expectedBytes = "123".getBytes();
    args = new BValue[] { new BInteger(numberOfBytesToRead) };
    BValue[] returns = BRunUtil.invoke(bytesInputOutputProgramFile, "readBytes", args);
    readBytes = (BBlob) returns[0];
    Assert.assertEquals(expectedBytes, readBytes.blobValue());
    // Reads the next three bytes "456"
    expectedBytes = "456".getBytes();
    args = new BValue[] { new BInteger(numberOfBytesToRead) };
    returns = BRunUtil.invoke(bytesInputOutputProgramFile, "readBytes", args);
    readBytes = (BBlob) returns[0];
    Assert.assertEquals(expectedBytes, readBytes.blobValue());
    // Request for a get, the bytes will be empty
    expectedBytes = new byte[0];
    args = new BValue[] { new BInteger(numberOfBytesToRead) };
    returns = BRunUtil.invoke(bytesInputOutputProgramFile, "readBytes", args);
    readBytes = (BBlob) returns[0];
    Assert.assertEquals(expectedBytes, readBytes.blobValue());
    BRunUtil.invoke(bytesInputOutputProgramFile, "close");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) BBlob(org.ballerinalang.model.values.BBlob) Test(org.testng.annotations.Test)

Example 73 with BInteger

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

the class TernaryExpressionTest method testInAssignment.

@Test
public void testInAssignment() {
    BValue[] args = { new BInteger(20) };
    BValue[] results = BRunUtil.invoke(compileResult, "test1", args);
    Assert.assertEquals(((BInteger) results[0]).intValue(), 15);
    args = new BValue[] { new BInteger(4) };
    results = BRunUtil.invoke(compileResult, "test1", args);
    Assert.assertEquals(((BInteger) results[0]).intValue(), 5);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 74 with BInteger

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

the class TernaryExpressionTest method testNestedTernary3.

@Test
public void testNestedTernary3() {
    BInteger[] args = { new BInteger(80) };
    BValue[] results = BRunUtil.invoke(compileResult, "testNestedTernary3", args);
    Assert.assertEquals(results[0].stringValue(), getNestedTernary3Value1(args[0].value()));
    Assert.assertEquals(results[1].stringValue(), getNestedTernary3Value2(args[0].value()));
    Assert.assertEquals(results[0].stringValue(), results[1].stringValue());
    args = new BInteger[] { new BInteger(35) };
    results = BRunUtil.invoke(compileResult, "testNestedTernary3", args);
    Assert.assertEquals(results[0].stringValue(), getNestedTernary3Value1(args[0].value()));
    Assert.assertEquals(results[1].stringValue(), getNestedTernary3Value2(args[0].value()));
    Assert.assertEquals(results[0].stringValue(), results[1].stringValue());
    args = new BInteger[] { new BInteger(25) };
    results = BRunUtil.invoke(compileResult, "testNestedTernary3", args);
    Assert.assertEquals(results[0].stringValue(), getNestedTernary3Value1(args[0].value()));
    Assert.assertEquals(results[1].stringValue(), getNestedTernary3Value2(args[0].value()));
    Assert.assertEquals(results[0].stringValue(), results[1].stringValue());
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 75 with BInteger

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

the class SimpleTypeCastExprTest method testIntToBooleanCast.

private void testIntToBooleanCast(int input, boolean excepted) {
    BValue[] args = { new BInteger(input) };
    BValue[] returns = BRunUtil.invoke(result, "intToBooleanExplicit", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertEquals(returns[0].getClass(), BBoolean.class);
    Assert.assertEquals(((BBoolean) returns[0]).booleanValue(), excepted);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger)

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