Changeset 6592 in josm for trunk


Ignore:
Timestamp:
2014-01-01T15:27:25+01:00 (11 years ago)
Author:
simon04
Message:

fix #8519 - Validator: validate :lanes values

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r6581 r6592  
    3434import org.openstreetmap.josm.data.validation.tests.DuplicatedWayNodes;
    3535import org.openstreetmap.josm.data.validation.tests.Highways;
     36import org.openstreetmap.josm.data.validation.tests.Lanes;
    3637import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker;
    3738import org.openstreetmap.josm.data.validation.tests.MultipolygonTest;
     
    120121        OpeningHourTest.class, // 2901 .. 2999
    121122        MapCSSTagChecker.class, // 3000 .. 3099
     123        Lanes.class, // 3100 .. 3199
    122124    };
    123125   
  • trunk/src/org/openstreetmap/josm/tools/Predicates.java

    r6573 r6592  
    1111
    1212    private Predicates() {
     13    }
     14
     15    /**
     16     * Returns the negation of {@code predicate}.
     17     */
     18    public static <T> Predicate<T> not(final Predicate<T> predicate) {
     19        return new Predicate<T>() {
     20            @Override
     21            public boolean evaluate(T obj) {
     22                return !predicate.evaluate(obj);
     23            }
     24        };
     25    }
     26
     27    /**
     28     * Returns a {@link Predicate} executing {@link Utils#equal}.
     29     */
     30    public static <T> Predicate<T> equalTo(final T ref) {
     31        return new Predicate<T>() {
     32            @Override
     33            public boolean evaluate(T obj) {
     34                return Utils.equal(obj, ref);
     35            }
     36        };
    1337    }
    1438
  • trunk/test/unit/org/openstreetmap/TestUtils.java

    r6562 r6592  
    22package org.openstreetmap;
    33
    4 import org.junit.Ignore;
     4import org.junit.Before;
     5import org.junit.Test;
     6import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.data.osm.Node;
     8import org.openstreetmap.josm.data.osm.OsmPrimitive;
     9import org.openstreetmap.josm.data.osm.Relation;
     10import org.openstreetmap.josm.data.osm.Way;
     11import org.openstreetmap.josm.tools.TextTagParser;
    512
    6 @Ignore
     13import java.util.Map;
     14
     15import static org.hamcrest.CoreMatchers.is;
     16import static org.junit.Assert.assertThat;
     17import static org.junit.Assert.assertTrue;
     18
    719public class TestUtils {
    8     private TestUtils() {
    9     }
    1020
    1121    /**
     
    2030        return testDataRoot.endsWith("/") ? testDataRoot : testDataRoot + "/";
    2131    }
     32
     33    public static OsmPrimitive createPrimitive(String assertion) {
     34        if (Main.pref == null) {
     35            Main.initApplicationPreferences();
     36        }
     37        final String[] x = assertion.split("\\s+", 2);
     38        final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0])
     39                ? new Node()
     40                : "w".equals(x[0]) || "way".equals(x[0])
     41                ? new Way()
     42                : "r".equals(x[0]) || "relation".equals(x[0])
     43                ? new Relation()
     44                : null;
     45        if (p == null) {
     46            throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]);
     47        }
     48        for (final Map.Entry<String, String> i : TextTagParser.readTagsFromText(x[1]).entrySet()) {
     49            p.put(i.getKey(), i.getValue());
     50        }
     51        return p;
     52    }
     53
     54    @Test
     55    public void testCreatePrimitive() throws Exception {
     56        final OsmPrimitive p = createPrimitive("way name=Foo railway=rail");
     57        assertTrue(p instanceof Way);
     58        assertThat(p.keySet().size(), is(2));
     59        assertThat(p.get("name"), is("Foo"));
     60        assertThat(p.get("railway"), is("rail"));
     61    }
    2262}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r6548 r6592  
    33import org.junit.Before;
    44import org.junit.Test;
     5import org.openstreetmap.TestUtils;
    56import org.openstreetmap.josm.Main;
    67import org.openstreetmap.josm.command.ChangePropertyCommand;
     
    6566    }
    6667
    67     OsmPrimitive createPrimitiveForAssertion(String assertion) {
    68         final String[] x = assertion.split("\\s+", 2);
    69         final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0])
    70                 ? new Node()
    71                 : "w".equals(x[0]) || "way".equals(x[0])
    72                 ? new Way()
    73                 : "r".equals(x[0]) || "relation".equals(x[0])
    74                 ? new Relation()
    75                 : null;
    76         if (p == null) {
    77             throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]);
    78         }
    79         for (final Map.Entry<String, String> i : TextTagParser.readTagsFromText(x[1]).entrySet()) {
    80             p.put(i.getKey(), i.getValue());
    81         }
    82         return p;
    83     }
    84 
    85     @Test
    86     public void testCreatePrimitiveForAssertion() throws Exception {
    87         final OsmPrimitive p = createPrimitiveForAssertion("way name=Foo railway=rail");
    88         assertTrue(p instanceof Way);
    89         assertThat(p.keySet().size(), is(2));
    90         assertThat(p.get("name"), is("Foo"));
    91         assertThat(p.get("railway"), is("rail"));
    92     }
    93 
    9468    @Test(expected = IllegalArgumentException.class)
    9569    public void testCreatePrimitiveForAssertionFail() throws Exception {
    96         final OsmPrimitive p = createPrimitiveForAssertion("noway name=Foo");
     70        final OsmPrimitive p = TestUtils.createPrimitive("noway name=Foo");
    9771    }
    9872
     
    10579        for (final MapCSSTagChecker.TagCheck check : c.checks) {
    10680            for (final Map.Entry<String, Boolean> i : check.assertions.entrySet()) {
    107                 final OsmPrimitive p = createPrimitiveForAssertion(i.getKey());
     81                final OsmPrimitive p = TestUtils.createPrimitive(i.getKey());
    10882                if (check.matchesPrimitive(p) != i.getValue()) {
    10983                    final String error = MessageFormat.format("Expecting test ''{0}'' (i.e., {1}) to {2} {3} (i.e., {4})",
Note: See TracChangeset for help on using the changeset viewer.