Ignore:
Timestamp:
2016-08-18T03:39:22+02:00 (3 years ago)
Author:
Don-vip
Message:

see #11924 - extract MapCSS conditions to new class ConditionFactory (on the same model than ExpressionFactory) - should workaround Groovy bug with Java 9 (https://issues.apache.org/jira/browse/GROOVY-7879 ?)

File:
1 edited

Legend:

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

    r10193 r10837  
    1414import org.openstreetmap.josm.gui.mappaint.Environment
    1515import org.openstreetmap.josm.gui.mappaint.MultiCascade
     16import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.ClassCondition
     17import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyCondition
     18import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyMatchType
     19import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyValueCondition
     20import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.Op
     21import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.PseudoClassCondition
     22import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.SimpleKeyValueCondition
    1623import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
    1724import org.openstreetmap.josm.tools.ColorHelper
     
    5057    public void testClassCondition() throws Exception {
    5158        def conditions = ((Selector.GeneralSelector) getParser("way[name=X].highway:closed").selector()).conds
    52         assert conditions.get(0) instanceof Condition.SimpleKeyValueCondition
     59        assert conditions.get(0) instanceof SimpleKeyValueCondition
    5360        assert conditions.get(0).applies(getEnvironment("name", "X"))
    54         assert conditions.get(1) instanceof Condition.ClassCondition
    55         assert conditions.get(2) instanceof Condition.PseudoClassCondition
     61        assert conditions.get(1) instanceof ClassCondition
     62        assert conditions.get(2) instanceof PseudoClassCondition
    5663        assert !conditions.get(2).applies(getEnvironment("name", "X"))
    5764    }
     
    93100    @Test
    94101    public void testEqualCondition() throws Exception {
    95         def condition = (Condition.SimpleKeyValueCondition) getParser("[surface=paved]").condition(Condition.Context.PRIMITIVE)
    96         assert condition instanceof Condition.SimpleKeyValueCondition
     102        def condition = (SimpleKeyValueCondition) getParser("[surface=paved]").condition(Condition.Context.PRIMITIVE)
     103        assert condition instanceof SimpleKeyValueCondition
    97104        assert "surface".equals(condition.k)
    98105        assert "paved".equals(condition.v)
     
    103110    @Test
    104111    public void testNotEqualCondition() throws Exception {
    105         def condition = (Condition.KeyValueCondition) getParser("[surface!=paved]").condition(Condition.Context.PRIMITIVE)
    106         assert Condition.Op.NEQ.equals(condition.op)
     112        def condition = (KeyValueCondition) getParser("[surface!=paved]").condition(Condition.Context.PRIMITIVE)
     113        assert Op.NEQ.equals(condition.op)
    107114        assert !condition.applies(getEnvironment("surface", "paved"))
    108115        assert condition.applies(getEnvironment("surface", "unpaved"))
     
    111118    @Test
    112119    public void testRegexCondition() throws Exception {
    113         def condition = (Condition.KeyValueCondition) getParser("[surface=~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
    114         assert Condition.Op.REGEX.equals(condition.op)
     120        def condition = (KeyValueCondition) getParser("[surface=~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
     121        assert Op.REGEX.equals(condition.op)
    115122        assert condition.applies(getEnvironment("surface", "unpaved"))
    116123        assert !condition.applies(getEnvironment("surface", "grass"))
     
    119126    @Test
    120127    public void testRegexConditionParenthesis() throws Exception {
    121         def condition = (Condition.KeyValueCondition) getParser("[name =~ /^\\(foo\\)/]").condition(Condition.Context.PRIMITIVE)
     128        def condition = (KeyValueCondition) getParser("[name =~ /^\\(foo\\)/]").condition(Condition.Context.PRIMITIVE)
    122129        assert condition.applies(getEnvironment("name", "(foo)"))
    123130        assert !condition.applies(getEnvironment("name", "foo"))
     
    127134    @Test
    128135    public void testNegatedRegexCondition() throws Exception {
    129         def condition = (Condition.KeyValueCondition) getParser("[surface!~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
    130         assert Condition.Op.NREGEX.equals(condition.op)
     136        def condition = (KeyValueCondition) getParser("[surface!~/paved|unpaved/]").condition(Condition.Context.PRIMITIVE)
     137        assert Op.NREGEX.equals(condition.op)
    131138        assert !condition.applies(getEnvironment("surface", "unpaved"))
    132139        assert condition.applies(getEnvironment("surface", "grass"))
     
    135142    @Test
    136143    public void testBeginsEndsWithCondition() throws Exception {
    137         def condition = (Condition.KeyValueCondition) getParser('[foo ^= bar]').condition(Condition.Context.PRIMITIVE)
    138         assert Condition.Op.BEGINS_WITH.equals(condition.op)
     144        def condition = (KeyValueCondition) getParser('[foo ^= bar]').condition(Condition.Context.PRIMITIVE)
     145        assert Op.BEGINS_WITH.equals(condition.op)
    139146        assert condition.applies(getEnvironment("foo", "bar123"))
    140147        assert !condition.applies(getEnvironment("foo", "123bar"))
    141148        assert !condition.applies(getEnvironment("foo", "123bar123"))
    142         condition = (Condition.KeyValueCondition) getParser('[foo $= bar]').condition(Condition.Context.PRIMITIVE)
    143         assert Condition.Op.ENDS_WITH.equals(condition.op)
     149        condition = (KeyValueCondition) getParser('[foo $= bar]').condition(Condition.Context.PRIMITIVE)
     150        assert Op.ENDS_WITH.equals(condition.op)
    144151        assert !condition.applies(getEnvironment("foo", "bar123"))
    145152        assert condition.applies(getEnvironment("foo", "123bar"))
     
    158165    @Test
    159166    public void testStandardKeyCondition() throws Exception {
    160         def c1 = (Condition.KeyCondition) getParser("[ highway ]").condition(Condition.Context.PRIMITIVE)
    161         assert Condition.KeyMatchType.EQ.equals(c1.matchType)
     167        def c1 = (KeyCondition) getParser("[ highway ]").condition(Condition.Context.PRIMITIVE)
     168        assert KeyMatchType.EQ.equals(c1.matchType)
    162169        assert c1.applies(getEnvironment("highway", "unclassified"))
    163170        assert !c1.applies(getEnvironment("railway", "rail"))
    164         def c2 = (Condition.KeyCondition) getParser("[\"/slash/\"]").condition(Condition.Context.PRIMITIVE)
    165         assert Condition.KeyMatchType.EQ.equals(c2.matchType)
     171        def c2 = (KeyCondition) getParser("[\"/slash/\"]").condition(Condition.Context.PRIMITIVE)
     172        assert KeyMatchType.EQ.equals(c2.matchType)
    166173        assert c2.applies(getEnvironment("/slash/", "yes"))
    167174        assert !c2.applies(getEnvironment("\"slash\"", "no"))
     
    170177    @Test
    171178    public void testYesNoKeyCondition() throws Exception {
    172         def c1 = (Condition.KeyCondition) getParser("[oneway?]").condition(Condition.Context.PRIMITIVE)
    173         def c2 = (Condition.KeyCondition) getParser("[oneway?!]").condition(Condition.Context.PRIMITIVE)
    174         def c3 = (Condition.KeyCondition) getParser("[!oneway?]").condition(Condition.Context.PRIMITIVE)
    175         def c4 = (Condition.KeyCondition) getParser("[!oneway?!]").condition(Condition.Context.PRIMITIVE)
     179        def c1 = (KeyCondition) getParser("[oneway?]").condition(Condition.Context.PRIMITIVE)
     180        def c2 = (KeyCondition) getParser("[oneway?!]").condition(Condition.Context.PRIMITIVE)
     181        def c3 = (KeyCondition) getParser("[!oneway?]").condition(Condition.Context.PRIMITIVE)
     182        def c4 = (KeyCondition) getParser("[!oneway?!]").condition(Condition.Context.PRIMITIVE)
    176183        def yes = getEnvironment("oneway", "yes")
    177184        def no = getEnvironment("oneway", "no")
     
    193200    @Test
    194201    public void testRegexKeyCondition() throws Exception {
    195         def c1 = (Condition.KeyCondition) getParser("[/.*:(backward|forward)\$/]").condition(Condition.Context.PRIMITIVE)
    196         assert Condition.KeyMatchType.REGEX.equals(c1.matchType)
     202        def c1 = (KeyCondition) getParser("[/.*:(backward|forward)\$/]").condition(Condition.Context.PRIMITIVE)
     203        assert KeyMatchType.REGEX.equals(c1.matchType)
    197204        assert !c1.applies(getEnvironment("lanes", "3"))
    198205        assert c1.applies(getEnvironment("lanes:forward", "3"))
     
    214221    @Test
    215222    public void testKeyKeyCondition() throws Exception {
    216         def c1 = (Condition.KeyValueCondition) getParser("[foo = *bar]").condition(Condition.Context.PRIMITIVE)
     223        def c1 = (KeyValueCondition) getParser("[foo = *bar]").condition(Condition.Context.PRIMITIVE)
    217224        def w1 = new Way()
    218225        w1.put("foo", "123")
     
    221228        w1.put("bar", "123")
    222229        assert c1.applies(new Environment(w1))
    223         def c2 = (Condition.KeyValueCondition) getParser("[foo =~ */bar/]").condition(Condition.Context.PRIMITIVE)
     230        def c2 = (KeyValueCondition) getParser("[foo =~ */bar/]").condition(Condition.Context.PRIMITIVE)
    224231        def w2 = new Way(w1)
    225232        w2.put("bar", "[0-9]{3}")
Note: See TracChangeset for help on using the changeset viewer.