Changeset 9382 in josm


Ignore:
Timestamp:
2016-01-10T10:49:51+01:00 (8 years ago)
Author:
simon04
Message:

fix #12329 - Tag checker: Losing valid values when auto-fixing in some tests

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r9023 r9382  
    444444                            // misspelled preset key
    445445                            String i = marktr("Key ''{0}'' looks like ''{1}''.");
    446                             errors.add(new FixableTestError(this, Severity.WARNING, tr("Misspelled property key"),
    447                                     tr(i, key, fixedKey),
    448                                     MessageFormat.format(i, key, fixedKey), MISSPELLED_KEY, p,
    449                                     new ChangePropertyKeyCommand(p, key, fixedKey)));
     446                            final TestError error;
     447                            if (p.hasKey(fixedKey)) {
     448                                error = new TestError(this, Severity.WARNING, tr("Misspelled property key"),
     449                                        tr(i, key, fixedKey),
     450                                        MessageFormat.format(i, key, fixedKey), MISSPELLED_KEY, p);
     451                            } else {
     452                                error = new FixableTestError(this, Severity.WARNING, tr("Misspelled property key"),
     453                                        tr(i, key, fixedKey),
     454                                        MessageFormat.format(i, key, fixedKey), MISSPELLED_KEY, p,
     455                                        new ChangePropertyKeyCommand(p, key, fixedKey));
     456                            }
     457                            errors.add(error);
    450458                            withErrors.put(p, "WPK");
    451459                        } else {
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/TagCheckerTest.java

    r9231 r9382  
    4545     */
    4646    @Test
    47     public void testInvalidKey() throws IOException {
     47    public void testMisspelledKey1() throws IOException {
    4848        final List<TestError> errors = test(OsmUtils.createPrimitive("node Name=Main"));
    4949        assertEquals(1, errors.size());
    5050        assertEquals("Misspelled property key", errors.get(0).getMessage());
    5151        assertEquals("Key 'Name' looks like 'name'.", errors.get(0).getDescription());
     52        assertEquals(true, errors.get(0).isFixable());
    5253    }
    5354
     
    5758     */
    5859    @Test
    59     public void testMisspelledKey() throws IOException {
     60    public void testMisspelledKey2() throws IOException {
    6061        final List<TestError> errors = test(OsmUtils.createPrimitive("node landuse;=forest"));
    6162        assertEquals(1, errors.size());
    6263        assertEquals("Misspelled property key", errors.get(0).getMessage());
    6364        assertEquals("Key 'landuse;' looks like 'landuse'.", errors.get(0).getDescription());
     65        assertEquals(true, errors.get(0).isFixable());
     66    }
     67
     68    /**
     69     * Check for mispelled key where the suggested alternative is in use. The error should not be fixable.
     70     * @throws IOException if any I/O error occurs
     71     */
     72    @Test
     73    public void testMisspelledKeyButAlternativeInUse() throws IOException {
     74        // ticket 12329
     75        final List<TestError> errors = test(OsmUtils.createPrimitive("node amenity=fuel brand=bah Brand=foo"));
     76        assertEquals(1, errors.size());
     77        assertEquals("Misspelled property key", errors.get(0).getMessage());
     78        assertEquals("Key 'Brand' looks like 'brand'.", errors.get(0).getDescription());
     79        assertEquals(false, errors.get(0).isFixable());
    6480    }
    6581
Note: See TracChangeset for help on using the changeset viewer.