Changeset 6859 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r6830 r6859 6 6 import java.text.MessageFormat; 7 7 import java.util.EnumSet; 8 import java.util.Set; 8 9 import java.util.regex.Pattern; 9 10 … … 78 79 REGEX, NREGEX, ONE_OF, BEGINS_WITH, ENDS_WITH, CONTAINS; 79 80 81 private static Set<Op> NEGATED_OPS = EnumSet.of(NEQ, NREGEX); 82 80 83 public boolean eval(String testString, String prototypeString) { 81 if (testString == null && this != NEQ)84 if (testString == null && !NEGATED_OPS.contains(this)) 82 85 return false; 83 86 switch (this) { … … 202 205 public boolean applies(Environment env) { 203 206 final String value = env.osm.get(k); 204 return value != null && (op.equals(Op.REGEX) 205 ? pattern.matcher(value).find() 206 : !pattern.matcher(value).find()); 207 if (Op.REGEX.equals(op)) { 208 return value != null && pattern.matcher(value).find(); 209 } else if (Op.NREGEX.equals(op)) { 210 return value == null || !pattern.matcher(value).find(); 211 } else { 212 throw new IllegalStateException(); 213 } 207 214 } 208 215 } -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy
r6774 r6859 166 166 167 167 @Test 168 public void testNRegexKeyConditionSelector() throws Exception { 169 def s1 = getParser("*[sport][tourism != hotel]").selector() 170 assert s1.matches(new Environment().withPrimitive(TestUtils.createPrimitive("node sport=foobar"))) 171 assert !s1.matches(new Environment().withPrimitive(TestUtils.createPrimitive("node sport=foobar tourism=hotel"))) 172 def s2 = getParser("*[sport][tourism != hotel][leisure !~ /^(sports_centre|stadium|)\$/]").selector() 173 assert s2.matches(new Environment().withPrimitive(TestUtils.createPrimitive("node sport=foobar"))) 174 assert !s2.matches(new Environment().withPrimitive(TestUtils.createPrimitive("node sport=foobar tourism=hotel"))) 175 assert !s2.matches(new Environment().withPrimitive(TestUtils.createPrimitive("node sport=foobar leisure=stadium"))) 176 } 177 178 @Test 168 179 public void testKeyKeyCondition() throws Exception { 169 180 def c1 = (Condition.KeyValueCondition) getParser("[foo = *bar]").condition(Condition.Context.PRIMITIVE)
Note:
See TracChangeset
for help on using the changeset viewer.