Search in sources :

Example 81 with Way

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

the class RuleFileReaderTest method testContinue.

/**
 * Test the continue keyword.  If a type is marked with this word, then
 * further matches are performed and this might result in more types
 * being added.
 */
@Test
public void testContinue() {
    RuleSet rs = makeRuleSet("highway=primary [0x1 continue]" + "highway=primary [0x2 continue]" + "highway=primary [0x3]" + "highway=primary [0x4]");
    Way el = new Way(1);
    el.addTag("highway", "primary");
    final List<GType> list = new ArrayList<>();
    rs.resolveType(el, new TypeResult() {

        public void add(Element el, GType type) {
            list.add(type);
        }
    });
    GType type = list.get(0);
    assertEquals("first type", 1, type.getType());
    assertEquals("continue search", true, type.isContinueSearch());
    assertEquals("number of result types", 3, list.size());
    assertEquals("type of first", 1, list.get(0).getType());
    assertEquals("type of second", 2, list.get(1).getType());
    assertEquals("type of third", 3, list.get(2).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) ArrayList(java.util.ArrayList) TypeResult(uk.me.parabola.mkgmap.reader.osm.TypeResult) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 82 with Way

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

the class RuleFileReaderTest method testNEAtTopWithRE.

@Test
public void testNEAtTopWithRE() {
    RuleSet rs = makeRuleSet("a != 'fred' &  a ~ '.*' [0x2]");
    Element el = new Way(1);
    el.addTag("a", "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 83 with Way

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

the class RuleFileReaderTest method testOptimizeWithOr.

/**
 * Failure of the optimiser to promote the correct term to the front.
 * Example from mailing list.
 */
@Test
public void testOptimizeWithOr() {
    String s = "highway ~ '(secondary|tertiary|unclassified|residential|minor|living_street|service)' " + "& oneway=* " + "& (cycleway=opposite | cycleway=opposite_lane | cycleway=opposite_track )" + "[0x2 ]";
    RuleSet rs = makeRuleSet(s);
    Element el = new Way(1);
    el.addTag("highway", "tertiary");
    el.addTag("oneway", "1");
    el.addTag("cycleway", "opposite_track");
    GType type = getFirstType(rs, el);
    assertNotNull(type);
    assertEquals(2, type.getType());
    el.addTag("cycleway", "fred");
    type = getFirstType(rs, el);
    assertNull(type);
    el.addTag("cycleway", "opposite");
    type = getFirstType(rs, el);
    assertNotNull(type);
    // Copy for LinkedOp which remembers the last matched element
    el = el.copy();
    el.addTag("cycleway", "opposite_lane");
    type = getFirstType(rs, el);
    assertNotNull(type);
    el.addTag("highway", "fred");
    type = getFirstType(rs, el);
    assertNull(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 84 with Way

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

the class RuleFileReaderTest method testIncludeAsTagName2.

@Test
public void testIncludeAsTagName2() {
    RuleSet rs = makeRuleSet("include = yes [0x2]");
    Way way = new Way(1);
    way.addTag("include", "yes");
    GType type = getFirstType(rs, way);
    assertNotNull(type);
    assertEquals(2, type.getType());
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 85 with Way

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

the class RuleFileReaderTest method testGType.

/**
 * Tests for the road classification and other parts of the GType.
 */
@Test
public void testGType() {
    RuleSet rs = makeRuleSet("highway=motorway " + "[0x1 road_class=4 road_speed=7 default_name='motor way']\n");
    Element el = new Way(1);
    el.addTag("highway", "motorway");
    GType type = getFirstType(rs, el);
    assertNotNull(type);
    // Check that the correct class and speed are returned.
    assertEquals("class", 4, type.getRoadClass());
    assertEquals("class", 7, type.getRoadSpeed());
    assertEquals("default name", "motor way", type.getDefaultName());
}
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

Way (uk.me.parabola.mkgmap.reader.osm.Way)142 Test (org.junit.Test)94 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)70 GType (uk.me.parabola.mkgmap.reader.osm.GType)60 Element (uk.me.parabola.mkgmap.reader.osm.Element)48 Coord (uk.me.parabola.imgfmt.app.Coord)31 ArrayList (java.util.ArrayList)18 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)12 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)11 List (java.util.List)8 Node (uk.me.parabola.mkgmap.reader.osm.Node)8 HashMap (java.util.HashMap)7 IdentityHashMap (java.util.IdentityHashMap)6 Map (java.util.Map)6 StringStyleFileLoader (func.lib.StringStyleFileLoader)5 CoordNode (uk.me.parabola.imgfmt.app.CoordNode)5 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)5 CoordPOI (uk.me.parabola.mkgmap.reader.osm.CoordPOI)4 RestrictionRelation (uk.me.parabola.mkgmap.reader.osm.RestrictionRelation)4 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)3