Search in sources :

Example 66 with BInteger

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");
}
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 67 with BInteger

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");
}
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 68 with BInteger

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");
}
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 69 with BInteger

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");
}
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 70 with BInteger

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");
}
Also used : BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

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