Ticket #18126: containsV2.patch

File containsV2.patch, 1.9 KB (added by francians, 5 years ago)
  • src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java

    diff --git a/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java b/src/org/openstreetmap/josm/gui/mappaint/mapcss/Functions.java
    index a14810572..d7281c4a8 100644
    a b public final class Functions {  
    11751175    public static boolean at(Environment env, double lat, double lon) { // NO_UCD (unused code)
    11761176        return new LatLon(lat, lon).equalsEpsilon(center(env));
    11771177    }
     1178
     1179    /**
     1180     * Test wheather the list {@code lst} contains the {@code str} element.
     1181     * @param str String
     1182     * @param lst list
     1183     * @return true if {@code str} is contained
     1184     * @since xxx
     1185     */
     1186    public static boolean contains(String str, List<?> lst) { // NO_UCD (unused code)
     1187        for (int i = 0; i < lst.size(); i++) {
     1188            if (lst.get(i).equals(str)) {
     1189                return true;
     1190            }
     1191        }
     1192        return false;
     1193    }
    11781194}
  • test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java b/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSParserTest.java
    index dbb6bdc84..6eb6ca2fb 100644
    a b public class MapCSSParserTest {  
    612612        sheet.loadStyleSource();
    613613        assertTrue(sheet.getErrors().toString(), sheet.getErrors().isEmpty());
    614614    }
     615
     616    @Test
     617    public void testListContains() throws Exception {
     618        Selector s1 = getParser("way[contains(\"x10\", split(\";\", tag(\"ref\")))]").selector();
     619        assertTrue(s1.matches(new Environment(OsmUtils.createPrimitive("way ref=x10;x20"))));
     620        assertFalse(s1.matches(new Environment(OsmUtils.createPrimitive("way ref=x20"))));
     621        assertFalse(s1.matches(new Environment(new Way())));
     622    }
    615623}