Changeset 8266 in josm for trunk/test


Ignore:
Timestamp:
2015-04-25T19:13:12+02:00 (5 years ago)
Author:
simon04
Message:

fix #9782 fix #10859 - MapCSS validator: evaluate real key and value for KeyConditions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r8265 r8266  
    88
    99import java.io.StringReader;
     10import java.util.Collection;
    1011import java.util.Iterator;
    1112import java.util.LinkedHashSet;
     
    2627import org.openstreetmap.josm.data.osm.OsmUtils;
    2728import org.openstreetmap.josm.data.validation.Severity;
     29import org.openstreetmap.josm.data.validation.TestError;
    2830import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.TagCheck;
     31import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;
    2932
    3033/**
     
    3942    public static void setUp() {
    4043        JOSMFixture.createUnitTestFixture().init();
     44    }
     45
     46    static MapCSSTagChecker buildTagChecker(String css) throws ParseException {
     47        final MapCSSTagChecker test = new MapCSSTagChecker();
     48        test.checks.putAll("test", TagCheck.readMapCSS(new StringReader(css)));
     49        return test;
    4150    }
    4251
     
    6978        n2.put("natural", "wood");
    7079        assertFalse(check.evaluate(n2));
    71         assertThat(MapCSSTagChecker.TagCheck.insertArguments(check.rule.selectors.get(0), "The key is {0.key} and the value is {0.value}"),
     80        assertThat(MapCSSTagChecker.TagCheck.insertArguments(check.rule.selectors.get(0), "The key is {0.key} and the value is {0.value}", null),
    7281                is("The key is natural and the value is marsh"));
    7382    }
     
    8998
    9099    @Test
     100    public void test9782() throws Exception {
     101        final MapCSSTagChecker test = buildTagChecker("*[/.+_name/][!name] {" +
     102                "throwWarning: tr(\"has {0} but not {1}\", \"{0.key}\", \"{1.key}\");}");
     103        final OsmPrimitive p = OsmUtils.createPrimitive("way alt_name=Foo");
     104        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
     105        assertThat(errors.size(), is(1));
     106        assertThat(errors.iterator().next().getMessage(), is("has alt_name but not name"));
     107    }
     108
     109    @Test
     110    public void test10859() throws Exception {
     111        final MapCSSTagChecker test = buildTagChecker("way[highway=footway][foot?!] {\n" +
     112                "  throwWarning: tr(\"{0} used with {1}\", \"{0.value}\", \"{1.tag}\");}");
     113        final OsmPrimitive p = OsmUtils.createPrimitive("way highway=footway foot=no");
     114        final Collection<TestError> errors = test.getErrorsForPrimitive(p, false);
     115        assertThat(errors.size(), is(1));
     116        assertThat(errors.iterator().next().getMessage(), is("footway used with foot=no"));
     117    }
     118
     119    @Test
    91120    public void testInit() throws Exception {
    92121        MapCSSTagChecker c = new MapCSSTagChecker();
Note: See TracChangeset for help on using the changeset viewer.