Skip to content

Commit

Permalink
An <additional_rule_separator> is not allowed after <year_selector> a…
Browse files Browse the repository at this point in the history
…nd <week_selector>. Related to #75.
  • Loading branch information
ypid committed Apr 12, 2015
1 parent c8f9a5c commit f4e7ca3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions opening_hours.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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]);
}
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)', [
Expand Down
11 changes: 9 additions & 2 deletions test.log
Original file line number Diff line number Diff line change
Expand Up @@ -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 …)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f4e7ca3

Please sign in to comment.