1 | package org.openstreetmap.josm.gui.mappaint.mapcss
|
---|
2 |
|
---|
3 | import org.junit.Test
|
---|
4 | import org.openstreetmap.josm.Main
|
---|
5 | import org.openstreetmap.josm.data.Preferences
|
---|
6 | import org.openstreetmap.josm.data.osm.OsmPrimitive
|
---|
7 | import org.openstreetmap.josm.data.osm.Way
|
---|
8 | import org.openstreetmap.josm.gui.mappaint.Environment
|
---|
9 | import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser
|
---|
10 |
|
---|
11 | class MapCSSParserTest {
|
---|
12 |
|
---|
13 | protected static OsmPrimitive getPrimitive(String key, String value) {
|
---|
14 | def w = new Way()
|
---|
15 | w.put(key, value)
|
---|
16 | return w
|
---|
17 | }
|
---|
18 |
|
---|
19 | @Test
|
---|
20 | public void testEqualCondition() throws Exception {
|
---|
21 | def condition = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[surface=paved]")).condition(Condition.Context.PRIMITIVE)
|
---|
22 | assert condition instanceof Condition.KeyValueCondition
|
---|
23 | assert Condition.Op.EQ.equals(condition.op)
|
---|
24 | assert "surface".equals(condition.k)
|
---|
25 | assert "paved".equals(condition.v)
|
---|
26 | Main.pref = new Preferences()
|
---|
27 | assert condition.applies(new Environment().withPrimitive(getPrimitive("surface", "paved")))
|
---|
28 | assert !condition.applies(new Environment().withPrimitive(getPrimitive("surface", "unpaved")))
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Test
|
---|
32 | public void testNotEqualCondition() throws Exception {
|
---|
33 | def condition = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[surface!=paved]")).condition(Condition.Context.PRIMITIVE)
|
---|
34 | assert condition instanceof Condition.KeyValueCondition
|
---|
35 | assert Condition.Op.NEQ.equals(condition.op)
|
---|
36 | Main.pref = new Preferences()
|
---|
37 | assert !condition.applies(new Environment().withPrimitive(getPrimitive("surface", "paved")))
|
---|
38 | assert condition.applies(new Environment().withPrimitive(getPrimitive("surface", "unpaved")))
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Test
|
---|
42 | public void testRegexCondition() throws Exception {
|
---|
43 | def condition = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[surface=~/paved|unpaved/]")).condition(Condition.Context.PRIMITIVE)
|
---|
44 | assert condition instanceof Condition.KeyValueCondition
|
---|
45 | assert Condition.Op.REGEX.equals(condition.op)
|
---|
46 | Main.pref = new Preferences()
|
---|
47 | assert condition.applies(new Environment().withPrimitive(getPrimitive("surface", "unpaved")))
|
---|
48 | assert !condition.applies(new Environment().withPrimitive(getPrimitive("surface", "grass")))
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Test
|
---|
52 | public void testNegatedRegexCondition() throws Exception {
|
---|
53 | def condition = (Condition.KeyValueCondition) new MapCSSParser(new StringReader("[surface!~/paved|unpaved/]")).condition(Condition.Context.PRIMITIVE)
|
---|
54 | assert condition instanceof Condition.KeyValueCondition
|
---|
55 | assert Condition.Op.NREGEX.equals(condition.op)
|
---|
56 | Main.pref = new Preferences()
|
---|
57 | assert !condition.applies(new Environment().withPrimitive(getPrimitive("surface", "unpaved")))
|
---|
58 | assert condition.applies(new Environment().withPrimitive(getPrimitive("surface", "grass")))
|
---|
59 | }
|
---|
60 | }
|
---|