Changeset 15071 in josm


Ignore:
Timestamp:
2019-05-11T21:15:10+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17709 - make TurnrestrictionTest aware of conditional restrictions

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/data_nodist/restriction.osm

    r14966 r15071  
    295295  <node id='-138978' action='modify' lat='51.11929761964' lon='14.1607307948' />
    296296  <node id='-138980' action='modify' lat='51.11938242064' lon='14.1607607948' />
     297  <node id='-139147' action='modify' lat='51.12600394515' lon='14.1602059678' />
     298  <node id='-139148' action='modify' lat='51.12545534658' lon='14.15967261709' />
     299  <node id='-139149' action='modify' lat='51.1257203484' lon='14.15988743891' />
     300  <node id='-139150' action='modify' lat='51.12552508405' lon='14.16119859274' />
     301  <node id='-139152' action='modify' lat='51.12608298001' lon='14.1608430256'>
     302    <tag k='name' v='05.4 - no u-turn via way (oneway, conditional)' />
     303  </node>
     304  <node id='-139153' action='modify' lat='51.12589701544' lon='14.16097636327' />
     305  <node id='-139155' action='modify' lat='51.12605520638' lon='14.16056440756' />
    297306  <way id='-138981' timestamp='2009-09-09T15:30:17Z'>
    298307    <nd ref='-112783' />
     
    953962    <nd ref='-138964' />
    954963    <tag k='highway' v='unclassified' />
     964  </way>
     965  <way id='-139151' action='modify'>
     966    <nd ref='-139148' />
     967    <nd ref='-139149' />
     968    <nd ref='-139147' />
     969    <tag k='highway' v='unclassified' />
     970    <tag k='oneway' v='yes' />
     971  </way>
     972  <way id='-139154' action='modify'>
     973    <nd ref='-139147' />
     974    <nd ref='-139155' />
     975    <nd ref='-139152' />
     976    <tag k='highway' v='unclassified' />
     977    <tag k='oneway' v='yes' />
     978  </way>
     979  <way id='-139156' action='modify'>
     980    <nd ref='-139152' />
     981    <nd ref='-139153' />
     982    <nd ref='-139150' />
     983    <tag k='highway' v='unclassified' />
     984    <tag k='oneway' v='yes' />
    955985  </way>
    956986  <relation id='-139094' action='modify' timestamp='2009-09-09T15:30:17Z'>
     
    12821312    <tag k='type' v='restriction' />
    12831313  </relation>
     1314  <relation id='-139207' action='modify'>
     1315    <member type='way' ref='-139151' role='from' />
     1316    <member type='way' ref='-139154' role='via' />
     1317    <member type='way' ref='-139156' role='to' />
     1318    <tag k='name' v='OK 05.4 - no u-turn via way (oneway, conditional)' />
     1319    <tag k='restriction:conditional' v='no_u_turn @ (Mo-Fr 16:00-18:00)' />
     1320    <tag k='type' v='restriction' />
     1321  </relation>
    12841322</osm>
  • trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java

    r14879 r15071  
    3838            /*,"hov","emergency","hazmat","disabled"*/));
    3939
     40    private static final Pattern CONDITIONAL_PATTERN;
     41    static {
     42        final String part = Pattern.compile("([^@\\p{Space}][^@]*?)"
     43                + "\\s*@\\s*" + "(\\([^)\\p{Space}][^)]+?\\)|[^();\\p{Space}][^();]*?)\\s*").toString();
     44        CONDITIONAL_PATTERN = Pattern.compile('(' + part + ")(;\\s*" + part + ")*");
     45    }
     46
    4047    /**
    4148     * Constructs a new {@code ConditionalKeys}.
     
    164171            // <restriction-value> @ <condition>[;<restriction-value> @ <condition>]
    165172            final List<ConditionalValue> r = new ArrayList<>();
    166             final String part = Pattern.compile("([^@\\p{Space}][^@]*?)"
    167                     + "\\s*@\\s*" + "(\\([^)\\p{Space}][^)]+?\\)|[^();\\p{Space}][^();]*?)\\s*").toString();
    168             final Matcher m = Pattern.compile('(' + part + ")(;\\s*" + part + ")*").matcher(value);
     173            final Matcher m = CONDITIONAL_PATTERN.matcher(value);
    169174            if (!m.matches()) {
    170175                throw new ConditionalParsingException(tr("Does not match pattern ''restriction value @ condition''"));
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

    r15019 r15071  
    1616import org.openstreetmap.josm.data.validation.Test;
    1717import org.openstreetmap.josm.data.validation.TestError;
     18import org.openstreetmap.josm.data.validation.tests.ConditionalKeys.ConditionalParsingException;
     19import org.openstreetmap.josm.data.validation.tests.ConditionalKeys.ConditionalValue;
     20import org.openstreetmap.josm.tools.Logging;
    1821
    1922/**
     
    5659    }
    5760
     61    private static boolean hasSupportedRestrictionTag(Relation r) {
     62        if (r.hasTag("restriction", SUPPORTED_RESTRICTIONS))
     63            return true;
     64        String conditionalValue = r.get("restriction:conditional");
     65        if (conditionalValue != null) {
     66            try {
     67                List<ConditionalValue> values = ConditionalValue.parse(conditionalValue);
     68                return !values.isEmpty() && SUPPORTED_RESTRICTIONS.contains(values.get(0).restrictionValue);
     69            } catch (ConditionalParsingException e) {
     70                Logging.trace(e);
     71            }
     72        }
     73        return false;
     74    }
     75
    5876    @Override
    5977    public void visit(Relation r) {
     
    6179            return;
    6280
    63         if (!r.hasTag("restriction", SUPPORTED_RESTRICTIONS)) {
     81        if (!hasSupportedRestrictionTag(r)) {
    6482            errors.add(TestError.builder(this, Severity.ERROR, UNKNOWN_RESTRICTION)
    6583                    .message(tr("Unknown turn restriction"))
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/ConditionalKeysTest.java

    r12568 r15071  
    4747        assertTrue(test.isKeyValid("oneway:backward:conditional"));
    4848        assertTrue(test.isKeyValid("fee:conditional"));
     49        assertTrue(test.isKeyValid("restriction:conditional"));
    4950        assertFalse(test.isKeyValid("maxspeed:hgv:conditional:backward"));
    5051    }
     
    6768        assertFalse(test.isValueValid("motor_vehicle:conditional", "no @ (10:00until18:00 AND length>5)"));
    6869        assertTrue(test.isValueValid("maxspeed:hgv:conditional", "60 @ (weight>7.5)"));
     70        assertTrue(test.isValueValid("restriction:conditional", "no_left_turn @ (Mo-Fr 16:00-18:00)"));
    6971    }
    7072}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/ValidatorTestUtils.java

    r15034 r15071  
    6666                } else if (t.hasKey("name") && namePredicate != null && namePredicate.test(t.getName())) {
    6767                    fail(name + " lacks josm_error_codes tag");
    68                 } else if (t.hasKey("name") && name.startsWith("OK") && !errors.isEmpty()) {
    69                     fail(name + "has unexpected error(s) ");
     68                } else if (t.hasKey("name") && t.get("name").startsWith("OK") && !errors.isEmpty()) {
     69                    fail(name + "has unexpected error(s): " + errors);
    7070                }
    7171            }
Note: See TracChangeset for help on using the changeset viewer.