use of org.ballerinalang.model.values.BInteger 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");
}
use of org.ballerinalang.model.values.BInteger 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");
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class SystemTest method testFormatDecimal.
@Test
public void testFormatDecimal() {
BRefValueArray fArgs = new BRefValueArray();
fArgs.add(0, new BInteger(65));
BValue[] args = { new BString("%d"), fArgs };
BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
Assert.assertEquals(returns[0].stringValue(), "65");
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class IOTest method testWriteBytes.
@Test(description = "Test 'writeBytes' function in ballerina.io package")
public void testWriteBytes() {
byte[] content = { -1, 46, 77, 90, 38 };
String sourceToWrite = currentDirectoryPath + "/bytesFile.txt";
// Will initialize the channel
BValue[] args = { new BString(sourceToWrite), new BString("w") };
BRunUtil.invoke(bytesInputOutputProgramFile, "initFileChannel", args);
args = new BValue[] { new BBlob(content), new BInteger(0) };
BRunUtil.invoke(bytesInputOutputProgramFile, "writeBytes", args);
BRunUtil.invoke(bytesInputOutputProgramFile, "close");
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class IOTest method testReadCharacters.
@Test(description = "Test 'readCharacters' function in ballerina.io package")
public void testReadCharacters() throws URISyntaxException {
String resourceToRead = "datafiles/io/text/utf8file.txt";
int numberOfCharactersToRead = 3;
BString readCharacters;
// Will initialize the channel
BValue[] args = { new BString(getAbsoluteFilePath(resourceToRead)), new BString("r"), new BString("UTF-8") };
BRunUtil.invoke(characterInputOutputProgramFile, "initCharacterChannel", args);
String expectedCharacters = "aaa";
args = new BValue[] { new BInteger(numberOfCharactersToRead) };
BValue[] returns = BRunUtil.invoke(characterInputOutputProgramFile, "readCharacters", args);
readCharacters = (BString) returns[0];
Assert.assertEquals(readCharacters.stringValue(), expectedCharacters);
expectedCharacters = "bbNJ";
args = new BValue[] { new BInteger(numberOfCharactersToRead) };
returns = BRunUtil.invoke(characterInputOutputProgramFile, "readCharacters", args);
readCharacters = (BString) returns[0];
Assert.assertEquals(readCharacters.stringValue(), expectedCharacters);
expectedCharacters = "";
args = new BValue[] { new BInteger(numberOfCharactersToRead) };
returns = BRunUtil.invoke(characterInputOutputProgramFile, "readCharacters", args);
readCharacters = (BString) returns[0];
Assert.assertEquals(readCharacters.stringValue(), expectedCharacters);
BRunUtil.invoke(characterInputOutputProgramFile, "close");
}
Aggregations