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, 10 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
Line 
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.*
7import org.openstreetmap.josm.JOSMFixture
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
21
22 def DataSet ds;
23
24 @BeforeClass
25 public static void createJOSMFixture(){
26 JOSMFixture.createUnitTestFixture().init()
27 }
28
29 @Before
30 public void setUp() {
31 ds = new DataSet()
32 }
33
34 def relation(id) {
35 def r = new Relation(id,1)
36 ds.addPrimitive(r)
37 return r
38 }
39
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 }
46
47 @Test
48 public void create() {
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
54 shouldFail(MapCSSException) {
55 c = Condition.createKeyValueCondition("an arbitry tag", "a role", Op.EQ, Context.LINK, false)
56 }
57 }
58
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))
64
65 Environment e = new Environment().withPrimitive(n).withParent(r).withLinkContext().withIndex(0, r.membersCount)
66
67 Condition cond = new Condition.RoleCondition("my_role", Op.EQ)
68 assert cond.applies(e)
69
70 cond = new Condition.RoleCondition("another_role", Op.EQ)
71 assert !cond.applies(e)
72 }
73
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))
79
80 Environment e = new Environment().withPrimitive(n).withParent(r).withIndex(0, r.membersCount).withLinkContext()
81
82 Condition cond = Condition.createKeyValueCondition("role", "my_role", Op.NEQ, Context.LINK, false)
83 assert !cond.applies(e)
84
85 cond = Condition.createKeyValueCondition("role", "another_role", Op.NEQ, Context.LINK, false)
86 assert cond.applies(e)
87 }
88}
Note: See TracBrowser for help on using the repository browser.