Search in sources :

Example 11 with Action

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

the class ActionReaderTest method testFreeForm.

/**
 * Test with embedded comment, newlines, semicolon used as separator.
 */
@Test
public void testFreeForm() {
    List<Action> actions = readActionsFromString(" { set web='world wide';" + "set \nribbon = 'yellow' \n# a comment } ");
    assertEquals("number of actions", 2, actions.size());
    Element el = stdElementRun(actions);
    assertEquals("park not overwritten", "no", el.getTag("park"));
    assertEquals("word with spaces", "world wide", el.getTag("web"));
    assertEquals("yellow ribbon", "yellow", el.getTag("ribbon"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Example 12 with Action

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

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

Example 14 with Action

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

the class ActionReaderTest method testMultipleNoSeparators.

@Test
public void testMultipleNoSeparators() {
    List<Action> actions = readActionsFromString("{" + "set park='${notset}' | yes " + "add fred=other " + "set pooh=bear}");
    assertEquals("number of actions", 3, actions.size());
    Element el = stdElementRun(actions);
    assertEquals("park set to yes", "yes", el.getTag("park"));
    assertEquals("fred set", "other", el.getTag("fred"));
    assertEquals("pooh set", "bear", el.getTag("pooh"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Test(org.junit.Test)

Example 15 with Action

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

the class ActionReaderTest method testMultipleCommands.

/**
 * Test several commands in the block.  They should all be executed.
 */
@Test
public void testMultipleCommands() {
    List<Action> actions = readActionsFromString("{set park=yes; add fred=other;" + "set pooh=bear}");
    assertEquals("number of actions", 3, actions.size());
    Element el = stdElementRun(actions);
    assertEquals("park set to yes", "yes", el.getTag("park"));
    assertEquals("fred set", "other", el.getTag("fred"));
    assertEquals("pooh set", "bear", el.getTag("pooh"));
}
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