aboutsummaryrefslogtreecommitdiff
path: root/paludis/fuzzy_finder_TEST.cc
diff options
context:
space:
mode:
Diffstat (limited to 'paludis/fuzzy_finder_TEST.cc')
-rw-r--r--paludis/fuzzy_finder_TEST.cc178
1 files changed, 85 insertions, 93 deletions
diff --git a/paludis/fuzzy_finder_TEST.cc b/paludis/fuzzy_finder_TEST.cc
index eff7bf0a4..775454ebf 100644
--- a/paludis/fuzzy_finder_TEST.cc
+++ b/paludis/fuzzy_finder_TEST.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2007 Fernando J. Pereda
+ * Copyright (c) 2011 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
@@ -19,107 +20,98 @@
#include <paludis/fuzzy_finder.hh>
#include <paludis/filter.hh>
+
#include <paludis/environments/test/test_environment.hh>
+
#include <paludis/repositories/fake/fake_repository.hh>
#include <paludis/repositories/fake/fake_installed_repository.hh>
#include <paludis/repositories/fake/fake_package_id.hh>
+
#include <paludis/util/wrapped_forward_iterator.hh>
#include <paludis/util/make_named_values.hh>
-#include <test/test_framework.hh>
-#include <test/test_runner.hh>
+#include <paludis/util/stringify.hh>
+
+#include <gtest/gtest.h>
using namespace paludis;
-using namespace test;
-namespace test_cases
+TEST(FuzzyCandidatesFinder, Works)
{
- struct FuzzyCandidatesFinderTest : TestCase
- {
- FuzzyCandidatesFinderTest() : TestCase("fuzzy candidates finder") { }
-
- void run()
- {
- TestEnvironment e;
-
- const std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("r1")
- )));
- r1->add_version("some-cat", "foo", "1");
- r1->add_version("other-cat", "foo", "1");
- r1->add_version("some-cat", "bar", "1");
- r1->add_version("some-cat", "one-two-three", "1");
- e.add_repository(1, r1);
-
- const std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("r2")
- )));
- e.add_repository(2, r2);
-
- FuzzyCandidatesFinder f1(e, std::string("some-cat/one-two-thee"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f1.begin(), f1.end()), 1);
-
- FuzzyCandidatesFinder f2(e, std::string("fio"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f2.begin(), f2.end()), 2);
-
- FuzzyCandidatesFinder f3(e, std::string("bra"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f3.begin(), f3.end()), 1);
-
- FuzzyCandidatesFinder f4(e, std::string("foobarandfriends"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f4.begin(), f4.end()), 0);
-
- FuzzyCandidatesFinder f5(e, std::string("some-cat/foo::r2"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f5.begin(), f5.end()), 0);
-
- FuzzyCandidatesFinder f6(e, std::string("some-cat/OnE-tWo-THEE"), filter::All());
- TEST_CHECK_EQUAL(std::distance(f6.begin(), f6.end()), 1);
-
- }
- } fuzzy_candidates_finder_test;
-
- struct FuzzyRepositoriesFinderTest : TestCase
- {
- FuzzyRepositoriesFinderTest() : TestCase("fuzzy repositories finder") { }
-
- void run()
- {
- TestEnvironment e;
-
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("my-main-repository")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("x-new-repository")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("bar-overlay")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("baz-overlay")))));
- e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
- n::environment() = &e,
- n::name() = RepositoryName("sunrise")))));
-
- FuzzyRepositoriesFinder f1(e, "my-main-respository");
- TEST_CHECK_EQUAL(std::distance(f1.begin(), f1.end()), 1);
-
- FuzzyRepositoriesFinder f2(e, "new-repository");
- TEST_CHECK_EQUAL(std::distance(f2.begin(), f2.end()), 1);
- TEST_CHECK_EQUAL(stringify(*f2.begin()), "x-new-repository");
-
- FuzzyRepositoriesFinder f3(e, "sunric3");
- TEST_CHECK_EQUAL(std::distance(f3.begin(), f3.end()), 1);
-
- FuzzyRepositoriesFinder f4(e, "bar-overlay");
- TEST_CHECK_EQUAL(std::distance(f4.begin(), f4.end()), 2);
-
- FuzzyRepositoriesFinder f5(e, "foo");
- TEST_CHECK_EQUAL(std::distance(f5.begin(), f5.end()), 0);
-
- FuzzyRepositoriesFinder f6(e, "new-repositori");
- TEST_CHECK_EQUAL(std::distance(f6.begin(), f6.end()), 1);
- }
- } fuzzy_repositories_finder_test;
+ TestEnvironment e;
+
+ const std::shared_ptr<FakeRepository> r1(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("r1")
+ )));
+ r1->add_version("some-cat", "foo", "1");
+ r1->add_version("other-cat", "foo", "1");
+ r1->add_version("some-cat", "bar", "1");
+ r1->add_version("some-cat", "one-two-three", "1");
+ e.add_repository(1, r1);
+
+ const std::shared_ptr<FakeRepository> r2(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("r2")
+ )));
+ e.add_repository(2, r2);
+
+ FuzzyCandidatesFinder f1(e, std::string("some-cat/one-two-thee"), filter::All());
+ EXPECT_EQ(1, std::distance(f1.begin(), f1.end()));
+
+ FuzzyCandidatesFinder f2(e, std::string("fio"), filter::All());
+ EXPECT_EQ(2, std::distance(f2.begin(), f2.end()));
+
+ FuzzyCandidatesFinder f3(e, std::string("bra"), filter::All());
+ EXPECT_EQ(1, std::distance(f3.begin(), f3.end()));
+
+ FuzzyCandidatesFinder f4(e, std::string("foobarandfriends"), filter::All());
+ EXPECT_EQ(0, std::distance(f4.begin(), f4.end()));
+
+ FuzzyCandidatesFinder f5(e, std::string("some-cat/foo::r2"), filter::All());
+ EXPECT_EQ(0, std::distance(f5.begin(), f5.end()));
+
+ FuzzyCandidatesFinder f6(e, std::string("some-cat/OnE-tWo-THEE"), filter::All());
+ EXPECT_EQ(1, std::distance(f6.begin(), f6.end()));
+
}
+
+TEST(FuzzyRepositoriesFinder, Works)
+{
+ TestEnvironment e;
+
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("my-main-repository")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("x-new-repository")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("bar-overlay")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("baz-overlay")))));
+ e.add_repository(1, std::shared_ptr<FakeRepository>(std::make_shared<FakeRepository>(make_named_values<FakeRepositoryParams>(
+ n::environment() = &e,
+ n::name() = RepositoryName("sunrise")))));
+
+ FuzzyRepositoriesFinder f1(e, "my-main-respository");
+ EXPECT_EQ(1, std::distance(f1.begin(), f1.end()));
+
+ FuzzyRepositoriesFinder f2(e, "new-repository");
+ EXPECT_EQ(1, std::distance(f2.begin(), f2.end()));
+ EXPECT_EQ("x-new-repository", stringify(*f2.begin()));
+
+ FuzzyRepositoriesFinder f3(e, "sunric3");
+ EXPECT_EQ(1, std::distance(f3.begin(), f3.end()));
+
+ FuzzyRepositoriesFinder f4(e, "bar-overlay");
+ EXPECT_EQ(2, std::distance(f4.begin(), f4.end()));
+
+ FuzzyRepositoriesFinder f5(e, "foo");
+ EXPECT_EQ(0, std::distance(f5.begin(), f5.end()));
+
+ FuzzyRepositoriesFinder f6(e, "new-repositori");
+ EXPECT_EQ(1, std::distance(f6.begin(), f6.end()));
+}
+