Skip to content

Commit

Permalink
Fix #23290: Use checks in checkgroups when looking for out-of-region …
Browse files Browse the repository at this point in the history
…tags

Also fix an i18n issue and update a test to use a key that is currently invalid
in a region.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19172 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Aug 7, 2024
1 parent 67b4bd2 commit 9d50ff5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions resources/data/defaultpresets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@
<reference ref="oh_wheelchair" />
</chunk>
<chunk id="toilets">
<check key="toilets" />
<check key="toilets:unisex" />
<combo key="toilets:wheelchair" values="yes,no,limited" values_context="toilets" />
<combo key="toilets:access" values="customers,yes,no" />
<check key="toilets" text="Toilets" />
<check key="toilets:unisex" text="Gender neutral" />
<combo key="toilets:wheelchair" values="yes,no,limited" values_context="toilets" text="Wheelchair accessible" />
<combo key="toilets:access" values="customers,yes,no" text="Access" />
</chunk>
<chunk id="color">
<combo key="colour" text="Color (HTML name or hexadecimal code)" values="black,blue,brown,gray,green,orange,purple,red,silver,white,yellow,#CD853F" values_context="color" />
Expand Down Expand Up @@ -8387,7 +8387,7 @@
<key key="shop" value="agrarian" />
<reference ref="name_oh_wheelchair" />
<optional>
<combo key="agrarian" values="yes,pesticide,fertilizer,seed,feed,tools,machine_parts,agricultural_machinery" values_context="Tag:shop=agrarian" />
<combo key="agrarian" values="yes,pesticide,fertilizer,seed,feed,tools,machine_parts,agricultural_machinery" values_context="Tag:shop=agrarian" text="Products" />
</optional>
<reference ref="link_contact_address_payment" />
</item>
Expand Down
12 changes: 10 additions & 2 deletions src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,14 @@ public static void initializePresets() {
addPresetValue((KeyedItem) i);
} else if (i instanceof CheckGroup) {
for (Check c : ((CheckGroup) i).checks) {
if (!"none".equals(c.match))
minData.add(c);
addPresetValue(c);
}
}
}
if (!minData.isEmpty()) {
presetIndex .put(p, minData);
presetIndex.put(p, minData);
}
}
}
Expand Down Expand Up @@ -854,7 +856,13 @@ private void tagCheckReal(TaggingPreset preset, OsmPrimitive p, LatLon center, R
*/
private static boolean primitiveInRegions(IPrimitive primitive, Collection<String> regions, boolean excludeRegions) {
if (primitive instanceof INode) {
return latLonInRegions((INode) primitive, regions) == excludeRegions;
// 4 options:
// In Region | excluding region | expected
// true | false | true
// true | true | false
// false | false | false
// false | true | true
return latLonInRegions((INode) primitive, regions) != excludeRegions;
} else if (primitive instanceof IWay) {
return ((IWay<?>) primitive).getNodes().stream().anyMatch(n -> primitiveInRegions(n, regions, excludeRegions));
} else if (primitive instanceof IRelation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ void testValueDifferentCase() throws IOException {

@Test
void testRegionKey() throws IOException {
final List<TestError> errors = test(OsmUtils.createPrimitive("node highway=crossing crossing_ref=zebra"));
final List<TestError> errors = test(OsmUtils.createPrimitive("node payment:ep_avant=yes"));
assertEquals(1, errors.size());
assertEquals("Key from a preset is invalid in this region", errors.get(0).getMessage());
assertEquals("Preset Pedestrian Crossing should not have the key crossing_ref", errors.get(0).getDescription());
assertEquals("Preset Payment Methods should not have the key payment:ep_avant", errors.get(0).getDescription());
assertEquals(Severity.WARNING, errors.get(0).getSeverity());
assertFalse(errors.get(0).isFixable());

Expand Down

0 comments on commit 9d50ff5

Please sign in to comment.