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