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

Last change on this file since 14019 was 14019, checked in by Don-vip, 16 months ago

update to Groovy 2.5.0 and Eclipse Photon (4.8.0)

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.mapcss;
3
4import static groovy.test.GroovyAssert.shouldFail
5import static org.junit.Assert.*
6
7import org.junit.*
8import org.openstreetmap.josm.JOSMFixture
9import org.openstreetmap.josm.data.coor.LatLon
10import org.openstreetmap.josm.data.osm.DataSet
11import org.openstreetmap.josm.data.osm.Node
12import org.openstreetmap.josm.data.osm.Relation
13import org.openstreetmap.josm.data.osm.RelationMember
14import org.openstreetmap.josm.gui.mappaint.Environment
15import org.openstreetmap.josm.gui.mappaint.mapcss.Condition.Context
16import org.openstreetmap.josm.gui.mappaint.mapcss.ConditionFactory.KeyMatchType
17
18class KeyConditionTest {
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 = ConditionFactory.createKeyCondition("a key", false, KeyMatchType.FALSE, Context.PRIMITIVE)
50        // ["a label"?]
51        c = ConditionFactory.createKeyCondition("a key", false, KeyMatchType.TRUE, Context.PRIMITIVE)
52        // [!"a label"]
53        c = ConditionFactory.createKeyCondition("a key", true, KeyMatchType.FALSE, Context.PRIMITIVE)
54        // [!"a label"?]
55        c = ConditionFactory.createKeyCondition("a key", true, KeyMatchType.TRUE, Context.PRIMITIVE)
56
57        // ["a label"]
58        c = ConditionFactory.createKeyCondition("a key", false, null, Context.LINK)
59        // [!"a label"]
60        c = ConditionFactory.createKeyCondition("a key", true, null, Context.LINK)
61
62        shouldFail(MapCSSException) {
63            // ["a label"?]
64           c = ConditionFactory.createKeyCondition("a key", false, KeyMatchType.TRUE, Context.LINK)
65        }
66
67        shouldFail(MapCSSException) {
68            // [!"a label"?]
69            c = ConditionFactory.createKeyCondition("a key", true, 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 = ConditionFactory.createKeyCondition("my_role", false, null, Context.LINK)
82        assert cond.applies(e)
83
84        cond = ConditionFactory.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 = ConditionFactory.createKeyCondition("another_role", false, null, Context.LINK)
97        assert !cond.applies(e)
98
99        cond = ConditionFactory.createKeyCondition("another_role", true, null, Context.LINK)
100        assert cond.applies(e)
101    }
102}
Note: See TracBrowser for help on using the repository browser.