Skip to content

Commit

Permalink
composer for function test doc (finos#2597)
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari authored Feb 1, 2024
1 parent 08b7fd7 commit 4ac5d44
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ else if (test instanceof FunctionTest)
{
FunctionTest functionTest = (FunctionTest) test;
Root_meta_legend_function_metamodel_FunctionTest metamodelTest = new Root_meta_legend_function_metamodel_FunctionTest_Impl("", SourceInformationHelper.toM3SourceInformation(test.sourceInformation), compileContext.pureModel.getClass("meta::legend::function::metamodel::FunctionTest"))
._id(functionTest.id);
._id(functionTest.id)
._doc(functionTest.doc);
if (functionTest.parameters != null && !functionTest.parameters.isEmpty())
{
metamodelTest._parameters(ListIterate.collect(functionTest.parameters, param -> processFunctionTestParameterValue(param, compileContext)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ functionData: qualifiedName COLON functionData
;
functionDataValue: (qualifiedName | externalFormatValue | embeddedData)
;
simpleFunctionTest: identifier PIPE identifier PAREN_OPEN functionParams PAREN_CLOSE EQUAL GREATER_THAN (externalFormatValue | primitiveValue) SEMI_COLON
simpleFunctionTest: identifier (STRING)? PIPE identifier PAREN_OPEN functionParams PAREN_CLOSE EQUAL GREATER_THAN (externalFormatValue | primitiveValue) SEMI_COLON
;
externalFormatValue: contentType STRING
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ private void processFuncTest(DomainParserGrammar.FunctionDefinitionContext funct
}
FunctionTest functionTest = new FunctionTest();
functionTest.id = PureGrammarParserUtility.fromIdentifier(simpleFunctionTestContext.identifier(0));
if (simpleFunctionTestContext.STRING() != null)
{
functionTest.doc = PureGrammarParserUtility.fromGrammarString(simpleFunctionTestContext.STRING().getText(), true);
}
functionTest.sourceInformation = this.walkerSourceInformation.getSourceInformation(simpleFunctionTestContext);
DomainParserGrammar.FunctionParamsContext functionParamsContext = simpleFunctionTestContext.functionParams();
if (functionParamsContext != null && !functionParamsContext.primitiveValue().isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ else if (embeddedData instanceof ExternalFormatData)
public static String renderFunctionTest(Function function, FunctionTest functionTest, int currentInt, PureGrammarComposerContext context)
{
StringBuilder str = new StringBuilder();
str.append(getTabString(currentInt)).append(functionTest.id).append(" | ").append(HelperValueSpecificationGrammarComposer.getFunctionNameWithNoPackage(function)).append("(");
str.append(getTabString(currentInt)).append(functionTest.id);
if (functionTest.doc != null)
{
str.append(" ").append(PureGrammarComposerUtility.convertString(functionTest.doc, true));
}
str.append(" | ").append(HelperValueSpecificationGrammarComposer.getFunctionNameWithNoPackage(function)).append("(");
if (functionTest.parameters != null && !functionTest.parameters.isEmpty())
{
str.append(LazyIterate.collect(functionTest.parameters, parameterValue -> parameterValue.value.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance(context).build())).makeString(","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public void testFunctionTest()
" 'Hello ' + $name\n" +
"}\n" +
"{\n" +
" myTest | Hello('John',20) => 'Hello John!';\n" +
" myTest 'this is some documentation for the test' | Hello('John',20) => 'Hello John!';\n" +
" myOtherTest | Hello('Nicole',20) => 'Hello Nicole!';\n" +
"}\n");
test("function my::Hello(name: String[1]): String[1]\n" +
Expand Down

0 comments on commit 4ac5d44

Please sign in to comment.