Search in sources :

Example 56 with BString

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

the class MapInitializerExprTest method testNestedMapInit.

@Test
public void testNestedMapInit() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testNestedMapInit", new BValue[] {});
    Assert.assertTrue(returns[0] instanceof BMap<?, ?>);
    BMap<String, BValue> outerMap = (BMap<String, BValue>) returns[0];
    Assert.assertEquals(outerMap.get("name"), new BString("Supun"));
    BValue info = outerMap.get("info");
    Assert.assertTrue(info instanceof BMap<?, ?>);
    BMap<String, BValue> infoMap = (BMap<String, BValue>) info;
    Assert.assertEquals(infoMap.get("city"), new BString("Colombo"));
    Assert.assertEquals(infoMap.get("country"), new BString("SriLanka"));
}
Also used : BMap(org.ballerinalang.model.values.BMap) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 57 with BString

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

the class MapInitializerExprTest method testMapInitWithPackageVars.

@Test(enabled = false)
public void testMapInitWithPackageVars() {
    CompileResult result = BCompileUtil.compile(this, "test-src/types/map/", "a.b");
    BValue[] returns = BRunUtil.invoke(result, "testMapInitWithPackageVars");
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BMap.class);
    BMap<String, ?> mapValue = (BMap<String, BString>) returns[0];
    Assert.assertEquals(mapValue.size(), 2);
    Assert.assertEquals(mapValue.get("name").stringValue(), "PI");
    Assert.assertEquals(((BFloat) mapValue.get("value")).floatValue(), 3.14159);
}
Also used : BMap(org.ballerinalang.model.values.BMap) BValue(org.ballerinalang.model.values.BValue) CompileResult(org.ballerinalang.launcher.util.CompileResult) BString(org.ballerinalang.model.values.BString) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 58 with BString

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

the class MapInitializerExprTest method testMapInitWithJson.

@Test
public void testMapInitWithJson() {
    BValue[] returns = BRunUtil.invoke(compileResult, "testMapInitWithJson", new BValue[] {});
    Assert.assertTrue(returns[0] instanceof BMap<?, ?>);
    BMap<String, BValue> outerMap = (BMap<String, BValue>) returns[0];
    Assert.assertEquals(outerMap.get("name"), new BString("Supun"));
    BValue info = outerMap.get("info");
    Assert.assertTrue(info instanceof BJSON);
    BJSON infoJson = (BJSON) info;
    Assert.assertEquals(infoJson.stringValue(), "{\"city\":\"Colombo\",\"country\":\"SriLanka\"}");
}
Also used : BMap(org.ballerinalang.model.values.BMap) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BString(org.ballerinalang.model.values.BString) BJSON(org.ballerinalang.model.values.BJSON) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 59 with BString

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

the class StringTest method testBooleanValueOf.

@Test
public void testBooleanValueOf() {
    BValue[] args = { new BBoolean(true) };
    BValue[] returns = BRunUtil.invoke(result, "booleanValueOf", args);
    Assert.assertTrue(returns[0] instanceof BString);
    final String expected = "true";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BBoolean(org.ballerinalang.model.values.BBoolean) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 60 with BString

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

the class StringTest method testXmlValueOf.

@Test
public void testXmlValueOf() {
    BValue[] args = { new BXMLItem("<test>name</test>") };
    BValue[] returns = BRunUtil.invoke(result, "xmlValueOf", args);
    Assert.assertTrue(returns[0] instanceof BString);
    final String expected = "<test>name</test>";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BXMLItem(org.ballerinalang.model.values.BXMLItem) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) 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