-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pure: Evaluate variables in the order they are declared
Store the variables from the Schematron in a linked hashmap, to preserve their order. They are then evaluated in the order they are declared. Before this, variables were sorted with the longest first. We were replacing variable references with their expressions, so starting with the longest was needed. With the new way of evaluating variables, this caused problems when a variable referenced another variable that has a shorter name. This changes the IPSXPathVariables interface to return maps and sets, instead of navigable maps and sorted sets. It does not seem that the specifics of these types were used. Add unit test that checks the correction of this bug. Fixes #177.
- Loading branch information
1 parent
10c5522
commit a0e969b
Showing
5 changed files
with
95 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
ph-schematron-pure/src/test/java/com/helger/schematron/pure/supplementary/Issue177Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2014-2024 Philip Helger (www.helger.com) | ||
* philip[at]helger[dot]com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.helger.schematron.pure.supplementary; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import java.io.File; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.helger.commons.io.resource.FileSystemResource; | ||
import com.helger.schematron.pure.SchematronResourcePure; | ||
import com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler; | ||
import com.helger.schematron.svrl.SVRLHelper; | ||
import com.helger.schematron.svrl.SVRLMarshaller; | ||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
|
||
public final class Issue177Test | ||
{ | ||
private static final Logger LOGGER = LoggerFactory.getLogger (Issue177Test.class); | ||
|
||
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception | ||
{ | ||
final SchematronResourcePure aSCH = SchematronResourcePure.fromFile (aSchematron); | ||
aSCH.validateCompletely (new LoggingPSErrorHandler ()); | ||
|
||
// Perform validation | ||
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML)); | ||
assertNotNull (aSVRL); | ||
if (true) | ||
LOGGER.info (new SVRLMarshaller ().getAsString (aSVRL)); | ||
|
||
assertEquals (0, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports (aSVRL).size ()); | ||
} | ||
|
||
@Test | ||
public void testIssue () throws Exception | ||
{ | ||
validateAndProduceSVRL (new File ("src/test/resources/external/issues/github177/schematron.sch"), | ||
new File ("src/test/resources/external/issues/github177/test.xml")); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
ph-schematron-pure/src/test/resources/external/issues/github177/schematron.sch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xpath2"> | ||
<pattern> | ||
<let name="var" value="1"/> | ||
<let name="var-plus-one" value="$var + 1"/> | ||
|
||
<rule context="/a"> | ||
<assert role="ERROR" test="$var-plus-one = 2">error message</assert> | ||
</rule> | ||
</pattern> | ||
</schema> |
12 changes: 12 additions & 0 deletions
12
ph-schematron-pure/src/test/resources/external/issues/github177/test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<a> | ||
<b> | ||
<c>1</c> | ||
</b> | ||
<b> | ||
<c>2</c> | ||
</b> | ||
<b> | ||
<c>3</c> | ||
</b> | ||
</a> |