Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r7099 r7167 3 3 4 4 import java.text.MessageFormat; 5 import java.util.Arrays; 5 6 import java.util.EnumSet; 6 7 import java.util.Objects; … … 95 96 return REGEX.equals(this) ? contains : !contains; 96 97 case ONE_OF: 97 String[] parts = testString.split(";"); 98 for (String part : parts) { 99 if (Objects.equals(prototypeString, part.trim())) 100 return true; 101 } 102 return false; 98 return Arrays.asList(testString.split("\\s*;\\s*")).contains(prototypeString); 103 99 case BEGINS_WITH: 104 100 return testString.startsWith(prototypeString); -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.groovy
r7166 r7167 122 122 123 123 @Test 124 public void testBeginsEndsWithCondition() throws Exception { 125 def condition = (Condition.KeyValueCondition) getParser('[foo ^= bar]').condition(Condition.Context.PRIMITIVE) 126 assert Condition.Op.BEGINS_WITH.equals(condition.op) 127 assert condition.applies(getEnvironment("foo", "bar123")) 128 assert !condition.applies(getEnvironment("foo", "123bar")) 129 assert !condition.applies(getEnvironment("foo", "123bar123")) 130 condition = (Condition.KeyValueCondition) getParser('[foo $= bar]').condition(Condition.Context.PRIMITIVE) 131 assert Condition.Op.ENDS_WITH.equals(condition.op) 132 assert !condition.applies(getEnvironment("foo", "bar123")) 133 assert condition.applies(getEnvironment("foo", "123bar")) 134 assert !condition.applies(getEnvironment("foo", "123bar123")) 135 } 136 137 @Test 138 public void testOneOfCondition() throws Exception { 139 def condition = getParser('[vending~=stamps]').condition(Condition.Context.PRIMITIVE) 140 assert condition.applies(getEnvironment("vending", "stamps")) 141 assert condition.applies(getEnvironment("vending", "bar;stamps;foo")) 142 assert !condition.applies(getEnvironment("vending", "every;thing;else")) 143 assert !condition.applies(getEnvironment("vending", "or_nothing")) 144 } 145 146 @Test 124 147 public void testStandardKeyCondition() throws Exception { 125 148 def c1 = (Condition.KeyCondition) getParser("[ highway ]").condition(Condition.Context.PRIMITIVE)
Note:
See TracChangeset
for help on using the changeset viewer.