Changeset 15978 in josm for trunk/test/unit
- Timestamp:
- 2020-03-01T21:33:56+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
r15815 r15978 6 6 import static org.hamcrest.CoreMatchers.not; 7 7 import static org.junit.Assert.assertEquals; 8 import static org.junit.Assert.assertFalse;9 8 import static org.junit.Assert.assertThat; 10 9 import static org.junit.Assert.assertTrue; … … 14 13 import java.util.LinkedHashSet; 15 14 import java.util.List; 15 import java.util.Locale; 16 16 import java.util.Set; 17 17 … … 66 66 assertThat(openingHourTest.checkOpeningHourSyntax(key, "09:00-21:00"), isEmpty()); 67 67 assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty()); 68 assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1));69 assertEquals(Severity.OTHER, openingHourTest.checkOpeningHourSyntax(70 key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getSeverity());71 assertEquals("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise", openingHourTest.checkOpeningHourSyntax(72 key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue());73 68 } 74 69 … … 78 73 @Test 79 74 public void testI18n() { 80 assertTrue(openingHourTest.checkOpeningHourSyntax("opening_hours", ".", null, false, "de") 81 .get(0).toString().contains("Unerwartetes Zeichen")); 82 assertFalse(openingHourTest.checkOpeningHourSyntax("opening_hours", ".", null, false, "en") 83 .get(0).toString().contains("Unerwartetes Zeichen")); 75 final String key = "opening_hours"; 76 String value = "."; 77 assertEquals("Vorgefunden wurde: \".\" \". \" in Zeile 0, Zeichen 0\nErwartet wurde: <EOF> => null", 78 openingHourTest.checkOpeningHourSyntax(key, value, false, Locale.GERMAN).get(0).toString()); 79 assertEquals("Encountered: \".\" \". \" at line 0, column 0\nWas expecting: <EOF> => null", 80 openingHourTest.checkOpeningHourSyntax(key, value, false, Locale.ENGLISH).get(0).toString()); 81 value = "Mon-Thu 12-18"; 82 assertEquals("Wochentag mit 3 Buchstaben in Zeile 1, Zeichen 4 => Mo-Th 12:00-18:00", 83 openingHourTest.checkOpeningHourSyntax(key, value, false, Locale.GERMAN).get(0).toString()); 84 assertEquals("Three character weekday at line 1, column 4 => Mo-Th 12:00-18:00", 85 openingHourTest.checkOpeningHourSyntax(key, value, false, Locale.ENGLISH).get(0).toString()); 84 86 } 85 87 … … 91 93 final String key = "opening_hours"; 92 94 final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(key, "Mo-Tue"); 93 assertThat(errors, hasSize(2)); 94 assertEquals(key + " - Mo-Tue <--- (Please use the English abbreviation \"Tu\" for \"tue\".)", errors.get(0).getMessage()); 95 assertThat(errors, hasSize(1)); 96 assertEquals("Mo-Tu", errors.get(0).getPrettifiedValue()); 97 assertEquals("Three character weekday at line 1, column 6", errors.get(0).getMessage()); 95 98 assertEquals(Severity.WARNING, errors.get(0).getSeverity()); 96 assertEquals(key +97 " - Mo-Tue <--- (This rule is not very explicit because there is no time selector being used."+98 " A time selector is the part specifying hours when the object is opened, for example \"10:00-19:00\"."+99 " Please add a time selector to this rule or use a comment to make it more explicit.)", errors.get(1).getMessage());100 assertEquals(Severity.WARNING, errors.get(1).getSeverity());101 99 } 102 100 … … 108 106 final String key = "opening_hours"; 109 107 final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00"); 110 assertThat(errors, hasSize(2)); 111 assertEquals(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)", errors.get(0).getMessage()); 108 assertThat(errors, hasSize(1)); 109 assertEquals("Sa-Su 10:00-20:00", errors.get(0).getPrettifiedValue()); 110 assertEquals("Invalid minutes at line 1, column 12", errors.get(0).getMessage()); 112 111 assertEquals(Severity.WARNING, errors.get(0).getSeverity()); 113 assertEquals("Sa-Su 10:00-20:00", errors.get(0).getPrettifiedValue());114 assertEquals(key + " - Sa-Su 10.00-20. <--- (Please use \":\" as hour/minute-separator)", errors.get(1).getMessage());115 assertEquals(Severity.WARNING, errors.get(1).getSeverity());116 112 } 117 113 … … 123 119 assertThat(openingHourTest.checkOpeningHourSyntax(null, null), isEmpty()); 124 120 assertThat(openingHourTest.checkOpeningHourSyntax(null, ""), isEmpty()); 125 assertEquals("opening_hours - The value contains nothing meaningful which can be parsed.",121 assertEquals("opening_hours value can be prettified", 126 122 openingHourTest.checkOpeningHourSyntax("opening_hours", " ").get(0).getMessage()); 127 assertEquals("null - The optional_conf_parm[\"tag_key\"] parameter is of unknown type. Given object, expected string.",123 assertEquals("null value can be prettified", 128 124 openingHourTest.checkOpeningHourSyntax(null, " ").get(0).getMessage()); 129 125 } … … 136 132 final String key = "opening_hours"; 137 133 assertThat(openingHourTest.checkOpeningHourSyntax(key, "badtext"), hasSize(1)); 138 assertEquals( key + " - ba <--- (Unexpected token: \"b\" Invalid/unsupported syntax.)",139 openingHourTest.checkOpeningHourSyntax(key, "badtext").get(0).getMessage() );134 assertEquals("Encountered: <UNEXPECTED_CHAR> \"b \" at line 0, column 0\nWas expecting: <EOF>", 135 openingHourTest.checkOpeningHourSyntax(key, "badtext").get(0).getMessage().trim()); 140 136 assertThat(openingHourTest.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1)); 141 assertEquals(key + " - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. " 142 + "For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)", 137 assertEquals("Encountered: <UNEXPECTED_CHAR> \"p \" at line 1, column 2\nWas expecting: <EOF>", 143 138 openingHourTest.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage()); 144 139 } … … 159 154 public void testCheckOpeningHourSyntax7() { 160 155 final String key = "opening_hours"; 156 assertThat(openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00", true, Locale.getDefault()), isEmpty()); 161 157 assertThat(openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1)); 162 158 assertEquals(Severity.OTHER, openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity()); … … 171 167 final String key = "opening_hours"; 172 168 assertEquals(Severity.WARNING, openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity()); 173 assertEquals(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. " 174 + "Not very explicit! Please use this syntax instead \"04:00-17:00\".)", 169 assertEquals("Hours without minutes", 175 170 openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage()); 176 assertEquals("Mo,Tu 04:00-17:00", openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue());177 171 } 178 172 … … 188 182 assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00"), isEmpty()); 189 183 assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su 09:30; We 19:30"), isEmpty()); 190 assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00"), isEmpty());184 // assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00"), isEmpty()); 191 185 assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00"), hasSize(1)); 192 assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH00:00-24:00",186 assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; PH,Sa,Su 00:00-24:00", 193 187 openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00").get(0).getPrettifiedValue()); 194 assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH00:00-24:00",188 assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; PH,Sa,Su 00:00-24:00", 195 189 openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00").get(0).getPrettifiedValue()); 196 190 } … … 233 227 for (final Tag t : values) { 234 228 final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(t.getKey(), t.getValue()); 229 if (!errors.isEmpty() && errors.get(0).getMessage().startsWith("Holiday after weekday")) { 230 continue; 231 } 235 232 assertThat(t + " is valid", errors, isEmpty()); 236 233 }
Note:
See TracChangeset
for help on using the changeset viewer.