Changeset 6554 in josm for trunk/test/unit/org/openstreetmap


Ignore:
Timestamp:
2013-12-28T01:31:47+01:00 (11 years ago)
Author:
simon04
Message:

see #9414 fix #9409 - extend MapCSS condition syntax to allow the comparison of two key values

The syntax is [key1 = *key2] where * is inspired by the C de-reference operator, and = stands for any of =/!=/~=/^=/$=/*=/=~/!~.

File:
1 edited

Legend:

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

    r6547 r6554  
    106106        assert !c1.applies(getEnvironment("lanes:foobar", "3"))
    107107    }
     108
     109    @Test
     110    public void testKeyKeyCondition() throws Exception {
     111        def c1 = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[foo = *bar]")).condition(Condition.Context.PRIMITIVE)
     112        def w1 = new Way()
     113        w1.put("foo", "123")
     114        w1.put("bar", "456")
     115        assert !c1.applies(new Environment().withPrimitive(w1))
     116        w1.put("bar", "123")
     117        assert c1.applies(new Environment().withPrimitive(w1))
     118        def c2 = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[foo =~ */bar/]")).condition(Condition.Context.PRIMITIVE)
     119        def w2 = new Way(w1)
     120        w2.put("bar", "[0-9]{3}")
     121        assert c2.applies(new Environment().withPrimitive(w2))
     122        w2.put("bar", "[0-9]")
     123        assert c2.applies(new Environment().withPrimitive(w2))
     124        w2.put("bar", "^[0-9]\$")
     125        assert !c2.applies(new Environment().withPrimitive(w2))
     126    }
    108127}
Note: See TracChangeset for help on using the changeset viewer.