Search in sources :

Example 6 with PackageNode

use of org.ballerinalang.model.tree.PackageNode in project ballerina by ballerina-lang.

the class DocumentationTest method testDocStruct.

@Test(description = "Test doc struct.")
public void testDocStruct() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/struct.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangStruct) packageNode.getStructs().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for Test struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " struct `field a` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " struct `field b` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " struct `field c` documentation");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 7 with PackageNode

use of org.ballerinalang.model.tree.PackageNode in project ballerina by ballerina-lang.

the class DocumentationTest method testNestedInline.

@Test(description = "Test doc nested inline.")
public void testNestedInline() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/nested_inline.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangVariable constant = (BLangVariable) packageNode.getGlobalVariables().get(0);
    List<BLangDocumentation> docNodes = constant.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.getAttributes().size(), 0);
    Assert.assertEquals(dNode.documentationText, "\n" + "  Example of a string template:\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 : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Test(org.testng.annotations.Test)

Example 8 with PackageNode

use of org.ballerinalang.model.tree.PackageNode in project ballerina by ballerina-lang.

the class DocumentationTest method testDocService.

@Test(description = "Test doc service.", enabled = false)
public void testDocService() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/service.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    BLangService service = (BLangService) packageNode.getServices().get(0);
    List<BLangDocumentation> docNodes = service.docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
    dNode = service.getResources().get(0).docAttachments.get(0);
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.documentationText, "Check orderPizza resource. ");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
    dNode = service.getResources().get(1).docAttachments.get(0);
    Assert.assertEquals(dNode.documentationText, "Check status resource. ");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "conn");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " HTTP connection. ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "req");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " In request.");
}
Also used : BLangService(org.wso2.ballerinalang.compiler.tree.BLangService) 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 9 with PackageNode

use of org.ballerinalang.model.tree.PackageNode in project ballerina by ballerina-lang.

the class DocumentationTest method testDeprecatedTransformer.

@Test(description = "Test doc deprecated Transformer.")
public void testDeprecatedTransformer() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/deprecated_transformer.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDeprecatedNode> dNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).deprecatedAttachments;
    BLangDeprecatedNode dNode = dNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + "  This Transformer is deprecated use\n" + "  `transformer <Person p, Employee e> Bar(any defaultAddress) { e.name = p.firstName; }\n" + "  ` instead.\n");
    List<BLangDocumentation> docNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).docAttachments;
    BLangDocumentation docNode = docNodes.get(0);
    Assert.assertNotNull(docNode);
    Assert.assertEquals(docNode.documentationText, "\n Transformer Foo Person -> Employee\n ");
    Assert.assertEquals(docNode.getAttributes().size(), 3);
    Assert.assertEquals(docNode.getAttributes().get(0).documentationField.getValue(), "p");
    Assert.assertEquals(docNode.getAttributes().get(0).documentationText, " input struct Person source used for transformation\n ");
    Assert.assertEquals(docNode.getAttributes().get(1).documentationField.getValue(), "e");
    Assert.assertEquals(docNode.getAttributes().get(1).documentationText, " output struct Employee struct which Person transformed to\n ");
    Assert.assertEquals(docNode.getAttributes().get(2).documentationField.getValue(), "defaultAddress");
    Assert.assertEquals(docNode.getAttributes().get(2).documentationText, " address which serves Eg: `POSTCODE 112`\n");
}
Also used : BLangTransformer(org.wso2.ballerinalang.compiler.tree.BLangTransformer) BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) CompileResult(org.ballerinalang.launcher.util.CompileResult) BLangDeprecatedNode(org.wso2.ballerinalang.compiler.tree.BLangDeprecatedNode) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Example 10 with PackageNode

use of org.ballerinalang.model.tree.PackageNode in project ballerina by ballerina-lang.

the class DocumentationTest method testDocEnum.

@Test(description = "Test doc annotation enum.")
public void testDocEnum() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/enum.bal");
    Assert.assertEquals(0, compileResult.getWarnCount());
    PackageNode packageNode = compileResult.getAST();
    List<BLangDocumentation> docNodes = ((BLangEnum) packageNode.getEnums().get(0)).docAttachments;
    BLangDocumentation dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, " Documentation for state enum\n");
    Assert.assertEquals(dNode.getAttributes().size(), 2);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "foo");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " enum `field foo` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "bar");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " enum `field bar` documentation");
}
Also used : BLangDocumentation(org.wso2.ballerinalang.compiler.tree.BLangDocumentation) BLangEnum(org.wso2.ballerinalang.compiler.tree.BLangEnum) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Aggregations

CompileResult (org.ballerinalang.launcher.util.CompileResult)16 PackageNode (org.ballerinalang.model.tree.PackageNode)16 Test (org.testng.annotations.Test)16 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)14 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)5 BLangDeprecatedNode (org.wso2.ballerinalang.compiler.tree.BLangDeprecatedNode)3 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)3 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)3 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)2 BLangTransformer (org.wso2.ballerinalang.compiler.tree.BLangTransformer)2 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)1 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)1