Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return empty set when grouping an empty set #40

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Loading