Ignore:
Timestamp:
2019-08-23T22:53:24+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #18057 - add tag_regex mapcss method to get keys by regex for comparison functions (patch by taylor.smock)

File:
1 edited

Legend:

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

    r15279 r15315  
    1313import java.util.List;
    1414
     15import org.junit.Assert;
    1516import org.junit.Rule;
    1617import org.junit.Test;
     
    263264    }
    264265
     266    /**
     267     * Make certain that getting tags by regex works
     268     * @throws Exception if there is an assert error (or another error)
     269     */
     270    @Test
     271    public void testTagRegex() throws Exception {
     272        DataSet ds = new DataSet();
     273        Way way1 = TestUtils.newWay("old_ref=A1 ref=A2", new Node(new LatLon(1, 1)), new Node(new LatLon(2, 2)));
     274        for (Node node : way1.getNodes()) {
     275            ds.addPrimitive(node);
     276        }
     277        ds.addPrimitive(way1);
     278
     279        tagRegex(way1, "way[ref][count(tag_regex(\"ref\")) > 1] {}", new Boolean[] {true, false, false, true, false});
     280        way1.keySet().stream().forEach(key -> way1.put(key, null));
     281        way1.put("old_ref", "A1");
     282        way1.put("ref", "A2");
     283        tagRegex(way1, "way[ref][count(tag_regex(\"ref\", \"i\")) > 1] {}", new Boolean[] {true, false, false, true, true});
     284    }
     285
     286    private void tagRegex(Way way, String parserString, Boolean[] expected) throws Exception {
     287        Selector selector = getParser(parserString).selector();
     288        Assert.assertEquals(expected[0], selector.matches(new Environment(way)));
     289        way.put("old_ref", null);
     290        Assert.assertEquals(expected[1], selector.matches(new Environment(way)));
     291        way.put("no_match_tag", "false");
     292        Assert.assertEquals(expected[2], selector.matches(new Environment(way)));
     293        way.put("old_ref", "A22");
     294        Assert.assertEquals(expected[3], selector.matches(new Environment(way)));
     295        way.put("old_ref", null);
     296        way.put("OLD_REF", "A23");
     297        Assert.assertEquals(expected[4], selector.matches(new Environment(way)));
     298    }
     299
    265300    @Test
    266301    public void testParentTag() throws Exception {
Note: See TracChangeset for help on using the changeset viewer.