summaryrefslogtreecommitdiff
path: root/test/plugins
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-05 13:52:40 +0100
committerAndreas Stöckel <andreas@somweyr.de>2014-12-05 13:52:40 +0100
commitddbea4164e126739f39658627c04e7e23b71e090 (patch)
treebdac63cf2a1c73fd3f67fa03fc821ef4eaf93b83 /test/plugins
parent3d6058315f7f0da9994e35c144d0acb76a252472 (diff)
parent9cb01624a4efe2063d5870f41e033476d9368b6d (diff)
fixed conflict
Diffstat (limited to 'test/plugins')
-rw-r--r--test/plugins/css/CSSParserTest.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/test/plugins/css/CSSParserTest.cpp b/test/plugins/css/CSSParserTest.cpp
new file mode 100644
index 0000000..84d4893
--- /dev/null
+++ b/test/plugins/css/CSSParserTest.cpp
@@ -0,0 +1,120 @@
+/*
+ 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 <sstream>
+
+#include <plugins/css/CSSParser.hpp>
+
+namespace ousia {
+namespace parser {
+namespace css {
+TEST(CSSParser, testParseSelectors)
+{
+ // create a string describing a SelectorTree as input.
+ std::stringstream input;
+ input << "A>B,A B:r, C#a A[bla=\"blub\"], A::g(4,2,3)";
+ /* This should describe the tree:
+ * root_____
+ * | \ \
+ * A C#a A::g(4,2,3)
+ * |\ \
+ * B B::r A[bla="blub"]
+ */
+
+ // initialize an empty parser context.
+ StandaloneParserContext ctx;
+
+ // parse the input.
+ CSSParser instance;
+ Rooted<SelectorNode> root = instance.parse(input, ctx).cast<SelectorNode>();
+
+ // we expect three children of the root node overall.
+ ASSERT_EQ(3, root->getEdges().size());
+ // get all "A" children, which should be two.
+ std::vector<Rooted<SelectorNode>> children = root->getChildren("A");
+ ASSERT_EQ(2, children.size());
+ // assert A
+ Rooted<SelectorNode> A = children[0];
+ ASSERT_EQ("A", A->getName());
+ {
+ PseudoSelector select{"true", false};
+ ASSERT_EQ(select, A->getPseudoSelector());
+ }
+ ASSERT_EQ(2, A->getEdges().size());
+ {
+ // assert A > B
+ std::vector<Rooted<SelectorNode>> Achildren =
+ A->getChildren(SelectionOperator::DIRECT_DESCENDANT, "B");
+ ASSERT_EQ(1, Achildren.size());
+ Rooted<SelectorNode> B = Achildren[0];
+ ASSERT_EQ("B", B->getName());
+ {
+ PseudoSelector select{"true", false};
+ ASSERT_EQ(select, B->getPseudoSelector());
+ }
+ ASSERT_EQ(0, B->getEdges().size());
+ // assert A B:r
+ Achildren = A->getChildren(SelectionOperator::DESCENDANT, "B");
+ ASSERT_EQ(1, Achildren.size());
+ Rooted<SelectorNode> Br = Achildren[0];
+ ASSERT_EQ("B", Br->getName());
+ {
+ PseudoSelector select{"r", false};
+ ASSERT_EQ(select, Br->getPseudoSelector());
+ }
+ ASSERT_EQ(0, Br->getEdges().size());
+ }
+ // assert C#a
+ children = root->getChildren("C");
+ ASSERT_EQ(1, children.size());
+ Rooted<SelectorNode> C = children[0];
+ ASSERT_EQ("C", C->getName());
+ {
+ PseudoSelector select{"has_id", {"a"}, false};
+ ASSERT_EQ(select, C->getPseudoSelector());
+ }
+ ASSERT_EQ(1, C->getEdges().size());
+ {
+ // assert C#a A[bla=\"blub\"]
+ std::vector<Rooted<SelectorNode>> Cchildren =
+ C->getChildren(SelectionOperator::DESCENDANT, "A");
+ ASSERT_EQ(1, Cchildren.size());
+ Rooted<SelectorNode> A = Cchildren[0];
+ ASSERT_EQ("A", A->getName());
+ {
+ PseudoSelector select{"has_value", {"bla", "blub"}, false};
+ ASSERT_EQ(select, A->getPseudoSelector());
+ }
+ ASSERT_EQ(0, A->getEdges().size());
+ }
+ // assert A::g(4,2,3)
+ children = root->getChildren("A");
+ ASSERT_EQ(2, children.size());
+ Rooted<SelectorNode> Ag = children[1];
+ ASSERT_EQ("A", Ag->getName());
+ {
+ PseudoSelector select{"g", {"4", "2", "3"}, true};
+ ASSERT_EQ(select, Ag->getPseudoSelector());
+ }
+ ASSERT_EQ(0, Ag->getEdges().size());
+}
+}
+}
+}