Changeset 6513 in josm for trunk


Ignore:
Timestamp:
2013-12-23T00:13:58+01:00 (11 years ago)
Author:
simon04
Message:

see #9414 - convert some tagchecker tests to MapCSS, extend MapCSS by test for false values

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/validator/tagchecker.cfg

    r6510 r6513  
    3737# Empty lines and space signs are ignored
    3838
    39 way  : W : highway == * && name == /.* (Ave|Blvd|Br|Brg|Cct|Cir|Cl|Cr|Crct|Cres|Crt|Ct|Dr|Drv|Esp|Espl|Hwy|Ln|Mw|Mwy|Pl|Rd|Qy|Qys|Sq|St|Str|Ter|Tce|Tr|Wy)\.?$/i               # abbreviated street name
    40 
    41 node : W : oneway == *                                                         # oneway tag on a node
    42 node : W : bridge == BOOLEAN_TRUE                                              # bridge tag on a node
    43 node : W : highway == /motorway*|trunk*|primary*|secondary*|tertiary*|unclassified|residential|service|living_street|pedestrian|track|path|footway/  # wrong highway tag on a node
    44 way  : W : /highway|railway/ == crossing                                       # wrong crossing tag on a way
    45 way  : I : highway == unclassified && name != *                                # Unnamed unclassified highway
    46 way  : I : highway == /motorway|trunk|primary|secondary|tertiary/ && ref != *  # highway without a reference
    47 *    : W : highway == road                                                     # temporary highway type
    4839*    : W : / *name */i == * && name != *                                       # misspelled key name
    4940
     
    5243#way  : W : highway == /motorway|trunk|primary|secondary|tertiary|residential|pedestrian/ && /name|ref|(name:.*)|(.*_name)|(.*_ref)/ != * # Unnamed
    5344
    54 way  : W : highway == cycleway && bicycle == BOOLEAN_FALSE     # cycleway with tag bicycle
    55 way  : W : highway == footway && foot == BOOLEAN_FALSE         # footway with tag foot
    56 #way  : I : highway == cycleway && bicycle == *                 # cycleway with tag bicycle
    57 #way  : I : highway == footway && foot == *                     # footway with tag foot
    58 way  : W : highway == cycleway && cycleway == lane             # separate cycleway as lane on a cycleway
    59 way  : W : highway == * && barrier == *                        # barrier used on a way
    60 
    61 #way  : I : waterway == * && layer != *                         # waterway without layer tag
    62 way  : I : highway == footway && maxspeed == *                 # maxspeed used for footway
    63 way  : I : highway == steps && maxspeed == *                   # maxspeed used for footway
    64 
    6545# see #5844, #6760
    6646#way  : W : oneway != BOOLEAN_FALSE && /.*:(backward|forward)/ == *    # oneway combined with *:backward/forward
    67 
    68 *    : W : layer == /\+.*/                                     # layer tag with + sign
    69 
    70 *    : I : name == /.*Strasse.*/i                              # street name contains ss
    7147
    7248relation : E : type != *                                       # relation without type
     
    217193
    218194# measurement values and units warnings (ticket #8687)
     195*   : W : layer == /\+.*/                                     # layer tag with + sign
    219196way : W : layer == * && layer != /^0$|^-?[1-5]$/                                                                         # layer should be between -5 and 5
    220197*   : W : level == * && level != /^((([0-9]|-[1-9])|[1-9][0-9]*)(\.5)?)(;(([0-9]|-[1-9])|[1-9][0-9]*)(\.5)?)*$|^-0\.5$/  # level should be numbers with optional .5 increments
  • trunk/src/org/openstreetmap/josm/data/osm/Tag.java

    r6512 r6513  
    9999    }
    100100
     101    /**
     102     * This constructs a {@link Tag} by splitting {@code s} on the first equality sign.
     103     * @see org.openstreetmap.josm.tools.TextTagParser
     104     * @param s the string to convert
     105     * @return the constructed tag
     106     */
    101107    public static Tag ofString(String s) {
    102108        CheckParameterUtil.ensureParameterNotNull(s, "s");
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r6512 r6513  
    229229    public void initialize() throws Exception {
    230230        addMapCSS(new InputStreamReader(getClass().getResourceAsStream("/data/validator/deprecated.mapcss"), "UTF-8"));
     231        addMapCSS(new InputStreamReader(getClass().getResourceAsStream("/data/validator/highway.mapcss"), "UTF-8"));
    231232    }
    232233}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r6455 r6513  
    3838    }
    3939
    40     public static Condition create(String k, boolean not, boolean yes, Context context) {
     40    public static Condition create(String k, boolean not, boolean yes, boolean no, Context context) {
    4141        switch (context) {
    4242        case PRIMITIVE:
    43             return new KeyCondition(k, not, yes);
     43            return new KeyCondition(k, not, yes, no);
    4444        case LINK:
    45             if (yes)
     45            if (yes || no)
    4646                throw new MapCSSException("Question mark operator ''?'' not supported in LINK context");
    4747            if (not)
     
    216216     *     ["a label"?]  PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a true-value
    217217     *                   LINK:       not supported
     218     *
     219     *     ["a label"?!] PRIMITIVE:  the primitive has a tag "a label" whose value evaluates to a false-value
     220     *                   LINK:       not supported
    218221     * </pre>
    219222     */
     
    221224
    222225        private String label;
    223         private boolean exclamationMarkPresent;
    224         private boolean questionMarkPresent;
    225 
    226         /**
    227          *
    228          * @param label
    229          * @param exclamationMarkPresent
    230          * @param questionMarkPresent
    231          */
    232         public KeyCondition(String label, boolean exclamationMarkPresent, boolean questionMarkPresent){
     226        private boolean negateResult;
     227        private boolean testForTrueValues;
     228        private boolean testForFalseValues;
     229
     230        public KeyCondition(String label, boolean negateResult, boolean testForTrueValues, boolean testForFalseValues){
    233231            this.label = label;
    234             this.exclamationMarkPresent = exclamationMarkPresent;
    235             this.questionMarkPresent = questionMarkPresent;
     232            this.negateResult = negateResult;
     233            this.testForTrueValues = testForTrueValues;
     234            this.testForFalseValues = testForFalseValues;
    236235        }
    237236
     
    240239            switch(e.getContext()) {
    241240            case PRIMITIVE:
    242                 if (questionMarkPresent)
    243                     return OsmUtils.isTrue(e.osm.get(label)) ^ exclamationMarkPresent;
     241                if (testForTrueValues)
     242                    return OsmUtils.isTrue(e.osm.get(label)) ^ negateResult;
     243                else if (testForFalseValues)
     244                    return OsmUtils.isFalse(e.osm.get(label)) ^ negateResult;
    244245                else
    245                     return e.osm.hasKey(label) ^ exclamationMarkPresent;
     246                    return e.osm.hasKey(label) ^ negateResult;
    246247            case LINK:
    247248                Utils.ensure(false, "Illegal state: KeyCondition not supported in LINK context");
     
    253254        @Override
    254255        public String toString() {
    255             return "[" + (exclamationMarkPresent ? "!" : "") + label + "]";
     256            return "[" + (negateResult ? "!" : "") + label + "]";
    256257        }
    257258    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParser.jj

    r6455 r6513  
    345345    boolean not = false;
    346346    boolean yes = false;
     347    boolean no = false;
    347348    String key;
    348349}
     
    350351    ( <EXCLAMATION> { not = true; } )?
    351352    key=tag_key()
     353    ( LOOKAHEAD(2) <QUESTION> <EXCLAMATION> { no = true; } )?
    352354    ( <QUESTION> { yes = true; } )?
    353     { return Condition.create(key, not, yes, context); }
     355    { return Condition.create(key, not, yes, no, context); }
    354356}
    355357
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r6512 r6513  
    1010import org.openstreetmap.josm.data.osm.Tag;
    1111import org.openstreetmap.josm.data.osm.Way;
     12import org.openstreetmap.josm.tools.TextTagParser;
    1213
    1314import java.io.StringReader;
     
    5556
    5657    OsmPrimitive createPrimitiveForAssertion(String assertion) {
    57         final String[] x = assertion.split("\\s+");
     58        final String[] x = assertion.split("\\s+", 2);
    5859        final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0])
    5960                ? new Node()
     
    6667            throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]);
    6768        }
    68         for (int i = 1; i < x.length; i++) {
    69             final Tag tag = Tag.ofString(x[i]);
    70             p.put(tag.getKey(), tag.getValue());
     69        for (final Map.Entry<String, String> i : TextTagParser.getValidatedTagsFromText(x[1]).entrySet()) {
     70            p.put(i.getKey(), i.getValue());
    7171        }
    7272        return p;
     
    9595        for (final MapCSSTagChecker.TagCheck check : c.checks) {
    9696            for (final Map.Entry<String, Boolean> i : check.assertions.entrySet()) {
    97                 if (check.matchesPrimitive(createPrimitiveForAssertion(i.getKey())) != i.getValue()) {
    98                     final String error = "Expecting test '" + check.getMessage() + "' to " + (i.getValue() ? "" : "not ") + "match " + i.getKey();
     97                final OsmPrimitive p = createPrimitiveForAssertion(i.getKey());
     98                if (check.matchesPrimitive(p) != i.getValue()) {
     99                    final String error = "Expecting test '" + check.getMessage() + "' to " + (i.getValue() ? "" : "not ") + "match " + i.getKey() + ", i.e., " + p.getKeys();
    99100                    System.err.println(error);
    100101                    assertionErrors.add(error);
Note: See TracChangeset for help on using the changeset viewer.