Support conversion of linkshere
[dueringa_WikiWalker.git] / test / CollectionTests.cpp
blob3b38651b281ed061943b62fa2658482eaa6bd63e
1 #include <memory>
3 #include <UnitTest++/UnitTest++.h>
5 #include "Article.h"
6 #include "ArticleCollection.h"
8 SUITE(CollectionTests)
10 using namespace WikiWalker;
11 using namespace WikiWalker::CollectionUtils;
13 TEST(MakeSureNoDuplicateArticlesExist)
15 ArticleCollection w;
16 auto la1 = std::make_shared<Article>("King"),
17 la2 = std::make_shared<Article>("Queen"),
18 la3 = std::make_shared<Article>("Prince"),
19 la4 = std::make_shared<Article>("Queen");
21 CHECK(CollectionUtils::add(w, la1));
22 CHECK(CollectionUtils::add(w, la2));
23 CHECK_EQUAL(2, w.size());
24 CHECK(CollectionUtils::add(w, la3));
25 CHECK_EQUAL(3, w.size());
27 // must fail
28 CHECK(!CollectionUtils::add(w, la4));
29 CHECK_EQUAL(3, w.size());
32 TEST(CollectionIsCaseInsensitive)
34 ArticleCollection w;
35 auto la1 = std::make_shared<Article>("King"),
36 la2 = std::make_shared<Article>("Queen"),
37 la3 = std::make_shared<Article>("Prince"),
38 la4 = std::make_shared<Article>("queen");
40 CollectionUtils::add(w, la1);
41 CollectionUtils::add(w, la2);
42 CHECK_EQUAL(2, w.size());
43 CollectionUtils::add(w, la3);
44 CHECK_EQUAL(3, w.size());
45 CollectionUtils::add(w, la4);
46 CHECK_EQUAL(4, w.size());
49 TEST(GetArticle_Existing_MustNotBeNull)
51 ArticleCollection w;
52 auto king = std::make_shared<Article>("King");
53 CollectionUtils::add(w, king);
54 CHECK(CollectionUtils::get(w, "King") != nullptr);
57 TEST(GetArticle_NonExisting_MustBeNull)
59 ArticleCollection w;
60 auto la1 = std::make_shared<Article>("King");
61 CollectionUtils::add(w, la1);
62 CHECK(CollectionUtils::get(w, "Queen") == nullptr);
65 ArticleCollection GetArticleCollection()
67 ArticleCollection ac;
68 CollectionUtils::add(ac, std::make_shared<Article>("Foo"));
69 CollectionUtils::add(ac, std::make_shared<Article>("Bar"));
70 return ac;
73 TEST(ArticleCollection_CreationViaMoveConstructor)
75 auto ac = GetArticleCollection();
76 CHECK_EQUAL(2, ac.size());
77 CHECK(CollectionUtils::get(ac, "Foo") != nullptr);