From b3a797f33636eef729bf2041c75c6f37348449f1 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Wed, 14 Aug 2019 17:34:34 +0300 Subject: [PATCH] [search] [bookmarks] Refactored the tests. So far bookmarks::Data has only been growing. This commit leaves it with one (general) constructor, thus shifting the code duplication from the class to its tests. --- search/bookmarks/data.hpp | 5 --- .../bookmarks_processor_tests.cpp | 42 ++++++++++++------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/search/bookmarks/data.hpp b/search/bookmarks/data.hpp index 2889db8a9b..3d23d6d92c 100644 --- a/search/bookmarks/data.hpp +++ b/search/bookmarks/data.hpp @@ -19,11 +19,6 @@ struct Data { Data() = default; - Data(std::string const & name, std::string customName, std::string const & description) - : m_name(name), m_customName(customName), m_description(description) - { - } - Data(kml::BookmarkData const & bookmarkData) : m_name(kml::GetDefaultStr(bookmarkData.m_name)) , m_customName(kml::GetDefaultStr(bookmarkData.m_customName)) diff --git a/search/search_tests/bookmarks_processor_tests.cpp b/search/search_tests/bookmarks_processor_tests.cpp index ec53c7dbdc..1d657349d6 100644 --- a/search/search_tests/bookmarks_processor_tests.cpp +++ b/search/search_tests/bookmarks_processor_tests.cpp @@ -71,20 +71,30 @@ protected: Processor m_processor; }; +kml::BookmarkData MakeBookmarkData(string const & name, string const & customName, + string const & description) +{ + kml::BookmarkData b; + b.m_name = {{kml::kDefaultLangCode, name}}; + b.m_customName = {{kml::kDefaultLangCode, customName}}; + b.m_description = {{kml::kDefaultLangCode, description}}; + return b; +} + UNIT_CLASS_TEST(BookmarksProcessorTest, Smoke) { GetProcessor().EnableIndexingOfDescriptions(true); - Add(10, {"Double R Diner" /* name */, - "2R Diner" /* customName */, - "They've got a cherry pie there that'll kill ya!" /* description */}); + Add(10, MakeBookmarkData("Double R Diner" /* name */, + "2R Diner" /* customName */, + "They've got a cherry pie there that'll kill ya!" /* description */)); - Add(18, {"Silver Mustang Casino" /* name */, - "Ag Mustang" /* customName */, - "Joyful place, owners Bradley and Rodney are very friendly!"}); - Add(20, {"Great Northern Hotel" /* name */, - "N Hotel" /* customName */, - "Clean place with a reasonable price" /* description */}); + Add(18, MakeBookmarkData("Silver Mustang Casino" /* name */, + "Ag Mustang" /* customName */, + "Joyful place, owners Bradley and Rodney are very friendly!")); + Add(20, MakeBookmarkData("Great Northern Hotel" /* name */, + "N Hotel" /* customName */, + "Clean place with a reasonable price" /* description */)); TEST_EQUAL(Search("R&R food"), Ids({10}), ()); TEST_EQUAL(Search("cherry pie"), Ids({10}), ()); @@ -108,9 +118,9 @@ UNIT_CLASS_TEST(BookmarksProcessorTest, IndexDescriptions) { GetProcessor().EnableIndexingOfDescriptions(true); - Add(10, {"Double R Diner" /* name */, - "2R Diner" /* customName */, - "They've got a cherry pie there that'll kill ya!" /* description */}); + Add(10, MakeBookmarkData("Double R Diner" /* name */, + "2R Diner" /* customName */, + "They've got a cherry pie there that'll kill ya!" /* description */)); TEST_EQUAL(Search("diner"), Ids({10}), ()); TEST_EQUAL(Search("cherry pie"), Ids({10}), ()); @@ -119,13 +129,13 @@ UNIT_CLASS_TEST(BookmarksProcessorTest, IndexDescriptions) TEST_EQUAL(Search("cherry pie"), Ids{}, ()); GetProcessor().EnableIndexingOfDescriptions(false); - Add(10, {"Double R Diner" /* name */, - "2R Diner" /* customName */, - "They've got a cherry pie there that'll kill ya!" /* description */}); + Add(10, MakeBookmarkData("Double R Diner" /* name */, + "2R Diner" /* customName */, + "They've got a cherry pie there that'll kill ya!" /* description */)); TEST_EQUAL(Search("diner"), Ids({10}), ()); TEST_EQUAL(Search("cherry pie"), Ids(), ()); - // Already indexed results don't change. + // Results for already indexed bookmarks don't change. GetProcessor().EnableIndexingOfDescriptions(true); TEST_EQUAL(Search("diner"), Ids({10}), ()); TEST_EQUAL(Search("cherry pie"), Ids(), ());