aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-05-24 00:03:40 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2013-05-24 00:03:40 +0100
commit8c1d1b87bec1c2b81ec8da4318c96bc4181ab4f9 (patch)
tree741c2f7eea64914b88c3ca17a22500cf49f53587
parenta5869415c0fa992ccfba64f9e2619983ec2f73c1 (diff)
downloadpaludis-8c1d1b87bec1c2b81ec8da4318c96bc4181ab4f9.tar.gz
paludis-8c1d1b87bec1c2b81ec8da4318c96bc4181ab4f9.tar.xz
Convert to fancy new visitors
-rw-r--r--paludis/repositories/fake/dep_parser_TEST.cc92
1 files changed, 39 insertions, 53 deletions
diff --git a/paludis/repositories/fake/dep_parser_TEST.cc b/paludis/repositories/fake/dep_parser_TEST.cc
index d5eb854..f48ae05 100644
--- a/paludis/repositories/fake/dep_parser_TEST.cc
+++ b/paludis/repositories/fake/dep_parser_TEST.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009, 2010, 2011 Ciaran McCreesh
+ * Copyright (c) 2008, 2009, 2010, 2011, 2013 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -31,62 +31,48 @@
using namespace paludis;
-namespace
-{
- struct QuickPrinter
- {
- std::stringstream str;
-
- void visit(const DependencySpecTree::NodeType<PackageDepSpec>::Type & node)
- {
- str << "p<" << stringify(*node.spec()) << ">";
- }
-
- void visit(const DependencySpecTree::NodeType<NamedSetDepSpec>::Type & node)
- {
- str << "s<" << stringify(*node.spec()) << ">";
- }
-
- void visit(const DependencySpecTree::NodeType<BlockDepSpec>::Type & node)
- {
- str << "b<" << stringify(*node.spec()) << ">";
- }
-
- void visit(const DependencySpecTree::NodeType<DependenciesLabelsDepSpec>::Type & node)
- {
- str << "l<" << stringify(*node.spec()) << ">";
- }
-
- void visit(const DependencySpecTree::NodeType<AllDepSpec>::Type & node)
- {
- str << "all<";
- std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
- str << ">";
- }
-
- void visit(const DependencySpecTree::NodeType<AnyDepSpec>::Type & node)
- {
- str << "any<";
- std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
- str << ">";
- }
-
- void visit(const DependencySpecTree::NodeType<ConditionalDepSpec>::Type & node)
- {
- str << "cond<" << *node.spec() << ",";
- std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), accept_visitor(*this));
- str << ">";
- }
- };
-}
-
TEST(DepParser, Works)
{
TestEnvironment env;
std::shared_ptr<DependencySpecTree> d(fakerepository::parse_depend("( ( a/a b/b ) )", &env));
- QuickPrinter p;
- d->top()->accept(p);
- EXPECT_EQ("all<all<all<p<a/a>p<b/b>>>>", p.str.str());
+ std::stringstream str;
+ d->top()->make_accept(
+ [&] (const DependencySpecTree::NodeType<PackageDepSpec>::Type & node) {
+ str << "p<" << stringify(*node.spec()) << ">";
+ },
+
+ [&] (const DependencySpecTree::NodeType<NamedSetDepSpec>::Type & node) {
+ str << "s<" << stringify(*node.spec()) << ">";
+ },
+
+ [&] (const DependencySpecTree::NodeType<BlockDepSpec>::Type & node) {
+ str << "b<" << stringify(*node.spec()) << ">";
+ },
+
+ [&] (const DependencySpecTree::NodeType<DependenciesLabelsDepSpec>::Type & node) {
+ str << "l<" << stringify(*node.spec()) << ">";
+ },
+
+ [&] (const DependencySpecTree::NodeType<AllDepSpec>::Type & node, const Revisit<void, DependencySpecTree::BasicNode> & revisit) {
+ str << "all<";
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), revisit);
+ str << ">";
+ },
+
+ [&] (const DependencySpecTree::NodeType<AnyDepSpec>::Type & node, const Revisit<void, DependencySpecTree::BasicNode> & revisit) {
+ str << "any<";
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), revisit);
+ str << ">";
+ },
+
+ [&] (const DependencySpecTree::NodeType<ConditionalDepSpec>::Type & node, const Revisit<void, DependencySpecTree::BasicNode> & revisit) {
+ str << "cond<" << *node.spec() << ",";
+ std::for_each(indirect_iterator(node.begin()), indirect_iterator(node.end()), revisit);
+ str << ">";
+ }
+ );
+
+ EXPECT_EQ("all<all<all<p<a/a>p<b/b>>>>", str.str());
}