Ignore:
Timestamp:
2019-02-20T23:16:24+01:00 (6 years ago)
Author:
Don-vip
Message:

see #17358 - add non-regression test (disabled for now)

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  
    326326                "}"));
    327327    }
     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    }
    328342}
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

    r14489 r14796  
    66import static org.junit.Assert.assertNull;
    77import static org.junit.Assert.assertTrue;
     8import static org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context.PRIMITIVE;
    89
    910import java.awt.Color;
     
    2627import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op;
    2728import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClassCondition;
     29import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.RegexpKeyValueRegexpCondition;
    2830import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition;
    2931import org.openstreetmap.josm.gui.mappaint.mapcss.Selector.ChildOrParentSelector;
    3032import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser;
     33import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
    3134import org.openstreetmap.josm.testutils.JOSMTestRules;
    3235import org.openstreetmap.josm.tools.ColorHelper;
     
    109112    @Test
    110113    public void testEqualCondition() throws Exception {
    111         Condition condition = getParser("[surface=paved]").condition(Condition.Context.PRIMITIVE);
     114        Condition condition = getParser("[surface=paved]").condition(PRIMITIVE);
    112115        assertTrue(condition instanceof SimpleKeyValueCondition);
    113116        assertEquals("surface", ((SimpleKeyValueCondition) condition).k);
     
    119122    @Test
    120123    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);
    122125        assertEquals(Op.NEQ, condition.op);
    123126        assertFalse(condition.applies(getEnvironment("surface", "paved")));
     
    127130    @Test
    128131    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);
    130133        assertEquals(Op.REGEX, condition.op);
    131134        assertTrue(condition.applies(getEnvironment("surface", "unpaved")));
     
    135138    @Test
    136139    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);
    138141        assertTrue(condition.applies(getEnvironment("name", "(foo)")));
    139142        assertFalse(condition.applies(getEnvironment("name", "foo")));
     
    143146    @Test
    144147    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);
    146149        assertEquals(Op.NREGEX, condition.op);
    147150        assertFalse(condition.applies(getEnvironment("surface", "unpaved")));
     
    151154    @Test
    152155    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);
    154157        assertEquals(Op.BEGINS_WITH, condition.op);
    155158        assertTrue(condition.applies(getEnvironment("foo", "bar123")));
    156159        assertFalse(condition.applies(getEnvironment("foo", "123bar")));
    157160        assertFalse(condition.applies(getEnvironment("foo", "123bar123")));
    158         condition = (KeyValueCondition) getParser("[foo $= bar]").condition(Condition.Context.PRIMITIVE);
     161        condition = (KeyValueCondition) getParser("[foo $= bar]").condition(PRIMITIVE);
    159162        assertEquals(Op.ENDS_WITH, condition.op);
    160163        assertFalse(condition.applies(getEnvironment("foo", "bar123")));
     
    165168    @Test
    166169    public void testOneOfCondition() throws Exception {
    167         Condition condition = getParser("[vending~=stamps]").condition(Condition.Context.PRIMITIVE);
     170        Condition condition = getParser("[vending~=stamps]").condition(PRIMITIVE);
    168171        assertTrue(condition.applies(getEnvironment("vending", "stamps")));
    169172        assertTrue(condition.applies(getEnvironment("vending", "bar;stamps;foo")));
     
    174177    @Test
    175178    public void testStandardKeyCondition() throws Exception {
    176         KeyCondition c1 = (KeyCondition) getParser("[ highway ]").condition(Condition.Context.PRIMITIVE);
     179        KeyCondition c1 = (KeyCondition) getParser("[ highway ]").condition(PRIMITIVE);
    177180        assertEquals(KeyMatchType.EQ, c1.matchType);
    178181        assertTrue(c1.applies(getEnvironment("highway", "unclassified")));
    179182        assertFalse(c1.applies(getEnvironment("railway", "rail")));
    180         KeyCondition c2 = (KeyCondition) getParser("[\"/slash/\"]").condition(Condition.Context.PRIMITIVE);
     183        KeyCondition c2 = (KeyCondition) getParser("[\"/slash/\"]").condition(PRIMITIVE);
    181184        assertEquals(KeyMatchType.EQ, c2.matchType);
    182185        assertTrue(c2.applies(getEnvironment("/slash/", "yes")));
     
    186189    @Test
    187190    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);
    192195        Environment yes = getEnvironment("oneway", "yes");
    193196        Environment no = getEnvironment("oneway", "no");
     
    209212    @Test
    210213    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);
    212215        assertEquals(KeyMatchType.REGEX, c1.matchType);
    213216        assertFalse(c1.applies(getEnvironment("lanes", "3")));
     
    215218        assertTrue(c1.applies(getEnvironment("lanes:backward", "3")));
    216219        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")));
    217229    }
    218230
     
    230242    @Test
    231243    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);
    233245        Way w1 = new Way();
    234246        w1.put("foo", "123");
     
    237249        w1.put("bar", "123");
    238250        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);
    240252        Way w2 = new Way(w1);
    241253        w2.put("bar", "[0-9]{3}");
     
    450462    }
    451463
    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")));
    462478    }
    463479
Note: See TracChangeset for help on using the changeset viewer.