Throw exception for unclosed action tags

This commit is contained in:
patrick96 2021-02-02 23:13:00 +01:00 committed by Patrick Ziegler
parent cd1d4fa183
commit 7a9f301830
4 changed files with 25 additions and 5 deletions

View File

@ -158,8 +158,8 @@ namespace tags {
bool has_double_click() const; bool has_double_click() const;
size_t num_actions() const; size_t num_actions() const;
size_t num_unclosed() const;
// TODO provide better interface for adjusting the start positions of actions
const std::vector<action_block>& get_blocks() const; const std::vector<action_block>& get_blocks() const;
protected: protected:

View File

@ -198,6 +198,18 @@ namespace tags {
return m_action_blocks.size(); return m_action_blocks.size();
} }
size_t action_context::num_unclosed() const {
size_t num = 0;
for (const auto& a : m_action_blocks) {
if (a.is_open) {
num++;
}
}
return num;
}
const std::vector<action_block>& action_context::get_blocks() const { const std::vector<action_block>& action_context::get_blocks() const {
return m_action_blocks; return m_action_blocks;
} }

View File

@ -100,14 +100,19 @@ namespace tags {
} }
} }
/*
* After rendering, we need to tell the action context about the position
* of the alignment blocks so that it can do intersection tests.
*/
for (auto a : {alignment::LEFT, alignment::CENTER, alignment::RIGHT}) { for (auto a : {alignment::LEFT, alignment::CENTER, alignment::RIGHT}) {
m_action_ctxt.set_alignmnent_start(a, renderer.get_alignment_start(a)); m_action_ctxt.set_alignmnent_start(a, renderer.get_alignment_start(a));
} }
// TODO handle unclosed action tags in ctxt auto num_unclosed = m_action_ctxt.num_unclosed();
/* if (!m_actions.empty()) { */
/* throw runtime_error(to_string(m_actions.size()) + " unclosed action block(s)"); */ if (num_unclosed != 0) {
/* } */ throw runtime_error(to_string(num_unclosed) + " unclosed action block(s)");
}
} }
/** /**

View File

@ -46,6 +46,7 @@ TEST(ActionCtxtTest, closing) {
EXPECT_EQ(make_pair(id2, mousebtn::RIGHT), ctxt.action_close(mousebtn::NONE, alignment::CENTER, 1)); EXPECT_EQ(make_pair(id2, mousebtn::RIGHT), ctxt.action_close(mousebtn::NONE, alignment::CENTER, 1));
EXPECT_EQ(4, ctxt.num_actions()); EXPECT_EQ(4, ctxt.num_actions());
EXPECT_EQ(0, ctxt.num_unclosed());
} }
TEST(ActionCtxtTest, overlapping) { TEST(ActionCtxtTest, overlapping) {
@ -76,6 +77,7 @@ TEST(ActionCtxtTest, overlapping) {
EXPECT_EQ(id3, actions[mousebtn::RIGHT]); EXPECT_EQ(id3, actions[mousebtn::RIGHT]);
EXPECT_EQ(3, ctxt.num_actions()); EXPECT_EQ(3, ctxt.num_actions());
EXPECT_EQ(0, ctxt.num_unclosed());
} }
TEST(ActionCtxtTest, stacking) { TEST(ActionCtxtTest, stacking) {
@ -109,6 +111,7 @@ TEST(ActionCtxtTest, stacking) {
EXPECT_EQ(id1, ctxt.has_action(mousebtn::LEFT, 7)); EXPECT_EQ(id1, ctxt.has_action(mousebtn::LEFT, 7));
EXPECT_EQ(3, ctxt.num_actions()); EXPECT_EQ(3, ctxt.num_actions());
EXPECT_EQ(0, ctxt.num_unclosed());
} }
TEST(ActionCtxtTest, cmd) { TEST(ActionCtxtTest, cmd) {