Search in sources :

Example 51 with BString

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

the class JSONTest method testParseNull.

@Test(description = "Get JSON null from a string")
public void testParseNull() {
    BValue[] args = { new BString("null") };
    BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
    Assert.assertTrue(returns[0] instanceof BJSON);
    Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.NULL);
    Assert.assertEquals(returns[0].stringValue(), "null");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 52 with BString

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

the class BMapValueTest method testBMapOrder.

@Test
public void testBMapOrder() {
    BMap<String, BRefType> map = new BMap<>();
    map.put(new String("Entry1"), new BString("foo"));
    map.put(new String("Entry2"), new BString("bar"));
    map.put(new String("Entry3"), new BString("foobar"));
    Set set = map.keySet();
    String[] ar = new String[3];
    Iterator itr = set.iterator();
    for (int i = 0; i < set.size(); i++) {
        ar[i] = itr.next().toString();
    }
    Assert.assertEquals(map.get(ar[0]).stringValue(), "foo");
    Assert.assertEquals(map.get(ar[1]).stringValue(), "bar");
    Assert.assertEquals(map.get(ar[2]).stringValue(), "foobar");
}
Also used : BRefType(org.ballerinalang.model.values.BRefType) Set(java.util.Set) BMap(org.ballerinalang.model.values.BMap) BString(org.ballerinalang.model.values.BString) Iterator(java.util.Iterator) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 53 with BString

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

the class BMapValueTest method testBMapClear.

@Test
public void testBMapClear() {
    BMap<BString, BInteger> map = new BMap<>();
    map.put(new BString("IS"), new BInteger(0));
    map.put(new BString("ESB"), new BInteger(1));
    map.put(new BString("APIM"), new BInteger(2));
    assertEquals(map.size(), 3);
    map.clear();
    assertEquals(map.size(), 0);
}
Also used : BMap(org.ballerinalang.model.values.BMap) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 54 with BString

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

the class BMapValueTest method testBMapToString.

@Test(description = "Testing convert map values to string")
public void testBMapToString() {
    BMap<String, BRefType> map = new BMap<>();
    map.put(new String("key1"), new BInteger(1));
    map.put(new String("key2"), new BString("foo"));
    map.put(new String("key3"), new BXMLItem("<bar>hello</bar>"));
    Assert.assertEquals(map.stringValue(), "{\"key1\":1, \"key2\":\"foo\", \"key3\":<bar>hello</bar>}");
}
Also used : BRefType(org.ballerinalang.model.values.BRefType) BXMLItem(org.ballerinalang.model.values.BXMLItem) BMap(org.ballerinalang.model.values.BMap) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 55 with BString

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

the class MapAccessExprTest method testArrayReturnValueTest.

@Test(description = "Test map return value")
public void testArrayReturnValueTest() {
    BValue[] args = { new BString("Chanaka"), new BString("Fernando") };
    BValue[] returns = BRunUtil.invoke(compileResult, "mapReturnTest", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BMap.class);
    BMap mapValue = (BMap) returns[0];
    Assert.assertEquals(mapValue.size(), 3);
    Assert.assertEquals(mapValue.get("fname").stringValue(), "Chanaka");
    Assert.assertEquals(mapValue.get("lname").stringValue(), "Fernando");
    Assert.assertEquals(mapValue.get("ChanakaFernando").stringValue(), "ChanakaFernando");
}
Also used : BMap(org.ballerinalang.model.values.BMap) BValue(org.ballerinalang.model.values.BValue) 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