Skip to content

Commit

Permalink
Return empty set when grouping an empty set
Browse files Browse the repository at this point in the history
  • Loading branch information
domi-b committed Jan 9, 2024
1 parent 04f4174 commit f909c30
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public Value evaluateInternal(String validationKind, String usageScope, IomObjec
return Value.createUndefined();
}

if (inputObjects.isEmpty()) {
return new Value(Collections.emptyList());
}

Viewable contextClass = EvaluationHelper.getContextClass(td, contextObject, argObjects);
if (contextClass == null) {
throw new IllegalStateException("unknown class in " + usageScope);
Expand Down
17 changes: 17 additions & 0 deletions src/test/data/GetInGroups/SetConstraintEmpty.ili
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INTERLIS 2.4;

MODEL TestSuite
AT "mailto:[email protected]" VERSION "2024-01-09" =
IMPORTS GeoW_FunctionsExt;

TOPIC FunctionTestTopic =

CLASS BaseClass =
textAttr: TEXT*16;
SET CONSTRAINT trueConstraintTextAttr: INTERLIS.elementCount(GeoW_FunctionsExt.GetInGroups(ALL, "textAttr")) == 0;
SET CONSTRAINT falseConstraintTextAttr: INTERLIS.elementCount(GeoW_FunctionsExt.GetInGroups(ALL, "textAttr")) == 2;
END BaseClass;

END FunctionTestTopic;

END TestSuite.
15 changes: 15 additions & 0 deletions src/test/data/GetInGroups/TestDataEmpty.xtf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ili:transfer xmlns:ili="http://www.interlis.ch/xtf/2.4/INTERLIS" xmlns:geom="http://www.interlis.ch/geometry/1.0"
xmlns:TestSuite="http://www.interlis.ch/xtf/2.4/TestSuite">
<ili:headersection>
<ili:models>
<ili:model>GeoW_FunctionsExt</ili:model>
<ili:model>TestSuite</ili:model>
</ili:models>
<ili:sender>ili2gpkg-4.6.1-63db90def1260a503f0f2d4cb846686cd4851184</ili:sender>
</ili:headersection>
<ili:datasection>
<TestSuite:FunctionTestTopic ili:bid="TestSuite.FunctionTestTopic">
</TestSuite:FunctionTestTopic>
</ili:datasection>
</ili:transfer>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class GetInGroupsIoxPluginTest {

protected static final String TEST_DATA = "GetInGroups/TestData.xtf";
protected static final String TEST_DATA_EMPTY = "GetInGroups/TestDataEmpty.xtf";
ValidationTestHelper vh = null;

@BeforeEach
Expand All @@ -28,4 +29,12 @@ void mandatoryConstraintOnThis() throws Ili2cFailure, IoxException {
AssertionHelper.assertSingleConstraintError(vh, 0, "falseConstraintEnumAttr");
AssertionHelper.assertSingleConstraintError(vh, 0, "falseConstraintNumberAttr");
}

@Test
void emptySet() throws Ili2cFailure, IoxException {
vh.runValidation(new String[]{TEST_DATA_EMPTY}, new String[]{"GetInGroups/SetConstraintEmpty.ili"});
Assert.equals(1, vh.getErrs().size());
AssertionHelper.assertNoConstraintError(vh, "trueConstraintTextAttr");
AssertionHelper.assertConstraintErrors(vh, 1, "falseConstraintTextAttr");
}
}

0 comments on commit f909c30

Please sign in to comment.