Search in sources :

Example 41 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class RuleFileReaderTest method testIsClosedFunction.

@Test
public void testIsClosedFunction() {
    RuleSet rs = makeRuleSet("A=B & is_closed() = true [0x5]");
    Way el = getWayForClosedCompleteCheck(true, true);
    GType type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals(5, type.getType());
    Way el2 = getWayForClosedCompleteCheck(false, true);
    RuleSet rs2 = makeRuleSet("A=B & is_closed() = false [0x5]");
    GType type2 = getFirstType(rs2, el2);
    assertNotNull(type2);
    assertEquals(5, type2.getType());
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 42 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class RuleSetTest method testActionOrder.

/**
 * Check that actions are run in the order given.  Use the add command
 * to set a variable.  The first add that is run will be the value of
 * the variable.
 */
@Test
public void testActionOrder() {
    RuleSet rs = makeRuleSet("b=c {add fred=1}" + "a=b {add fred=2}" + "c=d {add fred=3}" + "a=b [0x1]");
    // All of the conditions are set.
    Way el = new Way(1);
    el.addTag("a", "b");
    el.addTag("b", "c");
    el.addTag("c", "d");
    getFirstType(rs, el);
    assertEquals("b=c was first action", "1", el.getTag("fred"));
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 43 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class RuleSetTest method testAppendInOrder.

/**
 * Append to a variable in the correct order as in the rule set.
 */
@Test
public void testAppendInOrder() {
    RuleSet rs = makeRuleSet("highway=primary {set R='${R} a'}" + "ref=A1 {set R='${R} b'}" + "z=1 {set R='${R} c'}" + "a=1 {set R='${R} d'}");
    Way el = new Way(1);
    el.addTag("R", "init");
    el.addTag("highway", "primary");
    el.addTag("ref", "A1");
    el.addTag("z", "1");
    el.addTag("a", "1");
    getFirstType(rs, el);
    String s = el.getTag("R");
    assertEquals("appended value", "init a b c d", s);
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 44 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class RuleSetTest method testActionVarSetOnExistsRule1.

/**
 * An action variable is set on a rule that starts with an exists clause.
 * We then attempt to match on value that it is
 * @throws Exception
 */
@Test
public void testActionVarSetOnExistsRule1() throws Exception {
    RuleSet rs = makeRuleSet(MAXSPEED_EXAMPLE);
    Way el = new Way(1);
    el.addTag("highway", "primary");
    el.addTag("maxspeed", "40mph");
    el.addTag("ref", "A123");
    el.addTag("name", "Long Lane");
    GType type = getFirstType(rs, el);
    assertEquals("should match first", 1, type.getType());
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 45 with Way

use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.

the class RuleSetTest method testRuleEvaluatedOnce.

/**
 * Rules should only be evaluated once for an element.  Because of the
 * way that we handle rules that may get run after tags are set in actions
 * it is possible that a rule would get run twice if not careful.
 *
 * It is not that easy to trigger, as this is the second attempt at
 * showing it is possible...
 */
@Test
public void testRuleEvaluatedOnce() {
    RuleSet rs = makeRuleSet("highway=primary " + "  {set highway=primary; set result='${result} 1';}" + "highway='primary' {set result='${result} 2'");
    Way el = new Way(1);
    el.addTag("highway", "primary");
    el.addTag("result", "0");
    getFirstType(rs, el);
    assertEquals("rules run once", "0 1 2", el.getTag("result"));
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Aggregations

Way (uk.me.parabola.mkgmap.reader.osm.Way)142 Test (org.junit.Test)94 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)70 GType (uk.me.parabola.mkgmap.reader.osm.GType)60 Element (uk.me.parabola.mkgmap.reader.osm.Element)48 Coord (uk.me.parabola.imgfmt.app.Coord)31 ArrayList (java.util.ArrayList)18 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)12 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)11 List (java.util.List)8 Node (uk.me.parabola.mkgmap.reader.osm.Node)8 HashMap (java.util.HashMap)7 IdentityHashMap (java.util.IdentityHashMap)6 Map (java.util.Map)6 StringStyleFileLoader (func.lib.StringStyleFileLoader)5 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)5 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)5 CoordPOI (uk.me.parabola.mkgmap.reader.osm.CoordPOI)4 RestrictionRelation (uk.me.parabola.mkgmap.reader.osm.RestrictionRelation)4 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)3