diff --git a/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java b/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
index e57b473e8..709815720 100644
|
a
|
b
|
|
| 11 | 11 | import java.util.Locale; |
| 12 | 12 | import java.util.Objects; |
| 13 | 13 | |
| | 14 | import ch.poole.openinghoursparser.OpeningHoursParseException; |
| 14 | 15 | import ch.poole.openinghoursparser.OpeningHoursParser; |
| 15 | | import ch.poole.openinghoursparser.ParseException; |
| 16 | 16 | import ch.poole.openinghoursparser.Rule; |
| 17 | 17 | import ch.poole.openinghoursparser.Util; |
| 18 | 18 | import org.openstreetmap.josm.command.ChangePropertyCommand; |
| … |
… |
private TestError createTestError(Severity severity, String message, String key,
|
| 68 | 68 | * @return a list of {@link TestError} or an empty list |
| 69 | 69 | */ |
| 70 | 70 | public List<TestError> checkOpeningHourSyntax(final String key, final String value) { |
| 71 | | return checkOpeningHourSyntax(key, value, null, Locale.getDefault()); |
| | 71 | return checkOpeningHourSyntax(key, value, null, Locale.getDefault(), false); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
| … |
… |
private TestError createTestError(Severity severity, String message, String key,
|
| 78 | 78 | * @param value the opening hour value to be checked. |
| 79 | 79 | * @param p the primitive to check/fix. |
| 80 | 80 | * @param locale the locale code used for localizing messages |
| | 81 | * @param useHTML use HTML code for formatting the test error description |
| 81 | 82 | * @return a list of {@link TestError} or an empty list |
| 82 | 83 | */ |
| 83 | | List<TestError> checkOpeningHourSyntax(final String key, final String value, OsmPrimitive p, Locale locale) { |
| | 84 | List<TestError> checkOpeningHourSyntax(final String key, final String value, OsmPrimitive p, Locale locale, boolean useHTML) { |
| 84 | 85 | if (value == null || value.isEmpty()) { |
| 85 | 86 | return Collections.emptyList(); |
| 86 | 87 | } |
| … |
… |
private TestError createTestError(Severity severity, String message, String key,
|
| 94 | 95 | // parse again in strict mode for detailed message |
| 95 | 96 | new OpeningHoursParser(new StringReader(value)).rules(true); |
| 96 | 97 | } |
| 97 | | } catch (ParseException e) { |
| 98 | | return Collections.singletonList(createTestError(Severity.WARNING, e.getMessage(), key, prettifiedValue, p)); |
| | 98 | } catch (OpeningHoursParseException e) { |
| | 99 | String message = e.getMessage(); |
| | 100 | final int column = e.getColumn() - 1; |
| | 101 | if (useHTML && column >= 0) { |
| | 102 | message = "<html>" + value.substring(0, column) + "<span color='red'>" + value.substring(column) + "</span> – " + e.getMessage(); |
| | 103 | } |
| | 104 | return Collections.singletonList(createTestError(Severity.WARNING, message, key, prettifiedValue, p)); |
| 99 | 105 | } |
| 100 | 106 | |
| 101 | 107 | if (!includeOtherSeverityChecks() || Objects.equals(value, prettifiedValue) || p == null) { |
| … |
… |
private TestError createTestError(Severity severity, String message, String key,
|
| 109 | 115 | @Override |
| 110 | 116 | public void check(final OsmPrimitive p) { |
| 111 | 117 | for (String key : KEYS_TO_CHECK) { |
| 112 | | errors.addAll(checkOpeningHourSyntax(key, p.get(key), p, Locale.getDefault())); |
| | 118 | errors.addAll(checkOpeningHourSyntax(key, p.get(key), p, Locale.getDefault(), true)); |
| 113 | 119 | } |
| 114 | 120 | } |
| 115 | 121 | } |
diff --git a/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java b/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
index 1d45c0804..0f20fa529 100644
|
a
|
b
|
public void testI18n() {
|
| 87 | 87 | assertEquals("Encountered: \".\" \". \" at line 0, column 0\nWas expecting: <EOF>", |
| 88 | 88 | checkOpeningHourSyntax(key, value, Locale.ENGLISH).get(0).getDescription()); |
| 89 | 89 | value = "Mon-Thu 12-18"; |
| 90 | | assertEquals("Wochentag mit 3 Buchstaben in Zeile 1, Zeichen 4", |
| | 90 | assertEquals("<html>Mon-<span color=red>Thu 12-18</span> – Wochentag mit 3 Buchstaben in Zeile 1, Zeichen 4", |
| 91 | 91 | checkOpeningHourSyntax(key, value, Locale.GERMAN).get(0).getDescription()); |
| 92 | | assertEquals("Three character weekday at line 1, column 4", |
| | 92 | assertEquals("<html>Mon-<span color=red>Thu 12-18</span> – Three character weekday at line 1, column 4", |
| 93 | 93 | checkOpeningHourSyntax(key, value, Locale.ENGLISH).get(0).getDescription()); |
| 94 | 94 | } |
| 95 | 95 | |
| … |
… |
public void testCheckOpeningHourSyntax2() {
|
| 102 | 102 | final List<TestError> errors = checkOpeningHourSyntax(key, "Mo-Tue"); |
| 103 | 103 | assertThat(errors, hasSize(1)); |
| 104 | 104 | assertFixEquals("Mo-Tu", errors.get(0)); |
| 105 | | assertEquals("Three character weekday at line 1, column 6", errors.get(0).getDescription()); |
| | 105 | assertEquals("<html>Mo-Tue<span color=red></span> – Three character weekday at line 1, column 6", errors.get(0).getDescription()); |
| 106 | 106 | assertEquals(Severity.WARNING, errors.get(0).getSeverity()); |
| 107 | 107 | } |
| 108 | 108 | |
| … |
… |
public void testCheckOpeningHourSyntax3() {
|
| 115 | 115 | final List<TestError> errors = checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00"); |
| 116 | 116 | assertThat(errors, hasSize(1)); |
| 117 | 117 | assertFixEquals("Sa-Su 10:00-20:00", errors.get(0)); |
| 118 | | assertEquals("Invalid minutes at line 1, column 12", errors.get(0).getDescription()); |
| | 118 | assertEquals("<html>Sa-Su 10.00-<span color=red>20.00</span> – Invalid minutes at line 1, column 12", errors.get(0).getDescription()); |
| 119 | 119 | assertEquals(Severity.WARNING, errors.get(0).getSeverity()); |
| 120 | 120 | } |
| 121 | 121 | |
| … |
… |
public void testCheckOpeningHourSyntax5() {
|
| 142 | 142 | assertEquals("Encountered: <UNEXPECTED_CHAR> \"b \" at line 0, column 0\nWas expecting: <EOF>", |
| 143 | 143 | checkOpeningHourSyntax(key, "badtext").get(0).getDescription().trim()); |
| 144 | 144 | assertThat(checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1)); |
| 145 | | assertEquals("Encountered: <UNEXPECTED_CHAR> \"p \" at line 1, column 2\nWas expecting: <EOF>", |
| | 145 | assertEquals("<html>5.<span color=red>00 p.m-11.00 p.m</span> – " + |
| | 146 | "Encountered: <UNEXPECTED_CHAR> \"p \" at line 1, column 2\nWas expecting: <EOF>", |
| 146 | 147 | checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getDescription()); |
| 147 | 148 | } |
| 148 | 149 | |
| … |
… |
public void testPresetValues() {
|
| 233 | 234 | } |
| 234 | 235 | for (final Tag t : values) { |
| 235 | 236 | final List<TestError> errors = checkOpeningHourSyntax(t.getKey(), t.getValue()); |
| 236 | | if (!errors.isEmpty() && errors.get(0).getDescription().startsWith("Holiday after weekday")) { |
| | 237 | if (!errors.isEmpty() && errors.get(0).getDescription().contains("Holiday after weekday")) { |
| 237 | 238 | continue; |
| 238 | 239 | } |
| 239 | 240 | assertThat(t + " is valid", errors, isEmpty()); |
| … |
… |
public void testTicket17932() {
|
| 254 | 255 | final Node node = new Node(LatLon.ZERO); |
| 255 | 256 | node.put(key, value); |
| 256 | 257 | new DataSet(node); |
| 257 | | return openingHourTest.checkOpeningHourSyntax(key, value, node, locale); |
| | 258 | return openingHourTest.checkOpeningHourSyntax(key, value, node, locale, true); |
| 258 | 259 | } |
| 259 | 260 | |
| 260 | 261 | private static void assertFixEquals(String value, TestError error) { |