Changeset 6512 in josm
- Timestamp:
- 2013-12-22T22:43:24+01:00 (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/validator/deprecated.mapcss
r6506 r6512 4 4 fixAdd: "barrier=fence"; 5 5 fixAdd: "fence_type=chain_link"; 6 assertMatch: "way barrier=wire_fence"; 7 assertNoMatch: "way barrier=fence"; 6 8 } 7 9 -
trunk/src/org/openstreetmap/josm/data/osm/Tag.java
r6506 r6512 105 105 return new Tag(x[0], x[1]); 106 106 } else { 107 throw new IllegalArgumentException(" Stringdoes not contain '='");107 throw new IllegalArgumentException("'" + s + "' does not contain '='"); 108 108 } 109 109 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r6511 r6512 53 53 protected final List<Tag> alternatives = new ArrayList<Tag>(); 54 54 protected final Map<String, Severity> errors = new HashMap<String, Severity>(); 55 protected final Map<String, Boolean> assertions = new HashMap<String, Boolean>(); 55 56 56 57 TagCheck(List<Selector> selector) { … … 82 83 } else if ("suggestAlternative".equals(ai.key) && val != null) { 83 84 check.alternatives.add(val.contains("=") ? Tag.ofString(val) : new Tag(val)); 85 } else if ("assertMatch".equals(ai.key) && val != null) { 86 check.assertions.put(val, true); 87 } else if ("assertNoMatch".equals(ai.key) && val != null) { 88 check.assertions.put(val, false); 84 89 } else { 85 90 throw new RuntimeException("Cannot add instruction " + ai.key + ": " + ai.val + "!"); -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r6506 r6512 6 6 import org.openstreetmap.josm.data.Preferences; 7 7 import org.openstreetmap.josm.data.osm.Node; 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 import org.openstreetmap.josm.data.osm.Relation; 8 10 import org.openstreetmap.josm.data.osm.Tag; 11 import org.openstreetmap.josm.data.osm.Way; 9 12 10 13 import java.io.StringReader; 14 import java.util.LinkedHashSet; 11 15 import java.util.List; 16 import java.util.Map; 12 17 13 18 import static org.hamcrest.CoreMatchers.is; … … 49 54 } 50 55 56 OsmPrimitive createPrimitiveForAssertion(String assertion) { 57 final String[] x = assertion.split("\\s+"); 58 final OsmPrimitive p = "n".equals(x[0]) || "node".equals(x[0]) 59 ? new Node() 60 : "w".equals(x[0]) || "way".equals(x[0]) 61 ? new Way() 62 : "r".equals(x[0]) || "relation".equals(x[0]) 63 ? new Relation() 64 : null; 65 if (p == null) { 66 throw new IllegalArgumentException("Expecting n/node/w/way/r/relation, but got " + x[0]); 67 } 68 for (int i = 1; i < x.length; i++) { 69 final Tag tag = Tag.ofString(x[i]); 70 p.put(tag.getKey(), tag.getValue()); 71 } 72 return p; 73 } 74 75 @Test 76 public void testCreatePrimitiveForAssertion() throws Exception { 77 final OsmPrimitive p = createPrimitiveForAssertion("way name=Foo railway=rail"); 78 assertTrue(p instanceof Way); 79 assertThat(p.keySet().size(), is(2)); 80 assertThat(p.get("name"), is("Foo")); 81 assertThat(p.get("railway"), is("rail")); 82 } 83 84 @Test(expected = IllegalArgumentException.class) 85 public void testCreatePrimitiveForAssertionFail() throws Exception { 86 final OsmPrimitive p = createPrimitiveForAssertion("noway name=Foo"); 87 } 88 51 89 @Test 52 90 public void testInit() throws Exception { 53 91 final MapCSSTagChecker c = new MapCSSTagChecker(); 54 92 c.initialize(); 93 94 LinkedHashSet<String> assertionErrors = new LinkedHashSet<String>(); 95 for (final MapCSSTagChecker.TagCheck check : c.checks) { 96 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(); 99 System.err.println(error); 100 assertionErrors.add(error); 101 } 102 } 103 } 104 assertTrue("not all assertions included in the tests are met", assertionErrors.isEmpty()); 105 55 106 } 56 107 }
Note:
See TracChangeset
for help on using the changeset viewer.