Changeset 14796 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2019-02-20T23:16:24+01:00 (6 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r14540 r14796 326 326 "}")); 327 327 } 328 329 /** 330 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/17358">Bug #17358</a>. 331 * @throws ParseException if an error occurs 332 */ 333 @Test 334 @Ignore("not fixed yet") 335 public void testTicket17358() throws ParseException { 336 final Collection<TestError> errors = buildTagChecker( 337 "*[/^name/=~/Test/]{" + 338 " throwWarning: \"Key value match\";" + 339 "}").getErrorsForPrimitive(OsmUtils.createPrimitive("way name=Test St"), false); 340 assertEquals(1, errors.size()); 341 } 328 342 } -
trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java
r14489 r14796 6 6 import static org.junit.Assert.assertNull; 7 7 import static org.junit.Assert.assertTrue; 8 import static org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context.PRIMITIVE; 8 9 9 10 import java.awt.Color; … … 26 27 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op; 27 28 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClassCondition; 29 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.RegexpKeyValueRegexpCondition; 28 30 import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition; 29 31 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector; 30 32 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 33 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; 31 34 import org.openstreetmap.josm.testutils.JOSMTestRules; 32 35 import org.openstreetmap.josm.tools.ColorHelper; … … 109 112 @Test 110 113 public void testEqualCondition() throws Exception { 111 Condition condition = getParser("[surface=paved]").condition( Condition.Context.PRIMITIVE);114 Condition condition = getParser("[surface=paved]").condition(PRIMITIVE); 112 115 assertTrue(condition instanceof SimpleKeyValueCondition); 113 116 assertEquals("surface", ((SimpleKeyValueCondition) condition).k); … … 119 122 @Test 120 123 public void testNotEqualCondition() throws Exception { 121 KeyValueCondition condition = (KeyValueCondition) getParser("[surface!=paved]").condition( Condition.Context.PRIMITIVE);124 KeyValueCondition condition = (KeyValueCondition) getParser("[surface!=paved]").condition(PRIMITIVE); 122 125 assertEquals(Op.NEQ, condition.op); 123 126 assertFalse(condition.applies(getEnvironment("surface", "paved"))); … … 127 130 @Test 128 131 public void testRegexCondition() throws Exception { 129 KeyValueCondition condition = (KeyValueCondition) getParser("[surface=~/paved|unpaved/]").condition( Condition.Context.PRIMITIVE);132 KeyValueCondition condition = (KeyValueCondition) getParser("[surface=~/paved|unpaved/]").condition(PRIMITIVE); 130 133 assertEquals(Op.REGEX, condition.op); 131 134 assertTrue(condition.applies(getEnvironment("surface", "unpaved"))); … … 135 138 @Test 136 139 public void testRegexConditionParenthesis() throws Exception { 137 KeyValueCondition condition = (KeyValueCondition) getParser("[name =~ /^\\(foo\\)/]").condition( Condition.Context.PRIMITIVE);140 KeyValueCondition condition = (KeyValueCondition) getParser("[name =~ /^\\(foo\\)/]").condition(PRIMITIVE); 138 141 assertTrue(condition.applies(getEnvironment("name", "(foo)"))); 139 142 assertFalse(condition.applies(getEnvironment("name", "foo"))); … … 143 146 @Test 144 147 public void testNegatedRegexCondition() throws Exception { 145 KeyValueCondition condition = (KeyValueCondition) getParser("[surface!~/paved|unpaved/]").condition( Condition.Context.PRIMITIVE);148 KeyValueCondition condition = (KeyValueCondition) getParser("[surface!~/paved|unpaved/]").condition(PRIMITIVE); 146 149 assertEquals(Op.NREGEX, condition.op); 147 150 assertFalse(condition.applies(getEnvironment("surface", "unpaved"))); … … 151 154 @Test 152 155 public void testBeginsEndsWithCondition() throws Exception { 153 KeyValueCondition condition = (KeyValueCondition) getParser("[foo ^= bar]").condition( Condition.Context.PRIMITIVE);156 KeyValueCondition condition = (KeyValueCondition) getParser("[foo ^= bar]").condition(PRIMITIVE); 154 157 assertEquals(Op.BEGINS_WITH, condition.op); 155 158 assertTrue(condition.applies(getEnvironment("foo", "bar123"))); 156 159 assertFalse(condition.applies(getEnvironment("foo", "123bar"))); 157 160 assertFalse(condition.applies(getEnvironment("foo", "123bar123"))); 158 condition = (KeyValueCondition) getParser("[foo $= bar]").condition( Condition.Context.PRIMITIVE);161 condition = (KeyValueCondition) getParser("[foo $= bar]").condition(PRIMITIVE); 159 162 assertEquals(Op.ENDS_WITH, condition.op); 160 163 assertFalse(condition.applies(getEnvironment("foo", "bar123"))); … … 165 168 @Test 166 169 public void testOneOfCondition() throws Exception { 167 Condition condition = getParser("[vending~=stamps]").condition( Condition.Context.PRIMITIVE);170 Condition condition = getParser("[vending~=stamps]").condition(PRIMITIVE); 168 171 assertTrue(condition.applies(getEnvironment("vending", "stamps"))); 169 172 assertTrue(condition.applies(getEnvironment("vending", "bar;stamps;foo"))); … … 174 177 @Test 175 178 public void testStandardKeyCondition() throws Exception { 176 KeyCondition c1 = (KeyCondition) getParser("[ highway ]").condition( Condition.Context.PRIMITIVE);179 KeyCondition c1 = (KeyCondition) getParser("[ highway ]").condition(PRIMITIVE); 177 180 assertEquals(KeyMatchType.EQ, c1.matchType); 178 181 assertTrue(c1.applies(getEnvironment("highway", "unclassified"))); 179 182 assertFalse(c1.applies(getEnvironment("railway", "rail"))); 180 KeyCondition c2 = (KeyCondition) getParser("[\"/slash/\"]").condition( Condition.Context.PRIMITIVE);183 KeyCondition c2 = (KeyCondition) getParser("[\"/slash/\"]").condition(PRIMITIVE); 181 184 assertEquals(KeyMatchType.EQ, c2.matchType); 182 185 assertTrue(c2.applies(getEnvironment("/slash/", "yes"))); … … 186 189 @Test 187 190 public void testYesNoKeyCondition() throws Exception { 188 KeyCondition c1 = (KeyCondition) getParser("[oneway?]").condition( Condition.Context.PRIMITIVE);189 KeyCondition c2 = (KeyCondition) getParser("[oneway?!]").condition( Condition.Context.PRIMITIVE);190 KeyCondition c3 = (KeyCondition) getParser("[!oneway?]").condition( Condition.Context.PRIMITIVE);191 KeyCondition c4 = (KeyCondition) getParser("[!oneway?!]").condition( Condition.Context.PRIMITIVE);191 KeyCondition c1 = (KeyCondition) getParser("[oneway?]").condition(PRIMITIVE); 192 KeyCondition c2 = (KeyCondition) getParser("[oneway?!]").condition(PRIMITIVE); 193 KeyCondition c3 = (KeyCondition) getParser("[!oneway?]").condition(PRIMITIVE); 194 KeyCondition c4 = (KeyCondition) getParser("[!oneway?!]").condition(PRIMITIVE); 192 195 Environment yes = getEnvironment("oneway", "yes"); 193 196 Environment no = getEnvironment("oneway", "no"); … … 209 212 @Test 210 213 public void testRegexKeyCondition() throws Exception { 211 KeyCondition c1 = (KeyCondition) getParser("[/.*:(backward|forward)$/]").condition( Condition.Context.PRIMITIVE);214 KeyCondition c1 = (KeyCondition) getParser("[/.*:(backward|forward)$/]").condition(PRIMITIVE); 212 215 assertEquals(KeyMatchType.REGEX, c1.matchType); 213 216 assertFalse(c1.applies(getEnvironment("lanes", "3"))); … … 215 218 assertTrue(c1.applies(getEnvironment("lanes:backward", "3"))); 216 219 assertFalse(c1.applies(getEnvironment("lanes:foobar", "3"))); 220 } 221 222 @Test 223 public void testRegexKeyValueRegexpCondition() throws Exception { 224 RegexpKeyValueRegexpCondition c1 = (RegexpKeyValueRegexpCondition) getParser("[/^name/=~/Test/]").condition(PRIMITIVE); 225 assertEquals("^name", c1.keyPattern.pattern()); 226 assertEquals("Test", c1.pattern.pattern()); 227 assertTrue(c1.applies(getEnvironment("name", "Test St"))); 228 assertFalse(c1.applies(getEnvironment("alt_name", "Test St"))); 217 229 } 218 230 … … 230 242 @Test 231 243 public void testKeyKeyCondition() throws Exception { 232 KeyValueCondition c1 = (KeyValueCondition) getParser("[foo = *bar]").condition( Condition.Context.PRIMITIVE);244 KeyValueCondition c1 = (KeyValueCondition) getParser("[foo = *bar]").condition(PRIMITIVE); 233 245 Way w1 = new Way(); 234 246 w1.put("foo", "123"); … … 237 249 w1.put("bar", "123"); 238 250 assertTrue(c1.applies(new Environment(w1))); 239 KeyValueCondition c2 = (KeyValueCondition) getParser("[foo =~ */bar/]").condition( Condition.Context.PRIMITIVE);251 KeyValueCondition c2 = (KeyValueCondition) getParser("[foo =~ */bar/]").condition(PRIMITIVE); 240 252 Way w2 = new Way(w1); 241 253 w2.put("bar", "[0-9]{3}"); … … 450 462 } 451 463 452 @Test 453 public void testTicket12549() throws Exception { 454 Condition condition = getParser("[name =~ /^(?i)(?u)fóo$/]").condition(Condition.Context.PRIMITIVE); 455 assertTrue(condition.applies(new Environment(OsmUtils.createPrimitive("way name=fóo")))); 456 assertTrue(condition.applies(new Environment(OsmUtils.createPrimitive("way name=fÓo")))); 457 condition = getParser("[name =~ /^(\\p{Lower})+$/]").condition(Condition.Context.PRIMITIVE); 458 assertFalse(condition.applies(new Environment(OsmUtils.createPrimitive("way name=fóo")))); 459 condition = getParser("[name =~ /^(?U)(\\p{Lower})+$/]").condition(Condition.Context.PRIMITIVE); 460 assertTrue(condition.applies(new Environment(OsmUtils.createPrimitive("way name=fóo")))); 461 assertFalse(condition.applies(new Environment(OsmUtils.createPrimitive("way name=fÓo")))); 464 /** 465 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/12549">Bug #12549</a>. 466 * @throws ParseException if a parsing error occurs 467 */ 468 @Test 469 public void testTicket12549() throws ParseException { 470 Condition condition = getParser("[name =~ /^(?i)(?u)fóo$/]").condition(PRIMITIVE); 471 assertTrue(condition.applies(getEnvironment("name", "fóo"))); 472 assertTrue(condition.applies(getEnvironment("name", "fÓo"))); 473 condition = getParser("[name =~ /^(\\p{Lower})+$/]").condition(PRIMITIVE); 474 assertFalse(condition.applies(getEnvironment("name", "fóo"))); 475 condition = getParser("[name =~ /^(?U)(\\p{Lower})+$/]").condition(PRIMITIVE); 476 assertTrue(condition.applies(getEnvironment("name", "fóo"))); 477 assertFalse(condition.applies(getEnvironment("name", "fÓo"))); 462 478 } 463 479
Note:
See TracChangeset
for help on using the changeset viewer.