Search in sources :

Example 11 with Element

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"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 12 with Element

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());
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 13 with Element

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());
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 14 with Element

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());
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 15 with Element

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);
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Aggregations

Element (uk.me.parabola.mkgmap.reader.osm.Element)94 Test (org.junit.Test)75 Way (uk.me.parabola.mkgmap.reader.osm.Way)48 GType (uk.me.parabola.mkgmap.reader.osm.GType)25 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)23 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)15 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)8 ArrayList (java.util.ArrayList)7 Node (uk.me.parabola.mkgmap.reader.osm.Node)7 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)7 Coord (uk.me.parabola.imgfmt.app.Coord)5 StringStyleFileLoader (func.lib.StringStyleFileLoader)4 Map (java.util.Map)4 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)4 TypeResult (uk.me.parabola.mkgmap.reader.osm.TypeResult)4 HashMap (java.util.HashMap)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Area (uk.me.parabola.imgfmt.app.Area)2