From 2edd0e40cd1afa9a422733b0a3b4babc064041b6 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 17 Feb 2015 00:52:25 +0100 Subject: Improved behaviour of FileLocator: * really complete path, do not return completely new path * return file directly if it already exists * only complete the extension, nothing else * also ignore .backup files created by KDE programs --- test/plugins/filesystem/FileLocatorTest.cpp | 54 ++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) (limited to 'test/plugins/filesystem') diff --git a/test/plugins/filesystem/FileLocatorTest.cpp b/test/plugins/filesystem/FileLocatorTest.cpp index 361a3ca..22db926 100644 --- a/test/plugins/filesystem/FileLocatorTest.cpp +++ b/test/plugins/filesystem/FileLocatorTest.cpp @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -142,10 +144,11 @@ TEST(FileLocator, locate) assert_not_located(locator, "c.txt", "", ResourceType::SCRIPT); } -TEST(FileLocator, locateAbsolute){ +TEST(FileLocator, locateAbsolute) +{ FileLocator locator; - // construct the absolute path by utilizing SpecialPaths and - fs::path testdataDir {SpecialPaths::getDebugTestdataDir()}; + // construct the absolute path by utilizing SpecialPaths and + fs::path testdataDir{SpecialPaths::getDebugTestdataDir()}; fs::path absolute = fs::canonical(testdataDir); absolute /= "filesystem"; absolute /= "a.txt"; @@ -217,7 +220,50 @@ TEST(FileLocator, testDefaultSearchPaths) assert_located(locator, "domain/book.osxml", "", ResourceType::UNKNOWN); assert_located(locator, "book.osxml", "", ResourceType::DOMAIN_DESC); assert_not_located(locator, "color.osxml", "", ResourceType::UNKNOWN); - assert_located(locator, "typesystem/color.osxml", "", ResourceType::UNKNOWN); + assert_located(locator, "typesystem/color.osxml", "", + ResourceType::UNKNOWN); assert_located(locator, "color.osxml", "", ResourceType::TYPESYSTEM); } + +TEST(FileLocator, autocompleteIgnoreBackupFiles) +{ + FileLocator locator; + locator.addUnittestSearchPath("filesystem"); + + auto res = locator.autocomplete("autocomplete/a"); + ASSERT_EQ(std::vector{"autocomplete/a.test"}, res); +} + +TEST(FileLocator, autocompleteAmbiguous) +{ + FileLocator locator; + locator.addUnittestSearchPath("filesystem"); + + auto res = locator.autocomplete("autocomplete/b"); + + std::set resSet; + resSet.insert(res.begin(), res.end()); + + ASSERT_EQ( + std::set({"autocomplete/b.test1", "autocomplete/b.test2"}), + resSet); +} + +TEST(FileLocator, autocompleteExisting) +{ + FileLocator locator; + locator.addUnittestSearchPath("filesystem"); + + auto res = locator.autocomplete("autocomplete/c"); + ASSERT_EQ(std::vector{"autocomplete/c"}, res); +} + +TEST(FileLocator, autocompleteExtensionOnly) +{ + FileLocator locator; + locator.addUnittestSearchPath("filesystem"); + + auto res = locator.autocomplete("autocomplete/d"); + ASSERT_EQ(std::vector{}, res); +} } -- cgit v1.2.3