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