From 8c85e1c10085d6d634e35a63f0fc7b68a1b28eff Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 31 Mar 2015 23:57:59 +0200 Subject: Remove "inherit" flag in TokenStack, add tiny unit test for TokenStack, temporarily remove pushTokens and popTokens calls from DocumentChildHandler --- test/core/parser/stack/TokenStackTest.cpp | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 test/core/parser/stack/TokenStackTest.cpp (limited to 'test') diff --git a/test/core/parser/stack/TokenStackTest.cpp b/test/core/parser/stack/TokenStackTest.cpp new file mode 100644 index 0000000..c14de1c --- /dev/null +++ b/test/core/parser/stack/TokenStackTest.cpp @@ -0,0 +1,79 @@ +/* + Ousía + Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +#include + +namespace ousia { +namespace parser_stack { + +static Manager mgr; + +static Rooted nd1{new Node(mgr)}; +static Rooted nd2{new Node(mgr)}; +static Rooted nd3{new Node(mgr)}; + +static const std::vector ListA{ + SyntaxDescriptor(Tokens::Empty, 1, Tokens::Empty, nd1, 0), + SyntaxDescriptor(2, Tokens::Empty, Tokens::Empty, nd2, 2), + SyntaxDescriptor(3, Tokens::Empty, Tokens::Empty, nd3, 1)}; + +static const std::vector ListB{ + SyntaxDescriptor(Tokens::Empty, 1, Tokens::Empty, nd1, -1), + SyntaxDescriptor(2, Tokens::Empty, 3, nd3, 3), +}; + +static const std::vector ListC{ + SyntaxDescriptor(Tokens::Empty, Tokens::Empty, 4, nd2, 5), + SyntaxDescriptor(Tokens::Empty, Tokens::Empty, 3, nd3, 6), +}; + +TEST(TokenStack, tokens) +{ + TokenStack ts; + ASSERT_EQ((TokenSet{}), ts.tokens()); + ts.pushTokens(ListA); + ASSERT_EQ((TokenSet{1, 2, 3}), ts.tokens()); + ts.pushTokens(ListB); + ASSERT_EQ((TokenSet{1, 2, 3}), ts.tokens()); + ts.pushTokens(ListC); + ASSERT_EQ((TokenSet{3, 4}), ts.tokens()); + ts.popTokens(); + ASSERT_EQ((TokenSet{1, 2, 3}), ts.tokens()); + ts.popTokens(); + ASSERT_EQ((TokenSet{1, 2, 3}), ts.tokens()); + ts.popTokens(); + ASSERT_EQ((TokenSet{}), ts.tokens()); +} + +TEST(TokenStack, lookup) +{ + TokenStack ts; + ts.pushTokens(ListA); + ts.pushTokens(ListB); + ts.pushTokens(ListC); + + TokenDescriptor descr = ts.lookup(3); + ASSERT_EQ(0U, descr.open.size()); + ASSERT_EQ(0U, descr.close.size()); + ASSERT_EQ(1U, descr.shortForm.size()); + ASSERT_EQ(ListC[1], descr.shortForm[0]); +} +} +} -- cgit v1.2.3