From f4e7ca3aece8748598f225f3f0a7147a4db06ad7 Mon Sep 17 00:00:00 2001 From: Robin Schneider Date: Sun, 12 Apr 2015 21:58:01 +0200 Subject: [PATCH] An is not allowed after and . Related to #75. --- opening_hours.js | 12 ++++++++++++ test.js | 3 +++ test.log | 11 +++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/opening_hours.js b/opening_hours.js index 8bbcfd56..28d8a0a7 100644 --- a/opening_hours.js +++ b/opening_hours.js @@ -5486,6 +5486,12 @@ }}(tokens, at, year_from, is_range, has_period, period)); at += 1 + (is_range ? 2 : 0) + (has_period ? (has_period === 2 ? 1 : 2) : 0); + } else if (matchTokens(tokens, at - 1, ',')) { // additional rule + throw formatWarnErrorMessage( + nrule, + at, + 'An additional rule does not make sense here. Just use a ";" as rule separator.' + + ' See https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification#explain:additional_rule_separator'); } else { throw formatWarnErrorMessage(nrule, at, 'Unexpected token in year range: ' + tokens[at][1]); } @@ -5585,6 +5591,12 @@ } at += 1 + (is_range ? 2 : 0) + (period ? 2 : 0); + } else if (matchTokens(tokens, at - 1, ',')) { // additional rule + throw formatWarnErrorMessage( + nrule, + at, + 'An additional rule does not make sense here. Just use a ";" as rule separator.' + + ' See https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification#explain:additional_rule_separator'); } else { throw formatWarnErrorMessage(nrule, at, 'Unexpected token in week range: ' + tokens[at][1]); } diff --git a/test.js b/test.js index e1ac9a5f..42c69d67 100755 --- a/test.js +++ b/test.js @@ -4763,6 +4763,9 @@ test.addShouldFail('Incorrect syntax which should throw an error', [ 'PH, Aug-Sep 00:00-24:00' + value_suffix, 'We off, Mo,Tu,Th-Su,PH, Jun-Aug We 11:00-14:00,17:00+' + value_suffix, 'We, Aug Mo' + value_suffix, + '2014, Aug Mo' + value_suffix, + 'week 5, Aug Mo' + value_suffix, + 'Jun 2-5, week 5 00:00-24:00' + value_suffix, ], nominatiomTestJSON, 'not last test'); test.addShouldFail('Missing information (e.g. country or holidays not defined in this lib)', [ diff --git a/test.log b/test.log index 068f6777..b6913a21 100644 --- a/test.log +++ b/test.log @@ -1836,7 +1836,7 @@ PH + 2 day <--- (There should be no reason to differ more than 1 days from a pub Su- <--- (Unexpected token: "-" This means that the syntax is not valid at that point or it is currently not supported.) "Incorrect syntax which should throw an error" for "2012, Jan; 00:23-00:42 unknown "warning at correct position?"": PASSED -2012, Jan <--- (Unexpected token in year range: month) +2012, Jan <--- (An additional rule does not make sense here. Just use a ";" as rule separator. See https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification#explain:additional_rule_separator) "Incorrect syntax which should throw an error" for "easter + 370 days; 00:23-00:42 unknown "warning at correct position?"": PASSED easter + 370 days <--- (There should be no reason to differ more than 200 days from a event like easter. If so tell us …) @@ -1979,6 +1979,13 @@ We off, Mo,Tu,Th-Su,PH, Jun <--- (An additional rule does not make sense here. J "Incorrect syntax which should throw an error" for "We, Aug Mo; 00:23-00:42 unknown "warning at correct position?"": PASSED We, Aug <--- (An additional rule does not make sense here. Just use a ";" as rule separator. See https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification#explain:additional_rule_separator) +"Incorrect syntax which should throw an error" for "2014, Aug Mo; 00:23-00:42 unknown "warning at correct position?"": PASSED +2014, Aug <--- (An additional rule does not make sense here. Just use a ";" as rule separator. See https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification#explain:additional_rule_separator) + +"Incorrect syntax which should throw an error" for "week 5, Aug Mo; 00:23-00:42 unknown "warning at correct position?"": PASSED +week 5, Aug <--- (An additional rule does not make sense here. Just use a ";" as rule separator. See https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification#explain:additional_rule_separator) + +"Incorrect syntax which should throw an error" for "Jun 2-5, week 5 00:00-24:00; 00:23-00:42 unknown "warning at correct position?"": FAILED "Missing information (e.g. country or holidays not defined in this lib)" for "PH": PASSED Country code missing which is needed to select the correct holidays (see README how to provide it) @@ -2102,7 +2109,7 @@ Su 7:30,10i <--- (Missing time separator in time range after: "number") "Compare result from getMatchingRule()" for "Fr 08:00-12:00 || Fr 12:00-16:00 open "Notfallsprechstunde"": PASSED "Compare result from getMatchingRule()" for "Fr 08:00-12:00, Fr 12:00-16:00 open "Notfallsprechstunde"": PASSED "Compare result from getMatchingRule()" for "Fr 08:00-12:00 || Fr 12:00-16:00 open "Notfallsprechstunde"": PASSED -806/815 tests passed. +808/818 tests passed. 38 tests where (partly) ignored, sorted by commonness: * 23: prettifyValue (most of the cases this is used to test if values with selectors in wrong order or wrong symbols (error tolerance) are evaluated correctly) * 11: not implemented yet