source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyValueConditionTest.groovy@ 8206

Last change on this file since 8206 was 8206, checked in by simon04, 9 years ago

fix #10299 - MapCSS index for last element of object

Negative index numbers count from last to first, so >[index=-1] matches the last one.

  • Property svn:eol-style set to native
File size: 2.6 KB
RevLine 
[4069]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import static org.junit.Assert.*
5
6import org.junit.*
[7081]7import org.openstreetmap.josm.JOSMFixture
[4069]8import org.openstreetmap.josm.data.coor.LatLon
9import org.openstreetmap.josm.data.osm.DataSet
10import org.openstreetmap.josm.data.osm.Node
11import org.openstreetmap.josm.data.osm.Relation
12import org.openstreetmap.josm.data.osm.RelationMember
13import org.openstreetmap.josm.gui.mappaint.Environment
14import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context
15import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Op
16
17
18class KeyValueConditionTest {
19
20 def shouldFail = new GroovyTestCase().&shouldFail
[7081]21
[4069]22 def DataSet ds;
[7081]23
[4069]24 @BeforeClass
25 public static void createJOSMFixture(){
26 JOSMFixture.createUnitTestFixture().init()
27 }
[7081]28
[4069]29 @Before
30 public void setUp() {
31 ds = new DataSet()
32 }
[7081]33
[4069]34 def relation(id) {
35 def r = new Relation(id,1)
36 ds.addPrimitive(r)
37 return r
38 }
[7081]39
[4069]40 def node(id) {
41 def n = new Node(id,1)
42 n.setCoor(new LatLon(0,0))
43 ds.addPrimitive(n)
44 return n
45 }
[7081]46
[4069]47 @Test
48 public void create() {
[7081]49 Condition c = Condition.createKeyValueCondition("a key", "a value", Op.EQ, Context.PRIMITIVE, false)
50
51 c = Condition.createKeyValueCondition("role", "a role", Op.EQ, Context.LINK, false)
52 c = Condition.createKeyValueCondition("RoLe", "a role", Op.EQ, Context.LINK, false)
53
[4069]54 shouldFail(MapCSSException) {
[7081]55 c = Condition.createKeyValueCondition("an arbitry tag", "a role", Op.EQ, Context.LINK, false)
[4069]56 }
57 }
[7081]58
[4069]59 @Test
60 public void applies_1() {
61 Relation r = relation(1)
62 Node n = node(1)
63 r.addMember(new RelationMember("my_role", n))
[7081]64
[8206]65 Environment e = new Environment().withPrimitive(n).withParent(r).withLinkContext().withIndex(0, r.membersCount)
[7081]66
[4069]67 Condition cond = new Condition.RoleCondition("my_role", Op.EQ)
[7081]68 assert cond.applies(e)
69
[4069]70 cond = new Condition.RoleCondition("another_role", Op.EQ)
71 assert !cond.applies(e)
72 }
[7081]73
[4069]74 @Test
75 public void applies_2() {
76 Relation r = relation(1)
77 Node n = node(1)
78 r.addMember(new RelationMember("my_role", n))
[7081]79
[8206]80 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0, r.membersCount).withLinkContext()
[7081]81
82 Condition cond = Condition.createKeyValueCondition("role", "my_role", Op.NEQ, Context.LINK, false)
[4069]83 assert !cond.applies(e)
[7081]84
85 cond = Condition.createKeyValueCondition("role", "another_role", Op.NEQ, Context.LINK, false)
[4069]86 assert cond.applies(e)
87 }
88}
Note: See TracBrowser for help on using the repository browser.