diff --git a/src/main/java/gov/nasa/pds/tools/validate/SpecialConstantChecker.java b/src/main/java/gov/nasa/pds/tools/validate/SpecialConstantChecker.java index 069d1b69d..d0c30be71 100644 --- a/src/main/java/gov/nasa/pds/tools/validate/SpecialConstantChecker.java +++ b/src/main/java/gov/nasa/pds/tools/validate/SpecialConstantChecker.java @@ -28,19 +28,22 @@ public static boolean isInfOrNan (String value) { * @param constants * @return */ + private static boolean equalsStripped(String value, String constant) { + return constant != null && value.equals(constant.strip()); + } public static boolean isNonConformantSpecialConstant(String value, SpecialConstants constants) { boolean matched = false; if (constants != null) { - matched |= value.equals(constants.getErrorConstant()); - matched |= value.equals(constants.getInvalidConstant()); - matched |= value.equals(constants.getMissingConstant()); - //matched |= value.equals(constants.getHighInstrumentSaturation()); - //matched |= value.equals(constants.getHighRepresentationSaturation()); - //matched |= value.equals(constants.getLowInstrumentSaturation()); - //matched |= value.equals(constants.getLowRepresentationSaturation()); - matched |= value.equals(constants.getNotApplicableConstant()); - matched |= value.equals(constants.getSaturatedConstant()); - matched |= value.equals(constants.getUnknownConstant()); + matched |= equalsStripped(value, constants.getErrorConstant()); + matched |= equalsStripped(value, constants.getInvalidConstant()); + matched |= equalsStripped(value, constants.getMissingConstant()); + //matched |= equalsStripped(value, constants.getHighInstrumentSaturation()); + //matched |= equalsStripped(value, constants.getHighRepresentationSaturation()); + //matched |= equalsStripped(value, constants.getLowInstrumentSaturation()); + //matched |= equalsStripped(value, constants.getLowRepresentationSaturation()); + matched |= equalsStripped(value, constants.getNotApplicableConstant()); + matched |= equalsStripped(value, constants.getSaturatedConstant()); + matched |= equalsStripped(value, constants.getUnknownConstant()); } return matched; } @@ -164,6 +167,7 @@ public static boolean isConformantSpecialConstant(Number value, SpecialConstants } public static boolean sameContent (Number number, String constant_repr, int radix) { if (constant_repr == null) return false; + constant_repr = constant_repr.strip(); if (number.toString().equals(constant_repr)) { return true; } diff --git a/src/test/resources/features/4.2.x.feature b/src/test/resources/features/4.2.x.feature index 049d05b68..cdf3dfa6e 100644 --- a/src/test/resources/features/4.2.x.feature +++ b/src/test/resources/features/4.2.x.feature @@ -20,4 +20,7 @@ Feature: 4.2.x # github1660: missing_constant must suppress min/max range errors in ASCII table fields | 1660 | 1 | "github1660" | "--skip-context-validation -t {datasrc}/pccds.xml" | "summary:productValidation:passed=1,summary:totalErrors=0,summary:totalWarnings=2,summary:messageTypes:warning.label.bad_schematypens=1,summary:messageTypes:warning.label.missing_schematron_spec=1" | +# github1656: missing_constant with leading/trailing whitespace must suppress min/max range errors +| 1656 | 1 | "github1656" | "--skip-context-validation -t {datasrc}/test_missing_constant_whitespace.xml" | "summary:productValidation:passed=1,summary:totalErrors=0,summary:totalWarnings=2,summary:messageTypes:warning.label.bad_schematypens=1,summary:messageTypes:warning.label.missing_schematron_spec=1" | + #end diff --git a/src/test/resources/github1656/test_missing_constant_whitespace.csv b/src/test/resources/github1656/test_missing_constant_whitespace.csv new file mode 100644 index 000000000..73d237f21 --- /dev/null +++ b/src/test/resources/github1656/test_missing_constant_whitespace.csv @@ -0,0 +1,3 @@ +1.500,-1.000 +2.300,-1.000 +0.750,5.000 diff --git a/src/test/resources/github1656/test_missing_constant_whitespace.xml b/src/test/resources/github1656/test_missing_constant_whitespace.xml new file mode 100644 index 000000000..b1a5918ad --- /dev/null +++ b/src/test/resources/github1656/test_missing_constant_whitespace.xml @@ -0,0 +1,86 @@ + + + + + + + urn:nasa:pds:test:data:missing_constant_whitespace + 1.0 + Test: missing_constant with leading whitespace should suppress min/max warnings + 1.11.0.0 + Product_Observational + + + + + 2020-01-01Z + 2020-12-31Z + + + Science + Derived + + + None + Other Investigation + + urn:nasa:pds:context:investigation:individual.none + data_to_investigation + + + + + Test Instrument + Instrument + + + + Test Target + Comet + + + + + + test_missing_constant_whitespace.csv + 3 + + + Test Table + TABLE + 0 + PDS DSV 1 + 3 + Carriage-Return Line-Feed + Comma + + 2 + 0 + + measurement + 1 + ASCII_Real + + 10000.0 + 0.001 + + + + quality_flag + 2 + ASCII_Real + + -1.000 + + + 10000.000 + 0.001 + + + + + + +