Search in sources :

Example 61 with BString

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

the class StringTest method testReplace.

@Test
public void testReplace() {
    BValue[] args = { new BString("Best Company is Google"), new BString("Google"), new BString("WSO2") };
    BValue[] returns = BRunUtil.invoke(result, "replace", args);
    Assert.assertTrue(returns[0] instanceof BString);
    Assert.assertEquals(returns[0].stringValue(), "Best Company is WSO2");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 62 with BString

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

the class StringTest method testLength.

@Test
public void testLength() {
    BValue[] args = { new BString("Bandwagon") };
    BValue[] returns = BRunUtil.invoke(result, "length", args);
    Assert.assertTrue(returns[0] instanceof BInteger);
    Assert.assertEquals(((BInteger) returns[0]).intValue(), 9);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 63 with BString

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

the class StringTest method testSubString.

@Test
public void testSubString() {
    BValue[] args = { new BString("testValues"), new BInteger(0), new BInteger(9) };
    BValue[] returns = BRunUtil.invoke(result, "subString", args);
    Assert.assertTrue(returns[0] instanceof BString);
    Assert.assertEquals(returns[0].stringValue(), "testValue");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 64 with BString

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

the class StringTest method testTrimNull.

@Test(expectedExceptions = { BLangRuntimeException.class }, expectedExceptionsMessageRegExp = ".*error:.*NullReferenceException.*")
public void testTrimNull() {
    BValue[] args = { new BString(null) };
    BValue[] returns = BRunUtil.invoke(result, "trim", args);
    Assert.assertTrue(returns[0] instanceof BString);
    Assert.assertEquals(returns[0].stringValue(), "This is a String");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 65 with BString

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

the class StringTest method testToBlob.

@Test
public void testToBlob() throws UnsupportedEncodingException {
    String content = "Sample Content";
    BValue[] args = { new BString(content), new BString("UTF-8") };
    BValue[] returns = BRunUtil.invoke(result, "toBlob", args);
    Assert.assertEquals(((BBlob) returns[0]).blobValue(), content.getBytes("UTF-8"), "Produced Blob value is wrong");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Aggregations

BString (org.ballerinalang.model.values.BString)418 BValue (org.ballerinalang.model.values.BValue)339 Test (org.testng.annotations.Test)321 BInteger (org.ballerinalang.model.values.BInteger)77 BStruct (org.ballerinalang.model.values.BStruct)76 BMap (org.ballerinalang.model.values.BMap)37 BBoolean (org.ballerinalang.model.values.BBoolean)36 BFloat (org.ballerinalang.model.values.BFloat)34 BJSON (org.ballerinalang.model.values.BJSON)28 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)21 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)18 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)11 CompileResult (org.ballerinalang.launcher.util.CompileResult)11 BBlob (org.ballerinalang.model.values.BBlob)11 BStringArray (org.ballerinalang.model.values.BStringArray)11 BType (org.ballerinalang.model.types.BType)10 BIntArray (org.ballerinalang.model.values.BIntArray)9 BRefType (org.ballerinalang.model.values.BRefType)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7