Changeset 6538 in josm for trunk/test/unit


Ignore:
Timestamp:
2013-12-26T15:19:31+01:00 (10 years ago)
Author:
simon04
Message:

see #9414 - MapCSS-based tagchecker: provide {i.key}, {i.value}, {i.tag} variables to messages/fixes which refer to the corresponding match condition

File:
1 edited

Legend:

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

    r6534 r6538  
    44import org.junit.Test;
    55import org.openstreetmap.josm.Main;
     6import org.openstreetmap.josm.command.ChangePropertyCommand;
    67import org.openstreetmap.josm.data.Preferences;
    78import org.openstreetmap.josm.data.osm.Node;
     
    1011import org.openstreetmap.josm.data.osm.Tag;
    1112import org.openstreetmap.josm.data.osm.Way;
     13import org.openstreetmap.josm.data.validation.Severity;
    1214import org.openstreetmap.josm.tools.TextTagParser;
    1315
    1416import java.io.StringReader;
     17import java.text.MessageFormat;
    1518import java.util.LinkedHashSet;
    1619import java.util.List;
     
    3538        final List<MapCSSTagChecker.TagCheck> checks = MapCSSTagChecker.TagCheck.readMapCSS(new StringReader("" +
    3639                "*[natural=marsh] {\n" +
    37                 "   throwWarning: tr(\"{0} is deprecated\", \"natural=marsh\");\n" +
    38                 "   fixRemove: \"natural\";\n" +
     40                "   throwWarning: tr(\"{0} is deprecated\", \"{0.tag}\");\n" +
     41                "   fixRemove: \"{0.key}\";\n" +
    3942                "   fixAdd: \"natural=wetland\";\n" +
    4043                "   fixAdd: \"wetland=marsh\";\n" +
     
    4346        final MapCSSTagChecker.TagCheck check = checks.get(0);
    4447        assertThat(check, notNullValue());
    45         assertThat(check.change.get(0).apply(null), is(new Tag("natural")));
     48        assertThat(check.getDescription(), is("{0.tag} is deprecated"));
     49        assertThat(check.change.get(0).apply(null), is(new Tag("{0.key}")));
    4650        assertThat(check.change.get(1).apply(null), is(new Tag("natural", "wetland")));
    4751        assertThat(check.change.get(2).apply(null), is(new Tag("wetland", "marsh")));
    48         assertThat(check.errors.keySet().iterator().next(), is("natural=marsh is deprecated"));
    4952        final Node n1 = new Node();
    5053        n1.put("natural", "marsh");
    5154        assertTrue(check.matchesPrimitive(n1));
     55        assertThat(check.getErrorForPrimitive(n1).getMessage(), is("natural=marsh is deprecated"));
     56        assertThat(check.getErrorForPrimitive(n1).getSeverity(), is(Severity.WARNING));
     57        assertThat(((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString(),
     58                is("{natural=}"));
    5259        final Node n2 = new Node();
    5360        n2.put("natural", "wood");
    5461        assertFalse(check.matchesPrimitive(n2));
     62        assertThat(MapCSSTagChecker.TagCheck.insertArguments(check.selector.get(0), "The key is {0.key} and the value is {0.value}"),
     63                is("The key is natural and the value is marsh"));
    5564    }
    5665
     
    97106                final OsmPrimitive p = createPrimitiveForAssertion(i.getKey());
    98107                if (check.matchesPrimitive(p) != i.getValue()) {
    99                     final String error = "Expecting test '" + check.getMessage() + "' to " + (i.getValue() ? "" : "not ") + "match " + i.getKey() + ", i.e., " + p.getKeys();
     108                    final String error = MessageFormat.format("Expecting test ''{0}'' (i.e., {1}) to {2} {3} (i.e., {4})",
     109                            check.getMessage(), check.selector, i.getValue() ? "match" : "not match", i.getKey(), p.getKeys());
    100110                    System.err.println(error);
    101111                    assertionErrors.add(error);
Note: See TracChangeset for help on using the changeset viewer.