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

Last change on this file since 7068 was 7068, checked in by Don-vip, 10 years ago

test cleanup

  • 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.create("a key", "a value", Op.EQ, Context.PRIMITIVE)
50
51 c = Condition.create("role", "a role", Op.EQ, Context.LINK)
52 c = Condition.create("RoLe", "a role", Op.EQ, Context.LINK)
53
54 shouldFail(MapCSSException) {
55 c = Condition.create("an arbitry tag", "a role", Op.EQ, Context.LINK)
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)
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).withLinkContext()
81
82 Condition cond = Condition.create("role", "my_role", Op.NEQ, Context.LINK)
83 assert !cond.applies(e)
84
85 cond = Condition.create("role", "another_role", Op.NEQ, Context.LINK)
86 assert cond.applies(e)
87 }
88
89
90
91}
92
Note: See TracBrowser for help on using the repository browser.