diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-03-31 23:57:59 +0200 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:19:28 +0200 | 
| commit | 8c85e1c10085d6d634e35a63f0fc7b68a1b28eff (patch) | |
| tree | a09c12c3d0ed3269e6bc1f789da95ef3967b36d1 /test | |
| parent | 5aed7c46cff192311a208dc5e9cf7f81a40771a8 (diff) | |
Remove "inherit" flag in TokenStack, add tiny unit test for TokenStack, temporarily remove pushTokens and popTokens calls from DocumentChildHandler
Diffstat (limited to 'test')
| -rw-r--r-- | test/core/parser/stack/TokenStackTest.cpp | 79 | 
1 files changed, 79 insertions, 0 deletions
| 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 <http://www.gnu.org/licenses/>. +*/ + +#include <gtest/gtest.h> + +#include <core/parser/stack/TokenStack.hpp> + +namespace ousia { +namespace parser_stack { + +static Manager mgr; + +static Rooted<Node> nd1{new Node(mgr)}; +static Rooted<Node> nd2{new Node(mgr)}; +static Rooted<Node> nd3{new Node(mgr)}; + +static const std::vector<SyntaxDescriptor> 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<SyntaxDescriptor> ListB{ +    SyntaxDescriptor(Tokens::Empty, 1, Tokens::Empty, nd1, -1), +    SyntaxDescriptor(2, Tokens::Empty, 3, nd3, 3), +}; + +static const std::vector<SyntaxDescriptor> 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]); +} +} +} | 
