Changeset 18451 in josm for trunk/test/unit/org
- Timestamp:
- 2022-05-16T22:24:59+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.java
r17593 r18451 7 7 import static org.junit.jupiter.api.Assertions.fail; 8 8 9 import java.util.ArrayList; 10 import java.util.Collection; 11 import java.util.Collections; 12 import java.util.EnumSet; 13 import java.util.Iterator; 14 import java.util.List; 15 import java.util.regex.Pattern; 16 9 17 import org.junit.jupiter.api.BeforeEach; 10 18 import org.junit.jupiter.api.Test; 11 19 import org.junit.jupiter.api.extension.RegisterExtension; 20 import org.junit.jupiter.params.ParameterizedTest; 21 import org.junit.jupiter.params.provider.EnumSource; 22 import org.openstreetmap.josm.TestUtils; 12 23 import org.openstreetmap.josm.data.coor.LatLon; 13 24 import org.openstreetmap.josm.data.osm.DataSet; … … 17 28 import org.openstreetmap.josm.data.osm.RelationMember; 18 29 import org.openstreetmap.josm.gui.mappaint.Environment; 30 import org.openstreetmap.josm.gui.mappaint.Range; 19 31 import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context; 20 32 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyCondition; … … 149 161 assertTrue(cond.applies(e)); 150 162 } 163 164 /** 165 * Ensure that we are accounting for all necessary {@link ConditionFactory.KeyMatchType} are accounted for. 166 * If this fails, and the key should not be fully matched against (i.e., it is a regex), please modify 167 * {@link MapCSSRuleIndex#findAnyRequiredKey}. 168 * 169 * Non-regression test for JOSM #22073. 170 */ 171 @ParameterizedTest 172 @EnumSource(ConditionFactory.KeyMatchType.class) 173 void testNonRegression22073(final KeyMatchType keyMatchType) { 174 final EnumSet<ConditionFactory.KeyMatchType> current = EnumSet.of(KeyMatchType.EQ, KeyMatchType.FALSE, KeyMatchType.TRUE, 175 KeyMatchType.REGEX, KeyMatchType.ANY_CONTAINS, KeyMatchType.ANY_ENDS_WITH, KeyMatchType.ANY_STARTS_WITH); 176 assertTrue(current.contains(keyMatchType), "Is this type supposed to be matched against a whole key?"); 177 178 final boolean fullKey = EnumSet.of(KeyMatchType.EQ, KeyMatchType.TRUE, KeyMatchType.FALSE).contains(keyMatchType); 179 final MapCSSRuleIndex index = new MapCSSRuleIndex(); 180 final Condition condition = keyMatchType != KeyMatchType.REGEX 181 ? new KeyCondition("highway", false, keyMatchType) 182 : new ConditionFactory.KeyRegexpCondition(Pattern.compile("highway"), false); 183 index.add(new MapCSSRule(Collections.singletonList(new Selector.GeneralSelector("*", Range.ZERO_TO_INFINITY, 184 Collections.singletonList(condition), null)), null)); 185 index.initIndex(); 186 final Node testNode = TestUtils.newNode("highway=traffic_calming"); 187 // First get all the "remaining" candidates by passing a non-tagged node 188 final Collection<MapCSSRule> remaining = convertIterator(index.getRuleCandidates(new Node(LatLon.ZERO))); 189 // Then get all the matches for the test node 190 final Collection<MapCSSRule> matches = convertIterator(index.getRuleCandidates(testNode)); 191 // Finally, remove the remaining rules from the matches 192 matches.removeIf(remaining::contains); 193 assertEquals(fullKey, !matches.isEmpty()); 194 } 195 196 private static <T> Collection<T> convertIterator(Iterator<T> iterator) { 197 final List<T> rList = new ArrayList<>(); 198 iterator.forEachRemaining(rList::add); 199 return rList; 200 } 151 201 }
Note:
See TracChangeset
for help on using the changeset viewer.