Search in sources :

Example 46 with FIELD

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.

the class HtmlDocTest method testStructDefaultValues.

@Test(description = "Tests whether default values are collected.")
public void testStructDefaultValues() {
    BLangPackage bLangPackage = createPackage("package x.y; " + "public struct Person {" + "  string id;" + "  string address = \"20,Palm Grove\";" + "}");
    Page page = generatePage(bLangPackage);
    Assert.assertEquals(page.constructs.size(), 1);
    Assert.assertTrue(page.constructs.get(0) instanceof StructDoc, "Documentable of type StructDoc expected.");
    StructDoc personStructDoc = (StructDoc) page.constructs.get(0);
    Assert.assertEquals(personStructDoc.fields.size(), 2, "2 fields are expected.");
    Assert.assertEquals(personStructDoc.fields.get(0).name, "id", "Field \"id\" expected.");
    Assert.assertEquals(personStructDoc.fields.get(1).name, "address", "Field \"address\" expected.");
    Assert.assertEquals(personStructDoc.fields.get(1).defaultValue, "20,Palm Grove", "Unexpected address value found.");
}
Also used : BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) Page(org.ballerinalang.docgen.model.Page) StructDoc(org.ballerinalang.docgen.model.StructDoc) Test(org.testng.annotations.Test)

Example 47 with FIELD

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD 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)

Example 48 with FIELD

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD 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 49 with FIELD

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD 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 50 with FIELD

use of org.wso2.ballerinalang.compiler.codegen.CodeGenerator.VariableIndex.Kind.FIELD in project ballerina by ballerina-lang.

the class DocumentationTest method testMultiple.

@Test(description = "Test doc multiple.")
public void testMultiple() {
    CompileResult compileResult = BCompileUtil.compile("test-src/documentation/multiple.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 Tst struct\n");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "a");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " annotation `field a` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "b");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " annotation `field b` documentation\n");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "c");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " annotation `field c` documentation");
    docNodes = ((BLangEnum) packageNode.getEnums().get(0)).docAttachments;
    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");
    docNodes = ((BLangTransformer) packageNode.getTransformers().get(0)).docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "\n" + " Transformer Foo Person -> Employee\n" + " ");
    Assert.assertEquals(dNode.getAttributes().size(), 3);
    Assert.assertEquals(dNode.getAttributes().get(0).documentationField.getValue(), "p");
    Assert.assertEquals(dNode.getAttributes().get(0).documentationText, " input struct Person source used for transformation\n ");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationField.getValue(), "e");
    Assert.assertEquals(dNode.getAttributes().get(1).documentationText, " output struct Employee struct which Person transformed to\n ");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationField.getValue(), "defaultAddress");
    Assert.assertEquals(dNode.getAttributes().get(2).documentationText, " address which serves Eg: `POSTCODE 112`\n");
    BLangService service = (BLangService) packageNode.getServices().get(0);
    docNodes = service.docAttachments;
    dNode = docNodes.get(0);
    Assert.assertNotNull(dNode);
    Assert.assertEquals(dNode.documentationText, "PizzaService HTTP Service");
/*
        // Commented due to https://github.com/ballerina-lang/ballerina/issues/5586 issue
        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) BLangStruct(org.wso2.ballerinalang.compiler.tree.BLangStruct) CompileResult(org.ballerinalang.launcher.util.CompileResult) PackageNode(org.ballerinalang.model.tree.PackageNode) Test(org.testng.annotations.Test)

Aggregations

BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)14 Test (org.testng.annotations.Test)11 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)10 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)10 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)10 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)8 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)8 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)8 BLangXMLQName (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName)8 Name (org.wso2.ballerinalang.compiler.util.Name)8 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)7 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)7 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)7 CompileResult (org.ballerinalang.launcher.util.CompileResult)6 PackageNode (org.ballerinalang.model.tree.PackageNode)6 BLangDocumentation (org.wso2.ballerinalang.compiler.tree.BLangDocumentation)6 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)5 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)5 BLangEnum (org.wso2.ballerinalang.compiler.tree.BLangEnum)5