Changeset 10710 in josm


Ignore:
Timestamp:
2016-08-02T22:18:08+02:00 (3 years ago)
Author:
simon04
Message:

fix #12570 - Group MapCSS tag checker tests

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/validator/geometry.mapcss

    r10530 r10710  
    152152node[tag("amenity") = parent_tag("amenity")] ∈ *[amenity][amenity != parking] {
    153153  throwWarning: tr("{0} inside {1}", concat("amenity=", tag("amenity")), concat("amenity=", tag("amenity")));
     154  group: tr("{0} inside {1}", "amenity", "amenity");
    154155}
    155156node[tag("leisure") = parent_tag("leisure")] ∈ *[leisure] {
    156157  throwWarning: tr("{0} inside {1}", concat("leisure=", tag("leisure")), concat("leisure=", tag("leisure")));
     158  group: tr("{0} inside {1}", "leisure", "leisure");
    157159}
    158160node[tag("tourism") = parent_tag("tourism")] ∈ *[tourism] {
    159161  throwWarning: tr("{0} inside {1}", concat("tourism=", tag("tourism")), concat("tourism=", tag("tourism")));
     162  group: tr("{0} inside {1}", "tourism", "tourism");
    160163}
    161164node[tag("shop") = parent_tag("shop")] ∈ *[shop] {
    162165  throwWarning: tr("{0} inside {1}", concat("shop=", tag("shop")), concat("shop=", tag("shop")));
     166  group: tr("{0} inside {1}", "shop", "shop");
    163167}
    164168node[tag("power") = parent_tag("power")] ∈ *[power] {
    165169  throwWarning: tr("{0} inside {1}", concat("power=", tag("power")), concat("power=", tag("power")));
     170  group: tr("{0} inside {1}", "power", "power");
    166171}
    167172
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r10674 r10710  
    255255
    256256    public static class TagCheck implements Predicate<OsmPrimitive> {
     257        /** The selector of this {@code TagCheck} */
    257258        protected final GroupedMapCSSRule rule;
     259        /** Commands to apply in order to fix a matching primitive */
    258260        protected final List<FixCommand> fixCommands = new ArrayList<>();
     261        /** Tags (or arbitraty strings) of alternatives to be presented to the user */
    259262        protected final List<String> alternatives = new ArrayList<>();
     263        /** An {@link Instruction.AssignmentInstruction}-{@link Severity} pair.
     264         * Is evaluated on the matching primitive to give the error message. Map is checked to contain exactly one element. */
    260265        protected final Map<Instruction.AssignmentInstruction, Severity> errors = new HashMap<>();
     266        /** Unit tests */
    261267        protected final Map<String, Boolean> assertions = new HashMap<>();
     268        /** MapCSS Classes to set on matching primitives */
    262269        protected final Set<String> setClassExpressions = new HashSet<>();
     270        /** Denotes whether the object should be deleted for fixing it */
    263271        protected boolean deletion;
     272        /** A string used to group similar tests */
     273        protected String group;
    264274
    265275        TagCheck(GroupedMapCSSRule rule) {
     
    324334                    } else if ("assertNoMatch".equals(ai.key) && val != null) {
    325335                        check.assertions.put(val, Boolean.FALSE);
     336                    } else if ("group".equals(ai.key) && val != null) {
     337                        check.group = val;
    326338                    } else {
    327339                        throw new IllegalDataException("Cannot add instruction " + ai.key + ": " + ai.val + '!');
     
    563575                final Command fix = fixPrimitive(p);
    564576                final String description = getDescriptionForMatchingSelector(p, matchingSelector);
     577                final String description1 = group == null ? description : group;
     578                final String description2 = group == null ? null : description;
    565579                final List<OsmPrimitive> primitives;
    566580                if (env.child != null) {
     
    570584                }
    571585                if (fix != null) {
    572                     return new FixableTestError(null, getSeverity(), description, null, matchingSelector.toString(), 3000, primitives, fix);
     586                    return new FixableTestError(null, getSeverity(), description1, description2, matchingSelector.toString(), 3000, primitives, fix);
    573587                } else {
    574                     return new TestError(null, getSeverity(), description, null, matchingSelector.toString(), 3000, primitives);
     588                    return new TestError(null, getSeverity(), description1, description2, matchingSelector.toString(), 3000, primitives);
    575589                }
    576590            } else {
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r10657 r10710  
    5555        ParseResult result = MapCSSTagChecker.TagCheck.readMapCSS(new StringReader("" +
    5656                "*[natural=marsh] {\n" +
     57                "   group: tr(\"deprecated\");\n" +
    5758                "   throwWarning: tr(\"{0}={1} is deprecated\", \"{0.key}\", tag(\"natural\"));\n" +
    5859                "   fixRemove: \"{0.key}\";\n" +
     
    7273        n1.put("natural", "marsh");
    7374        assertTrue(check.test(n1));
    74         assertEquals("natural=marsh is deprecated", check.getErrorForPrimitive(n1).getMessage());
     75        assertEquals("deprecated", check.getErrorForPrimitive(n1).getMessage());
     76        assertEquals("natural=marsh is deprecated", check.getErrorForPrimitive(n1).getDescription());
    7577        assertEquals(Severity.WARNING, check.getErrorForPrimitive(n1).getSeverity());
    7678        assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText());
Note: See TracChangeset for help on using the changeset viewer.