source: josm/trunk/test/unit/org/openstreetmap/josm/gui/mappaint/mapcss/KeyConditionTest.groovy@ 9214

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

use LatLon.ZERO instead of new LatLon(0, 0)

  • Property svn:eol-style set to native
File size: 3.2 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
15
16class KeyConditionTest {
17
18 def shouldFail = new GroovyTestCase().&shouldFail
19
20 def DataSet ds;
21
22 @BeforeClass
23 public static void createJOSMFixture(){
24 JOSMFixture.createUnitTestFixture().init()
25 }
26
27 @Before
28 public void setUp() {
29 ds = new DataSet()
30 }
31
32 def relation(id) {
33 def r = new Relation(id,1)
34 ds.addPrimitive(r)
35 return r
36 }
37
38 def node(id) {
39 def n = new Node(id,1)
40 n.setCoor(LatLon.ZERO)
41 ds.addPrimitive(n)
42 return n
43 }
44
45 @Test
46 public void create() {
47
48 // ["a label"]
49 Condition c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.FALSE, Context.PRIMITIVE)
50 // ["a label"?]
51 c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.TRUE, Context.PRIMITIVE)
52 // [!"a label"]
53 c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.FALSE, Context.PRIMITIVE)
54 // [!"a label"?]
55 c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.TRUE, Context.PRIMITIVE)
56
57 // ["a label"]
58 c = Condition.createKeyCondition("a key", false, null, Context.LINK)
59 // [!"a label"]
60 c = Condition.createKeyCondition("a key", true, null, Context.LINK)
61
62 shouldFail(MapCSSException) {
63 // ["a label"?]
64 c = Condition.createKeyCondition("a key", false, Condition.KeyMatchType.TRUE, Context.LINK)
65 }
66
67 shouldFail(MapCSSException) {
68 // [!"a label"?]
69 c = Condition.createKeyCondition("a key", true, Condition.KeyMatchType.TRUE, Context.LINK)
70 }
71 }
72
73 @Test
74 public void applies_1() {
75 Relation r = relation(1)
76 Node n = node(1)
77 r.addMember(new RelationMember("my_role", n))
78
79 Environment e = new Environment(n).withParent(r).withIndex(0, r.membersCount).withLinkContext()
80
81 Condition cond = Condition.createKeyCondition("my_role", false, null, Context.LINK)
82 assert cond.applies(e)
83
84 cond = Condition.createKeyCondition("my_role", true, null, Context.LINK)
85 assert !cond.applies(e)
86 }
87
88 @Test
89 public void applies_2() {
90 Relation r = relation(1)
91 Node n = node(1)
92 r.addMember(new RelationMember("my_role", n))
93
94 Environment e = new Environment(n).withParent(r).withIndex(0, r.membersCount).withLinkContext()
95
96 Condition cond = Condition.createKeyCondition("another_role", false, null, Context.LINK)
97 assert !cond.applies(e)
98
99 cond = Condition.createKeyCondition("another_role", true, null, Context.LINK)
100 assert cond.applies(e)
101 }
102}
Note: See TracBrowser for help on using the repository browser.