Search in sources :

Example 16 with Example

use of org.wso2.siddhi.annotation.Example in project ballerina by ballerina-lang.

the class DocumentationTest method testDocFunction.

@Test(description = "Test doc function.")
public void testDocFunction() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/function.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + "Gets a access parameter value (`true` or `false`) for a given key. " + "Please note that #foo will always be bigger than #bar.\n" + "Example:\n" + "``SymbolEnv pkgEnv = symbolEnter.packageEnvs.get(pkgNode.symbol);``\n");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "file");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " file path ``C:\\users\\OddThinking\\Documents\\My Source\\Widget\\foo.src``\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "accessMode");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " read or write mode\n");
    docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for File struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 1);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "path");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field path` documentation\n");
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 17 with Example

use of org.wso2.siddhi.annotation.Example in project ballerina by ballerina-lang.

the class DocumentationTest method testDocConnectorFunction.

@Test(description = "Test doc connector/function.", enabled = false)
public void testDocConnectorFunction() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/connector_function.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangConnector connector = (BLangConnector) packageNode.getConnectors().get(0);
    List<BLangDocumentation> docNodes = connector.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.documentationText, "Test Connector\n");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "url");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " url for endpoint\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "path");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " path for endpoint\n");
    dNode = connector.getActions().get(0).docAttachments.get(0);
    Assert.assertEquals(dNode.getAttributes().size(), 1);
    Assert.assertEquals(dNode.documentationText, "Test Connector action testAction ");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "s");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not");
    dNode = connector.getActions().get(1).docAttachments.get(0);
    Assert.assertEquals(dNode.documentationText, "Test Connector action testSend ");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "ep");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " which represent successful or not ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "s");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " which represent successful or not");
    docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + "Gets a access parameter value (`true` or `false`) for a given key. " + "Please note that #foo will always be bigger than #bar.\n" + "Example:\n" + "``SymbolEnv pkgEnv = symbolEnter.packageEnvs.get(pkgNode.symbol);``\n");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "file");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " file path ``C:\\users\\OddThinking\\Documents\\My Source\\Widget\\foo.src``\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "accessMode");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " read or write mode\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "successful");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " boolean `true` or `false`\n");
    docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for File struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 1);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "path");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field path` documentation\n");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) BLangConnector(org.wso2.ballerinalang.compiler.tree.BLangConnector) Test(org.testng.annotations.Test)

Example 18 with Example

use of org.wso2.siddhi.annotation.Example in project ballerina by ballerina-lang.

the class DocumentationTest method testNestedInlineDeprecated.

@Test(description = "Test doc nested inline inside deprecated tag.")
public void testNestedInlineDeprecated() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/nested_inline_deprecated.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangVariable constant = (BLangVariable) packageNode.getGlobalVariables().get(0);
    List<BLangDeprecatedNode> docNodes = constant.deprecatedAttachments;
    BLangDeprecatedNode dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + "  Example of a string templates:\n" + "  ``` This starts ends triple backtick  ``string s = string `hello {{name}}`;`` " + "ends triple backtick```\n" + "\n" + "  Example for an xml literal:\n" + "    ``xml x = xml `<{{tagName}}>hello</{{tagName}}>`;``\n");
}
Also used : CompileResult(org.ballerinalang.launcher.util.CompileResult) BLangDeprecatedNode(org.wso2.ballerinalang.compiler.tree.BLangDeprecatedNode) PackageNode(org.ballerinalang.model.tree.PackageNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Test(org.testng.annotations.Test)

Example 19 with Example

use of org.wso2.siddhi.annotation.Example in project ballerina by ballerina-lang.

the class DocumentationTest method testDocNativeFunction.

@Test(description = "Test doc native function.")
public void testDocNativeFunction() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/native_function.bal", CompilerPhase.TYPE_CHECK);
    Assert.assertEquals(1, compileResult.getWarnCount());
    BAssertUtil.validateWarning(compileResult, 0, "no such documentable attribute 'successful' with doc prefix 'P'", 6, 1);
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangFunction) packageNode.getFunctions().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + "Gets a access parameter value (`true` or `false`) for a given key. " + "Please note that #foo will always be bigger than #bar.\n" + "Example:\n" + "``SymbolEnv pkgEnv = symbolEnter.packageEnvs.get(pkgNode.symbol);``\n");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "accessMode");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " read or write mode\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "successful");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " boolean `true` or `false`\n");
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Aggregations

CompileResult (org.ballerinalang.launcher.util.CompileResult)7 PackageNode (org.ballerinalang.model.tree.PackageNode)7 Test (org.testng.annotations.Test)7 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)6 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)6 ArrayList (java.util.ArrayList)3 Collection (org.wso2.carbon.registry.core.Collection)3 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)2 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)2 BVarSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol)2 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)2 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)2 BLangBlockStmt (org.wso2.ballerinalang.compiler.tree.statements.BLangBlockStmt)2 BLangVariableDef (org.wso2.ballerinalang.compiler.tree.statements.BLangVariableDef)2 Example (org.wso2.siddhi.annotation.Example)2 Extension (org.wso2.siddhi.annotation.Extension)2 Parameter (org.wso2.siddhi.annotation.Parameter)2 ReturnAttribute (org.wso2.siddhi.annotation.ReturnAttribute)2 SystemParameter (org.wso2.siddhi.annotation.SystemParameter)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1