Ticket #12083: 12083-better-search-compile-error.patch

File 12083-better-search-compile-error.patch, 2.4 KB (added by simon04, 10 years ago)
  • src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    diff --git a/src/org/openstreetmap/josm/actions/search/SearchCompiler.java b/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
    index b16ffb3..f9946d3 100644
    a b public class SearchCompiler {  
    182182                            long maxDate = rangeA2.isEmpty() ? System.currentTimeMillis() : DateUtils.fromString(rangeA2).getTime();
    183183                            return new TimestampRange(minDate, maxDate);
    184184                        } else {
    185                             // I18n: Don't translate timestamp keyword
    186                             throw new ParseError(tr("Expecting <i>min</i>/<i>max</i> after ''timestamp''"));
     185                            throw new ParseError("<html>" + tr("Expecting {0} after {1}", "<i>min</i>/<i>max</i>", "<i>timestamp<i>"));
    187186                        }
    188187                    }
     188                } else {
     189                    throw new ParseError(tr("<html>" + "Expecting {0} after {1}", "<code>:</code>", "<i>" + keyword + "<i>"));
    189190                }
    190191            }
    191             return null;
     192            throw new IllegalStateException("Not expecting keyword " + keyword);
    192193        }
    193194
    194195        @Override
  • test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java

    diff --git a/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java b/test/unit/org/openstreetmap/josm/actions/search/SearchCompilerTest.java
    index 9c9463b..2f5a332 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.actions.search;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertFalse;
    56import static org.junit.Assert.assertThat;
    67import static org.junit.Assert.assertTrue;
    public class SearchCompilerTest {  
    378379        anonymous.match(anonymous.n1, false);
    379380        anonymous.match(anonymous.n2, true);
    380381    }
     382
     383    @Test
     384    public void testFooTypeBar() throws Exception {
     385        try {
     386            SearchCompiler.compile("foo type bar");
     387            throw new RuntimeException();
     388        } catch (ParseError parseError) {
     389            assertEquals("Expecting <code>:</code> after <i>type<i>", parseError.getMessage());
     390        }
     391    }
    381392}