use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testSetChildren.
@Test
public void testSetChildren() {
BValue[] returns = BRunUtil.invoke(result, "testSetChildren");
Assert.assertEquals(returns.length, 4);
Assert.assertTrue(returns[0] instanceof BXML);
Assert.assertEquals(returns[0].stringValue(), "<ns0:name xmlns:ns0=\"http://sample.com/test\"><newFname>" + "supun-new</newFname><newMname>thilina-new</newMname><newLname>setunga-new</newLname></ns0:name>");
// is children seq is empty?
Assert.assertSame(returns[1].getClass(), BBoolean.class);
Assert.assertEquals(((BBoolean) returns[1]).booleanValue(), false);
// is children seq is singleton?
Assert.assertSame(returns[2].getClass(), BBoolean.class);
Assert.assertEquals(((BBoolean) returns[2]).booleanValue(), true);
// Check children
Assert.assertTrue(returns[3] instanceof BXML);
BRefValueArray children = ((BXMLSequence) returns[3]).value();
Assert.assertEquals(children.size(), 3);
Assert.assertEquals(children.get(0).stringValue(), "<newFname>supun-new</newFname>");
Assert.assertEquals(children.get(1).stringValue(), "<newMname>thilina-new</newMname>");
Assert.assertEquals(children.get(2).stringValue(), "<newLname>setunga-new</newLname>");
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class XMLNativeFunctionTest method testSetChildrenWithEmptyNamespace.
@Test
public void testSetChildrenWithEmptyNamespace() {
BValue[] returns = BRunUtil.invoke(result, "testSetChildrenEmptyNamespace");
Assert.assertEquals(returns.length, 5);
Assert.assertTrue(returns[0] instanceof BXML);
Assert.assertEquals(returns[0].stringValue(), "<name xmlns=\"http://sample.com/test\"><fname>supun</fname>" + "<lname>setunga</lname><residency xmlns=\"\" citizen=\"true\">true</residency></name>");
// is children seq is empty?
Assert.assertSame(returns[1].getClass(), BBoolean.class);
Assert.assertEquals(((BBoolean) returns[1]).booleanValue(), false);
// is children seq is singleton?
Assert.assertSame(returns[2].getClass(), BBoolean.class);
Assert.assertEquals(((BBoolean) returns[2]).booleanValue(), true);
// Check children
Assert.assertTrue(returns[3] instanceof BXML);
BRefValueArray children = ((BXMLSequence) returns[3]).value();
Assert.assertEquals(children.size(), 3);
Assert.assertEquals(children.get(0).stringValue(), "<fname xmlns=\"http://sample.com/test\">supun</fname>");
Assert.assertEquals(children.get(1).stringValue(), "<lname xmlns=\"http://sample.com/test\">setunga</lname>");
Assert.assertEquals(children.get(2).stringValue(), "<residency citizen=\"true\">true</residency>");
// Check attribute value
Assert.assertSame(returns[4].getClass(), BString.class);
Assert.assertEquals(((BString) returns[4]).stringValue(), "true");
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class GetDate method execute.
@Override
public void execute(Context context) {
BStruct timeStruct = ((BStruct) context.getRefArgument(0));
BRefValueArray date = new BRefValueArray(getDateTupleType);
date.add(0, new BInteger(getYear(timeStruct)));
date.add(1, new BInteger(getMonth(timeStruct)));
date.add(2, new BInteger(getDay(timeStruct)));
context.setReturnValues(date);
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class GetTime method execute.
@Override
public void execute(Context context) {
BStruct timeStruct = ((BStruct) context.getRefArgument(0));
BRefValueArray time = new BRefValueArray(getTimeTupleType);
time.add(0, new BInteger(getHour(timeStruct)));
time.add(1, new BInteger(getMinute(timeStruct)));
time.add(2, new BInteger(getSecond(timeStruct)));
time.add(3, new BInteger(getMilliSecond(timeStruct)));
context.setReturnValues(time);
}
use of org.ballerinalang.model.values.BRefValueArray in project ballerina by ballerina-lang.
the class Util method getArrayOfBodyParts.
/**
* From a given list of body parts get a ballerina value array.
*
* @param bodyParts List of body parts
* @return BRefValueArray representing an array of entities
*/
static BRefValueArray getArrayOfBodyParts(ArrayList<BStruct> bodyParts) {
BStructType typeOfBodyPart = bodyParts.get(0).getType();
BStruct[] result = bodyParts.toArray(new BStruct[bodyParts.size()]);
return new BRefValueArray(result, typeOfBodyPart);
}
Aggregations