Search in sources :

Example 66 with Element

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

the class RuleFileReaderTest method testNEAtTop.

@Test(expected = SyntaxException.class)
public void testNEAtTop() {
    RuleSet rs = makeRuleSet("QUOTA != 'fred' [0x2]");
    Element el = new Way(1);
    el.addTag("QUOTA", "tom");
    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 67 with Element

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

the class RuleFileReaderTest method testMultipleActions.

@Test
public void testMultipleActions() {
    String rstr = "highway=footway {add access = no; add foot = yes} [0x16 road_class=0 road_speed=0 resolution 23]";
    RuleSet rs = makeRuleSet(rstr);
    Element el = new Way(1);
    el.addTag("highway", "footway");
    getFirstType(rs, el);
    assertEquals("access set", "no", el.getTag("access"));
    assertEquals("access set", "yes", el.getTag("foot"));
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 68 with Element

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

the class RuleFileReaderTest method getFirstType.

/**
 * Resolve the rule set with the given element and get the first
 * resolved type.
 */
private GType getFirstType(Rule rs, Element el) {
    final List<GType> types = new ArrayList<>();
    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 69 with Element

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

the class RuleFileReaderTest method testIncludeFileQuoted.

@Test
public void testIncludeFileQuoted() {
    StyleFileLoader loader = new StringStyleFileLoader(new String[][] { { "lines", "include \n 'inc file' \n;" }, { "inc file", "highway=secondary [0x3]" } });
    RuleSet rs = makeRuleSet(loader);
    Element el = new Way(1);
    el.addTag("highway", "secondary");
    GType type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals(3, 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 70 with Element

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

the class RuleFileReaderTest method testRegex2.

@Test
public void testRegex2() {
    RuleSet rs = makeRuleSet("a=b & (smoothness ~ '.*(bad|horrible|impassable)' | sac_scale ~ '.*(mountain|alpine)_hiking') [0x1]" + "a = '>=' & b = '>' [0x2]");
    assertNotNull(rs);
    Element el = new Way(1);
    el.addTag("a", "b");
    el.addTag("smoothness", "zzzbad");
    GType type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals("matched .*bad", 1, type.getType());
    el = new Way(1);
    el.addTag("a", "b");
    el.addTag("sac_scale", "zzz alpine_hiking");
    type = getFirstType(rs, el);
    assertNotNull(type);
    el = new Way(1);
    el.addTag("a", "b");
    el.addTag("sac_scale", "zzz alp_hiking");
    type = getFirstType(rs, el);
    assertNull(type);
    el = new Way(1);
    el.addTag("a", ">=");
    el.addTag("b", ">");
    type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals("match string that is the same as an operator", 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)

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