Changeset 6376 in josm for trunk/src/org
- Timestamp:
- 2013-11-07T21:28:12+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
r6373 r6376 54 54 if (ENGINE != null) { 55 55 ENGINE.eval(new InputStreamReader(new MirroredInputStream("resource://data/opening_hours.js"), "UTF-8")); 56 ENGINE.eval("var oh = function (x, y) {return new opening_hours(x, y);};"); 56 // fake country/state to not get errors on holidays 57 ENGINE.eval("var nominatiomJSON = {address: {state: 'Bayern', country_code: 'de'}};"); 58 ENGINE.eval("var oh = function (value, mode) {return new opening_hours(value, nominatiomJSON, mode);};"); 57 59 } else { 58 60 Main.warn("Unable to initialize OpeningHourTest because no JavaScript engine has been found"); … … 60 62 } 61 63 62 protected Object parse(String value) throws ScriptException, NoSuchMethodException { 63 return ((Invocable) ENGINE).invokeFunction("oh", value); 64 static enum CheckMode { 65 TIME_RANGE(0), POINTS_IN_TIME(1), BOTH(2); 66 final int code; 67 68 CheckMode(int code) { 69 this.code = code; 70 } 71 } 72 73 protected Object parse(String value, CheckMode mode) throws ScriptException, NoSuchMethodException { 74 return ((Invocable) ENGINE).invokeFunction("oh", value, mode.code); 64 75 } 65 76 … … 104 115 * @return a list of {@link TestError} or an empty list 105 116 */ 106 public List<TestError> checkOpeningHourSyntax(final String value ) {117 public List<TestError> checkOpeningHourSyntax(final String value, CheckMode mode) { 107 118 if (ENGINE == null || value == null || value.trim().isEmpty()) { 108 119 return Collections.emptyList(); 109 120 } 110 121 try { 111 final Object r = parse(value );122 final Object r = parse(value, mode); 112 123 final List<TestError> errors = new ArrayList<TestError>(); 113 124 for (final Object i : getList(((Invocable) ENGINE).invokeMethod(r, "getWarnings"))) { … … 117 128 } catch (ScriptException ex) { 118 129 final String message = ex.getMessage() 119 .replace ("sun.org.mozilla.javascript.internal.JavaScriptException: ", "opening_hours - ")130 .replaceAll("[^:]*Exception: ", "opening_hours - ") 120 131 .replaceAll("\\(<Unknown source.*", "") 121 132 .trim(); … … 126 137 } 127 138 128 protected void check(final OsmPrimitive p, final String tagValue) { 129 for (TestError e : checkOpeningHourSyntax(tagValue)) { 139 public List<TestError> checkOpeningHourSyntax(final String value) { 140 return checkOpeningHourSyntax(value, CheckMode.TIME_RANGE); 141 } 142 143 protected void check(final OsmPrimitive p, final String tagValue, CheckMode mode) { 144 for (TestError e : checkOpeningHourSyntax(tagValue, mode)) { 130 145 e.setPrimitives(Collections.singletonList(p)); 131 146 errors.add(e); … … 134 149 135 150 protected void check(final OsmPrimitive p) { 136 check(p, p.get("opening_hours")); 137 // unsupported, cf. https://github.com/AMDmi3/opening_hours.js/issues/12 138 //check(p, p.get("collection_times")); 139 //check(p, p.get("service_times")); 151 check(p, p.get("opening_hours"), CheckMode.TIME_RANGE); 152 check(p, p.get("collection_times"), CheckMode.BOTH); 153 check(p, p.get("service_times"), CheckMode.BOTH); 140 154 } 141 155
Note:
See TracChangeset
for help on using the changeset viewer.