Search in sources :

Example 6 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.

the class ActionReaderTest method testName.

/**
 * The name action set the element-name (not the 'name' tag).
 * The first value to set it counts, later matches are ignored.
 */
@Test
public void testName() {
    List<Action> actions = readActionsFromString("{name '${name} (${ref})' |" + "  '${ref}' | '${name}' ; }");
    Element el = makeElement();
    el.addTag("name", "Main St");
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(el, TypeResult.NULL_RESULT);
    assertEquals("just name", "Main St", 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 7 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.

the class ActionReaderTest method testRename.

@Test
public void testRename() {
    List<Action> actions = readActionsFromString("{rename park landarea}");
    assertEquals("one action", 1, actions.size());
    Element el = stdElementRun(actions);
    assertNull("park should be gone", el.getTag("park"));
    assertEquals("park renamed", "no", el.getTag("landarea"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Example 8 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action 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 9 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action 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 10 with Action

use of uk.me.parabola.mkgmap.osmstyle.actions.Action in project mkgmap by openstreetmap.

the class ActionReaderTest method testSimpleAdd.

@Test
public void testSimpleAdd() {
    List<Action> actions = readActionsFromString("{add park=yes}");
    assertEquals("one action", 1, actions.size());
    // add does not overwrite existing tags.
    Element el = stdElementRun(actions);
    assertEquals("park not overwritten", "no", el.getTag("park"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Aggregations

Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)18 Element (uk.me.parabola.mkgmap.reader.osm.Element)15 Test (org.junit.Test)13 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)7 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)5 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)3 AddTagAction (uk.me.parabola.mkgmap.osmstyle.actions.AddTagAction)2 DeleteAction (uk.me.parabola.mkgmap.osmstyle.actions.DeleteAction)2 ArrayList (java.util.ArrayList)1 ActionList (uk.me.parabola.mkgmap.osmstyle.actions.ActionList)1 EqualsOp (uk.me.parabola.mkgmap.osmstyle.eval.EqualsOp)1 NotOp (uk.me.parabola.mkgmap.osmstyle.eval.NotOp)1 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)1 ValueOp (uk.me.parabola.mkgmap.osmstyle.eval.ValueOp)1 GetTagFunction (uk.me.parabola.mkgmap.osmstyle.function.GetTagFunction)1 Token (uk.me.parabola.mkgmap.scan.Token)1