use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.
the class BJSONValueTest method testJsonToJsonArrayInvalidCasting.
@Test
public void testJsonToJsonArrayInvalidCasting() {
BValue[] returns = BRunUtil.invoke(compileResult, "testJsonToJsonArrayInvalidCasting");
Assert.assertTrue(returns[0] instanceof BStruct);
String errorMsg = ((BStruct) returns[0]).getStringField(0);
Assert.assertEquals(errorMsg, "'json[]' cannot be cast to 'json[][][]'");
}
use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.
the class BJSONValueTest method testFloatAsJsonVal.
@Test(description = "Test initializing json with a float")
public void testFloatAsJsonVal() {
BValue[] returns = BRunUtil.invoke(compileResult, "testFloatAsJsonVal");
Assert.assertTrue(returns[0] instanceof BJSON);
BJSON person = ((BJSON) returns[0]);
Assert.assertEquals(person.value().doubleValue(), 7.65);
}
use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.
the class BJSONValueTest method testJSONWithExpressionKey.
@Test
public void testJSONWithExpressionKey() {
CompileResult result = BCompileUtil.compile("test-src/types/jsontype/json-literal-with-expr-key.bal");
BValue[] returns = BRunUtil.invoke(result, "testJSONWithExpressionKey");
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(returns[0].stringValue(), "{\"a\":\"Lion\",\"key1\":\"Cat\",\"key2\":\"Dog\"}");
}
use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.
the class BJSONValueTest method testUpdateJson.
@Test
public void testUpdateJson() {
BValue[] returns = BRunUtil.invoke(compileResult, "testUpdateJson");
Assert.assertTrue(returns[0] instanceof BJSON);
BJSON json = ((BJSON) returns[0]);
Assert.assertEquals(json.toString(), "{\"fname\":\"Supun\",\"address\":{\"country\":\"SriLanka\"}}");
}
use of org.ballerinalang.model.values.BValue in project ballerina by ballerina-lang.
the class BJSONValueTest method testStringAsJsonVal.
@Test(description = "Test initializing json with a string")
public void testStringAsJsonVal() {
BValue[] returns = BRunUtil.invoke(compileResult, "testStringAsJsonVal");
Assert.assertTrue(returns[0] instanceof BJSON);
BJSON person = ((BJSON) returns[0]);
Assert.assertEquals(person.value().asText(), "Supun");
}
Aggregations