use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class JSONTest method testParseMalformedString.
@Test(description = "Get JSON from a malformed string")
public void testParseMalformedString() {
BValue[] args = { new BString("some words without quotes") };
BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
Assert.assertTrue(returns[0] instanceof BStruct);
Assert.assertEquals(((BStruct) returns[0]).getStringField(0), "Failed to parse json string: unrecognized token 'some' at line: 1 column: 6");
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class JSONTest method testToXMLJsonWithValue.
@Test(description = "Convert a json object with number value only")
public void testToXMLJsonWithValue() {
BValue[] args = { new BJSON(jsonToXML5) };
BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLString", args);
Assert.assertTrue(returns[0] instanceof BString);
String returnElement = (returns[0]).stringValue();
Assert.assertEquals(returnElement, "5");
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class JSONTest method testParseBoolean.
@Test(description = "Get JSON boolean from a string")
public void testParseBoolean() {
BValue[] args = { new BString("true") };
BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.BOOLEAN);
Assert.assertEquals(returns[0].stringValue(), "true");
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class JSONTest method testParseNumber.
@Test(description = "Get JSON number from a string")
public void testParseNumber() {
BValue[] args = { new BString("45678") };
BValue[] returns = BRunUtil.invoke(compileResult, "testParse", args);
Assert.assertTrue(returns[0] instanceof BJSON);
Assert.assertEquals(((BJSON) returns[0]).value().getType(), Type.LONG);
Assert.assertEquals(returns[0].stringValue(), "45678");
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class JSONTest method testToXMLEmptyElements.
@Test(description = "Convert a json object with empty elements")
public void testToXMLEmptyElements() {
BValue[] args = { new BJSON(jsonToXML10) };
BValue[] returns = BRunUtil.invoke(compileResult, "testToXMLWithXMLSequence", args);
Assert.assertTrue(returns[0] instanceof BString);
String textValue = returns[0].stringValue();
Assert.assertEquals(textValue, "<address/><homeAddresses/><phoneNumbers/>");
}
Aggregations