Changeset 8874 in josm for trunk/test


Ignore:
Timestamp:
2015-10-14T22:56:14+02:00 (4 years ago)
Author:
simon04
Message:

fix #10467 - MapCSS: allow comparisons in regexp key conditions

File:
1 edited

Legend:

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

    r8415 r8874  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.mappaint.mapcss;
    3 
    4 import static org.junit.Assert.*
    53
    64import org.junit.*
     
    97import org.openstreetmap.josm.data.osm.DataSet
    108import org.openstreetmap.josm.data.osm.Node
     9import org.openstreetmap.josm.data.osm.OsmUtils
    1110import org.openstreetmap.josm.data.osm.Relation
    1211import org.openstreetmap.josm.data.osm.RelationMember
     
    1413import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context
    1514import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Op
     15import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
    1616
    1717
     
    8686        assert cond.applies(e)
    8787    }
     88
     89    @Test
     90    public void testKeyRegexValueRegex() throws Exception {
     91        def selPos = new MapCSSParser(new StringReader("*[/^source/ =~ /.*,.*/]")).selector()
     92        def selNeg = new MapCSSParser(new StringReader("*[/^source/ !~ /.*,.*/]")).selector()
     93        assert !selPos.matches(new Environment(OsmUtils.createPrimitive("way foo=bar")))
     94        assert selPos.matches(new Environment(OsmUtils.createPrimitive("way source=1,2")))
     95        assert selPos.matches(new Environment(OsmUtils.createPrimitive("way source_foo_bar=1,2")))
     96        assert !selPos.matches(new Environment(OsmUtils.createPrimitive("way source=1")))
     97        assert !selPos.matches(new Environment(OsmUtils.createPrimitive("way source=1")))
     98        assert !selNeg.matches(new Environment(OsmUtils.createPrimitive("way source=1,2")))
     99        assert !selNeg.matches(new Environment(OsmUtils.createPrimitive("way foo=bar source=1,2")))
     100        assert selNeg.matches(new Environment(OsmUtils.createPrimitive("way foo=bar source=baz")))
     101        assert selNeg.matches(new Environment(OsmUtils.createPrimitive("way foo=bar src=1,2")))
     102    }
    88103}
Note: See TracChangeset for help on using the changeset viewer.