Commit c1681b45 authored by David Faure's avatar David Faure
Browse files

Fix autocorrect for cases where the state differs

The testcase in the bug is "Sa 08:00-12:00; 11:30-13:00 off"
but I also added tests (and fixes) for other autocorrect features
which misbehaved when the state was different between the two rules.

BUG: 445787
parent 46e72e47
Pipeline #105576 passed with stage
in 1 minute and 11 seconds
......@@ -204,6 +204,7 @@ private Q_SLOTS:
T2("2020-2021 Mo, Tu-Fr, Sa [-1] 09:00-14:00", "2020-2021 Mo,Tu-Fr,Sa[-1] 09:00-14:00");
T2("week 1-3 Mo[2], Tu-Fr, Sa [-1] 09:00-14:00", "week 01-03 Mo[2],Tu-Fr,Sa[-1] 09:00-14:00");
T2("Mo Fr 09:30-12:30 13:30-18:30", "Mo,Fr 09:30-12:30,13:30-18:30");
T2("Mo Fr 09:30-12:30, 13:30-18:30 off", "Mo,Fr 09:30-12:30,13:30-18:30 off");
T2("Mo, We, Fr 06:30-21:30; Tu, Th 09:00-21:30; Sa 09:00-17:00; Su 09:00-14:00", "Mo,We,Fr 06:30-21:30; Tu,Th 09:00-21:30; Sa 09:00-17:00; Su 09:00-14:00");
// technically wrong but often found content in OSM for which we have error recovery
......@@ -322,6 +323,10 @@ private Q_SLOTS:
T2("Mo-Sa 12:00-15:00; 18:00-24:00", "Mo-Sa 12:00-15:00,18:00-24:00");
T2("Mo-Sa 12:00-15:00; Mo-Sa 18:00-24:00", "Mo-Sa 12:00-15:00,18:00-24:00");
T2("Mo 12:00-15:00; Mo 18:00-24:00", "Mo 12:00-15:00,18:00-24:00");
T("Mo-Sa 12:00-15:00 off; 18:00-24:00");
T("Mo-Sa 12:00-15:00; Mo-Sa 18:00-24:00 closed");
T("Mo 12:00-15:00; Mo 18:00-24:00 \"comment\"");
T("Sa 08:00-12:00; 11:30-13:00 off");
// recovery from wrong time selector separators
T3("Dimanche Fermé Lundi 08:00 – 12:30 14:00 – 19:00 Mardi 08:00 – 12:30 14:00 – 19:00 Mercredi 08:00 – 12:30 14:00 – 19:00 Jeudi 08:00 – 12:30 14:00 – 19:00 Vendredi 08:00 – 12:30 14:00 – 19:00 Samedi 08:00 – 12:30 14:30 – 18:00",
......
......@@ -81,6 +81,7 @@ void OpeningHoursPrivate::autocorrect()
// the current rule only has a time selector, so we append that to the previous rule
else if (curRuleSingleSelector && rule->m_timeSelector && prevRule->m_timeSelector) {
appendSelector(prevRule->m_timeSelector.get(), std::move(rule->m_timeSelector));
prevRule->copyStateFrom(*rule);
it = std::prev(m_rules.erase(it));
}
......@@ -98,7 +99,8 @@ void OpeningHoursPrivate::autocorrect()
// Current rule is only a time selector
// "Mo-Sa 12:00-15:00; 18:00-24:00" => "Mo-Sa 12:00-15:00,18:00-24:00"
if (curRuleSingleSelector && rule->m_timeSelector
&& prevRule->selectorCount() > 1 && prevRule->m_timeSelector) {
&& prevRule->selectorCount() > 1 && prevRule->m_timeSelector
&& rule->state() == prevRule->state()) {
appendSelector(prevRule->m_timeSelector.get(), std::move(rule->m_timeSelector));
it = std::prev(m_rules.erase(it));
}
......@@ -113,6 +115,7 @@ void OpeningHoursPrivate::autocorrect()
&& rule->selectorCount() == 2 && rule->m_weekdaySelector && prevRule->m_weekdaySelector
// slower than writing an operator==, but so much easier to write :)
&& rule->m_weekdaySelector->toExpression() == prevRule->m_weekdaySelector->toExpression()
&& rule->state() == prevRule->state()
) {
appendSelector(prevRule->m_timeSelector.get(), std::move(rule->m_timeSelector));
it = std::prev(m_rules.erase(it));
......
......@@ -35,6 +35,12 @@ void Rule::setState(State state)
}
}
void Rule::copyStateFrom(const Rule &otherRule)
{
m_state = otherRule.m_state;
m_stateFlags = otherRule.m_stateFlags;
}
bool Rule::hasComment() const
{
return !m_comment.isEmpty();
......
......@@ -54,6 +54,7 @@ public:
Interval::State state() const;
bool hasImplicitState() const;
void setState(State state);
void copyStateFrom(const Rule &otherRule);
bool hasComment() const;
void setComment(const char *str, int len);
int requiredCapabilities() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment