Search in sources :

Example 6 with Rule

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

the class ActionReaderTest method testApplyWithSubst.

/**
 * When an apply statement runs, then substitutions on the value use
 * the tags of the relation and not of the sub element.
 */
@Test
public void testApplyWithSubst() {
    List<Action> actions = readActionsFromString("{apply {" + "add route='${route_no}';" + "}}");
    Relation rel = makeRelation();
    rel.addTag("route_no", "66");
    Element el1 = rel.getElements().get(0).getValue();
    el1.addTag("route_no", "42");
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    assertEquals("route_no taken from relation tags", "66", el1.getTag("route"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 7 with Rule

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

the class ActionReaderTest method stdElementRun.

private Element stdElementRun(List<Action> actions) {
    Rule rule = new ActionRule(null, actions);
    Element el = makeElement();
    rule.resolveType(el, TypeResult.NULL_RESULT);
    return el;
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule)

Example 8 with Rule

use of uk.me.parabola.mkgmap.reader.osm.Rule 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 9 with Rule

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

the class ActionReaderTest method testDoubleName.

/**
 * Test with two name actions.  This works just the same as having several
 * name options on the same name command, in that it is still the
 * first one to match that counts.
 */
@Test
public void testDoubleName() {
    List<Action> actions = readActionsFromString("{name '${name} (${ref})' |" + "  '${ref}' | '${name}' ; " + " name 'fred';}");
    // Something that matches nothing in the first name command.
    Element el = makeElement();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(el, TypeResult.NULL_RESULT);
    assertEquals("no tags, second action matches", "fred", el.getName());
    el = makeElement();
    el.addTag("ref", "A1");
    rule.resolveType(el, TypeResult.NULL_RESULT);
    assertEquals("just a ref tag", "A1", el.getName());
    el = makeElement();
    el.addTag("ref", "A1");
    el.addTag("name", "Main St");
    rule.resolveType(el, TypeResult.NULL_RESULT);
    assertEquals("ref and name", "Main St (A1)", el.getName());
}
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 10 with Rule

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

the class ActionReaderTest method testAlternatives.

@Test
public void testAlternatives() {
    List<Action> actions = readActionsFromString("{set fred = '${park}' | 'default value'}");
    Element el = makeElement();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(el, TypeResult.NULL_RESULT);
    assertEquals("first alternative", "no", 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)

Aggregations

Rule (uk.me.parabola.mkgmap.reader.osm.Rule)12 Element (uk.me.parabola.mkgmap.reader.osm.Element)8 Test (org.junit.Test)7 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)7 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)3 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)3 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)1 AbstractBinaryOp (uk.me.parabola.mkgmap.osmstyle.eval.AbstractBinaryOp)1 AbstractOp (uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp)1 LinkedBinaryOp (uk.me.parabola.mkgmap.osmstyle.eval.LinkedBinaryOp)1 LinkedOp (uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp)1 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)1 WatchableTypeResult (uk.me.parabola.mkgmap.reader.osm.WatchableTypeResult)1 Way (uk.me.parabola.mkgmap.reader.osm.Way)1