Skip to content

Commit

Permalink
Fix parsing of function parameters for #320 (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-stein-gsa authored Jan 2, 2025
1 parent ee233b5 commit f73954c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public IExpression handleInlinefunctionexpr(Metapath10.InlinefunctionexprContext
0,
2,
(ctx, idx) -> {
int pos = (idx - 1) / 2;
int pos = idx / 2;
ParamContext tree = ctx.param(pos);
return IArgument.of(
getContext().parseVariableName(ObjectUtils.notNull(tree.eqname().getText())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import static gov.nist.secauto.metaschema.core.metapath.TestUtils.qname;
import gov.nist.secauto.metaschema.core.metapath.DynamicContext;
import gov.nist.secauto.metaschema.core.metapath.IMetapathExpression;
import gov.nist.secauto.metaschema.core.metapath.StaticContext;
import gov.nist.secauto.metaschema.core.metapath.IMetapathExpression.ResultType;
import gov.nist.secauto.metaschema.core.qname.IEnhancedQName;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -51,7 +54,15 @@ void test() {

@Test
void testMultipleParameters() {
// FIXME: Add test for function with multiple parameters
StaticContext staticContext = StaticContext.builder()
.namespace("ex", NS)
.build();
DynamicContext dynamicContext = new DynamicContext(staticContext);
String metapath = "function ($argument1 as meta:string, $argument2 as meta:string) as meta:string { $argument2 }";
dynamicContext.bindVariableValue(qname(NS, "boom"),
IMetapathExpression.compile(metapath, staticContext).evaluate(null, dynamicContext));
String result = IMetapathExpression.compile("$ex:boom('a', 'b')", staticContext).evaluateAs(null, ResultType.STRING , dynamicContext);
assertEquals(result, "b");
}

@Test
Expand Down

0 comments on commit f73954c

Please sign in to comment.