use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class ActionReaderTest method testSecondAlternative.
@Test
public void testSecondAlternative() {
List<Action> actions = readActionsFromString("{set fred = '${notset}' | 'default value'}");
Element el = makeElement();
el.addTag("fred", "origvalue");
Rule rule = new ActionRule(null, actions);
rule.resolveType(el, TypeResult.NULL_RESULT);
assertEquals("second alternative", "default value", el.getTag("fred"));
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class RuleFileReaderTest method testComplexExpressions.
/**
* Try out arithmetic comparisons and mixtures of 'and' and 'or'.
*/
@Test
public void testComplexExpressions() {
String str = "a=b & (c=d | e=f) & x>10 [0x1]\n";
RuleSet rs = makeRuleSet(str);
Element el = new Way(1);
el.addTag("a", "b");
el.addTag("c", "d");
el.addTag("x", "11");
GType type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("expression ok", 1, type.getType());
// fails with x less than 10
el.addTag("x", "9");
type = getFirstType(rs, el);
assertNull("x too low", type);
// also fails with x equal to 10
el.addTag("x", "10");
type = getFirstType(rs, el);
assertNull("x too low", type);
// OK with x > 10
el.addTag("x", "100");
el.addTag("e", "f");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("c and e set", 1, type.getType());
el.addTag("c", "");
el.addTag("e", "");
type = getFirstType(rs, el);
assertNull("none of c and e set", type);
el.addTag("e", "f");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("e is set to f", 1, type.getType());
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class RuleFileReaderTest method testLoad.
/**
* Test of a file containing a number of different rules, with varying
* formatting and including comments.
*/
@Test
public void testLoad() {
RuleSet rs = makeRuleSet("highway=footway & type=rough [0x2 level 2]\n" + "highway=footway | highway = path\n" + " [0x3]\n# comment here\n" + "foo=\nbar & bar=two [0x4]\n" + "highway=* & oneway=true [0x6 level 1]\n" + "");
Element el = new Way(1);
el.addTag("highway", "footway");
GType type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("plain footway", "[0x3 level 0]", type.toString());
el.addTag("type", "rough");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("rough footway", "[0x2 level 2]", type.toString());
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class RuleFileReaderTest method testComparasons.
/**
* Test based on email on the mailing list at:
* http://www.mkgmap.org.uk/pipermail/mkgmap-dev/2009q3/003009.html
* See that email for an explanation.
*/
@Test
public void testComparasons() {
String str = "highway=null_null & layer<0 [0x01 resolution 10]\n" + "highway=null_null & layer=0 [0x02 resolution 10]\n" + "highway=null_null & layer>0 [0x03 resolution 10]\n" + "highway=null_null & layer='-1' [0x04 resolution 10]\n" + "highway=null_null & layer='0' [0x05 resolution 10]\n" + "highway=null_null & layer='1' [0x06 resolution 10]\n" + "highway=null_null & layer='+1' [0x07 resolution 10]\n" + "highway=null_null [0x08 resolution 10]";
RuleSet rs = makeRuleSet(str);
// 9902
Element el = new Way(1);
el.addTag("highway", "null_null");
el.addTag("layer", "-1");
GType type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("9902 layer = -1", 0x1, type.getType());
// 9912
el.addTag("layer", "0");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("9912 layer = 0", 0x2, type.getType());
// 9922
el.deleteTag("layer");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("9922 no layer tag", 0x8, type.getType());
// 9932
el.addTag("layer", "1");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("9932 layer is 1", 0x3, type.getType());
// 9952
el.addTag("layer", "+1");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals("9952 layer is +1", 0x3, type.getType());
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class RuleFileReaderTest method testOptimizeWithOr2.
/**
* Test is a simplified version of a rule in the floodblocker style.
*/
@Test
public void testOptimizeWithOr2() {
String s = "highway=*" + "& tunnel!=*" + "& (layer!=* | layer=0)" + " [0x02]\n";
RuleSet rs = makeRuleSet(s);
Element el = new Way(1);
el.addTag("highway", "primary");
GType type = getFirstType(rs, el);
assertNotNull(type);
assertEquals(2, type.getType());
el.addTag("layer", "0");
type = getFirstType(rs, el);
assertNotNull(type);
assertEquals(2, type.getType());
el.addTag("layer", "1");
type = getFirstType(rs, el);
assertNull(type);
}
Aggregations