Search in sources :

Example 16 with Element

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

the class RuleFileReaderTest method testOptimizeWithOr3.

@Test
public void testOptimizeWithOr3() throws Exception {
    String s = "highway=* &  bridge!=* & " + "   (mtb:scale>0 | mtb:scale='0+' | tracktype ~ 'grade[2-6]' |" + "   sac_scale ~ '.*(mountain|alpine)_hiking' |" + "   sport=via_ferrata) [0x3]";
    RuleSet rs = makeRuleSet(s);
    Element el = new Way(1);
    el.addTag("highway", "primary");
    el.addTag("mtb:scale", "0+");
    GType type = getFirstType(rs, el);
    assertNotNull(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)

Example 17 with Element

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

the class RuleFileReaderTest method testNestedIncludeAndImmediateInclude.

/**
 * Bug when the first statement of an include file is itself an include statement.
 * As luck would have the test tested the supposedly more difficult case of an
 * include statement in the middle of the file.
 */
@Test
public void testNestedIncludeAndImmediateInclude() {
    StyleFileLoader loader = new StringStyleFileLoader(new String[][] { { "lines", "a=1 [0x1] include 'first'; a=2 [0x2]" }, { "first", "include 'second'; b=2 [0x2 ]" }, { "second", "c=1 [0x1] c=2 [0x2 ]" } });
    RuleSet rs = makeRuleSet(loader);
    Element el = new Way(1);
    el.addTag("a", "2");
    GType type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals(2, type.getType());
    el = new Way(2);
    el.addTag("c", "1");
    type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals(1, type.getType());
    el = new Way(2);
    el.addTag("c", "2");
    type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals(2, type.getType());
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) StringStyleFileLoader(func.lib.StringStyleFileLoader) Element(uk.me.parabola.mkgmap.reader.osm.Element) StringStyleFileLoader(func.lib.StringStyleFileLoader) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 18 with Element

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

the class RuleFileReaderTest method testRegexAtTop.

/**
 * Some operations could not originally be used by themselves but now they are converted
 * into expressions that can be handled automatically. The following few tests verify this.
 */
@Test
public void testRegexAtTop() {
    RuleSet rs = makeRuleSet("QUOTA ~ ' [05]00\\.0+' [0x2]");
    Element el = new Way(1);
    el.addTag("QUOTA", " 500.0");
    GType type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals(2, 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 19 with Element

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

the class RuleSetTest method getFirstType.

private GType getFirstType(Rule rs, Element el) {
    final List<GType> types = new ArrayList<GType>();
    rs.resolveType(el, new TypeResult() {

        public void add(Element el, GType type) {
            types.add(type);
        }
    });
    if (types.isEmpty())
        return null;
    else
        return types.get(0);
}
Also used : GType(uk.me.parabola.mkgmap.reader.osm.GType) Element(uk.me.parabola.mkgmap.reader.osm.Element) ArrayList(java.util.ArrayList) TypeResult(uk.me.parabola.mkgmap.reader.osm.TypeResult)

Example 20 with Element

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

the class AddAccessActionTest method testFirstAlternativeMatches.

/**
 * Several alternatives and the first one matches.
 */
@Test
public void testFirstAlternativeMatches() {
    AddAccessAction act = new AddAccessAction("${access}", false);
    act.add("${hello}");
    act.add("${world}");
    Element el = stdElement();
    el.addTag("hello", "hello");
    act.perform(el);
    for (String accessTag : ACCESS_TAGS.keySet()) assertEquals(accessTag + " is set", ACCESSVAL, el.getTag(accessTag));
}
Also used : Element(uk.me.parabola.mkgmap.reader.osm.Element) 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