Search in sources :

Example 1 with StandardNativeElementProvider

use of org.ballerinalang.test.utils.mock.StandardNativeElementProvider in project ballerina by ballerina-lang.

the class FunctionSignatureTest method testOptionalArgsInNativeFunc.

@Test(enabled = false)
public void testOptionalArgsInNativeFunc() {
    NativeElementRepository repo = NativeUnitLoader.getInstance().getNativeElementRepository();
    StandardNativeElementProvider provider = new StandardNativeElementProvider();
    provider.populateNatives(repo);
    CompileResult result = BCompileUtil.compile(this, "test-src/functions/", "foo.bar");
    BValue[] returns = BRunUtil.invoke(result, "testOptionalArgsInNativeFunc");
    Assert.assertTrue(returns[0] instanceof BInteger);
    Assert.assertEquals(((BInteger) returns[0]).intValue(), 78);
    Assert.assertTrue(returns[1] instanceof BFloat);
    Assert.assertEquals(((BFloat) returns[1]).floatValue(), 89.0);
    Assert.assertTrue(returns[2] instanceof BString);
    Assert.assertEquals(returns[2].stringValue(), "John");
    Assert.assertTrue(returns[3] instanceof BInteger);
    Assert.assertEquals(((BInteger) returns[3]).intValue(), 5);
    Assert.assertTrue(returns[4] instanceof BString);
    Assert.assertEquals(returns[4].stringValue(), "Doe");
    Assert.assertTrue(returns[5] instanceof BIntArray);
    Assert.assertEquals(returns[5].stringValue(), "[4, 5, 6]");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) StandardNativeElementProvider(org.ballerinalang.test.utils.mock.StandardNativeElementProvider) CompileResult(org.ballerinalang.launcher.util.CompileResult) NativeElementRepository(org.ballerinalang.natives.NativeElementRepository) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Aggregations

CompileResult (org.ballerinalang.launcher.util.CompileResult)1 BFloat (org.ballerinalang.model.values.BFloat)1 BIntArray (org.ballerinalang.model.values.BIntArray)1 BInteger (org.ballerinalang.model.values.BInteger)1 BString (org.ballerinalang.model.values.BString)1 BValue (org.ballerinalang.model.values.BValue)1 NativeElementRepository (org.ballerinalang.natives.NativeElementRepository)1 StandardNativeElementProvider (org.ballerinalang.test.utils.mock.StandardNativeElementProvider)1 Test (org.testng.annotations.Test)1