/* 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 { TEST(CSSParser, testParseSelectors) { // create a selector Tree as input. BufferedCharReader reader; reader.feed("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"] */ // parse the input. CSSParser instance; Rooted root = instance.parse(reader); // 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> children = root->getChildren("A"); ASSERT_EQ(2, children.size()); // assert A Rooted 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> Achildren = A->getChildren(SelectionOperator::DIRECT_DESCENDANT, "B"); ASSERT_EQ(1, Achildren.size()); Rooted 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 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 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> Cchildren = C->getChildren(SelectionOperator::DESCENDANT, "A"); ASSERT_EQ(1, Cchildren.size()); Rooted 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 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()); } }