Changeset 17593 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2021-03-20T11:50:06+01:00 (4 years ago)
Author:
simon04
Message:

see #20613 - Split KeyCondition/KeyRegexpCondition

Rewrite patterns for prefix/substring/suffix checks.

5.75->2.93% of allocations in MapCSSTagCheckerPerformanceTest.testCity relate to Pattern matching.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.java

    r17275 r17593  
    22package org.openstreetmap.josm.gui.mappaint.mapcss;
    33
     4import static org.junit.jupiter.api.Assertions.assertEquals;
    45import static org.junit.jupiter.api.Assertions.assertFalse;
    56import static org.junit.jupiter.api.Assertions.assertTrue;
     
    1213import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.Node;
     15import org.openstreetmap.josm.data.osm.OsmUtils;
    1416import org.openstreetmap.josm.data.osm.Relation;
    1517import org.openstreetmap.josm.data.osm.RelationMember;
     
    8284        ConditionFactory.createKeyCondition("a key", true, KeyMatchType.TRUE, Context.PRIMITIVE);
    8385
     86        // [/regex/]
     87        Condition c = ConditionFactory.createKeyCondition("foo|bar", false, KeyMatchType.REGEX, Context.PRIMITIVE);
     88        assertTrue(c.applies(new Environment(OsmUtils.createPrimitive("node BARfooBAZ=true"))));
     89        assertFalse(c.applies(new Environment(OsmUtils.createPrimitive("node BARBAZ=true"))));
     90        c = ConditionFactory.createKeyCondition("colour:", false, KeyMatchType.REGEX, Context.PRIMITIVE);
     91        assertEquals(KeyMatchType.ANY_CONTAINS, ((KeyCondition) c).matchType);
     92        assertEquals("colour:", ((KeyCondition) c).label);
     93        assertTrue(c.applies(new Environment(OsmUtils.createPrimitive("node colour:roof=ref"))));
     94        assertFalse(c.applies(new Environment(OsmUtils.createPrimitive("node foo=bar"))));
     95        c = ConditionFactory.createKeyCondition("^wikipedia:", false, KeyMatchType.REGEX, Context.PRIMITIVE);
     96        assertEquals(KeyMatchType.ANY_STARTS_WITH, ((KeyCondition) c).matchType);
     97        assertEquals("wikipedia:", ((KeyCondition) c).label);
     98        assertTrue(c.applies(new Environment(OsmUtils.createPrimitive("node wikipedia:en=a"))));
     99        assertFalse(c.applies(new Environment(OsmUtils.createPrimitive("node wikipedia=a"))));
     100        c = ConditionFactory.createKeyCondition("_name$", false, KeyMatchType.REGEX, Context.PRIMITIVE);
     101        assertEquals(KeyMatchType.ANY_ENDS_WITH, ((KeyCondition) c).matchType);
     102        assertEquals("_name", ((KeyCondition) c).label);
     103        assertTrue(c.applies(new Environment(OsmUtils.createPrimitive("node alt_name=a"))));
     104        assertFalse(c.applies(new Environment(OsmUtils.createPrimitive("node name=a"))));
     105
    84106        // ["a label"]
    85107        ConditionFactory.createKeyCondition("a key", false, null, Context.LINK);
Note: See TracChangeset for help on using the changeset viewer.