Search in sources :

Example 61 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element 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 62 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element 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)

Example 63 with Element

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

the class RuleFileReaderTest method testIncludeFile.

@Test
public void testIncludeFile() {
    StyleFileLoader loader = new StringStyleFileLoader(new String[][] { { "lines", "include incfile;" }, { "incfile", "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 64 with Element

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

the class RuleFileReaderTest method testWildcardTop.

/**
 * You can now have a wild card at the top level.
 */
@Test
public void testWildcardTop() {
    RuleSet rs = makeRuleSet("highway=* {set a=fred} [0x1]\n");
    assertNotNull("rule found", rs);
    Element el = new Way(1);
    el.addTag("highway", "secondary");
    GType type = getFirstType(rs, el);
    assertNotNull("can find match", type);
    assertEquals("correct type", 1, type.getType());
    assertEquals("tag set", "fred", el.getTag("a"));
}
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 65 with Element

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

the class RuleFileReaderTest method testRegexp.

/**
 * Check for the regexp handling.
 */
@Test
public void testRegexp() {
    RuleSet rs = makeRuleSet("highway=* & name ~ 'blue.*' [0x2]\n");
    assertNotNull("rule found", rs);
    // Set up element with matching name
    Element el = new Way(1);
    el.addTag("highway", "secondary");
    el.addTag("name", "blue sq");
    GType type = getFirstType(rs, el);
    assertNotNull("matched regexp", type);
    assertEquals("matched type", 2, type.getType());
    // change name to one that should not match
    el.addTag("name", "yellow");
    type = getFirstType(rs, el);
    assertNull("no match for yello", 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)

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