/// be placed. It is removed at the end of the test suite.
static SmallString<128> BaseDir;
+ static SmallString<128> OriginalWorkingDir;
+
static SmallString<128> DirFoo;
static SmallString<128> DirFooA;
static SmallString<128> DirFooB;
static SmallString<128> FileBar;
static SmallString<128> FileBaz;
+ void SetUp() override { llvm::sys::fs::set_current_path(OriginalWorkingDir); }
+
static void SetUpTestCase() {
+ llvm::sys::fs::current_path(OriginalWorkingDir);
+
ASSERT_NO_ERROR(fs::createUniqueDirectory("FsCompletion", BaseDir));
const char *DirNames[] = {"foo", "fooa", "foob", "fooc",
"bar", "baz", "test_folder"};
}
return false;
}
+
+ void DoDirCompletions(const Twine &Prefix,
+ StandardTildeExpressionResolver &Resolver,
+ StringList &Results) {
+ // When a partial name matches, it returns all matches. If it matches both
+ // a full name AND some partial names, it returns all of them.
+ uint32_t Count =
+ CommandCompletions::DiskDirectories(Prefix + "foo", Results, Resolver);
+ ASSERT_EQ(4u, Count);
+ ASSERT_EQ(Count, Results.GetSize());
+ EXPECT_TRUE(HasEquivalentFile(DirFoo, Results));
+ EXPECT_TRUE(HasEquivalentFile(DirFooA, Results));
+ EXPECT_TRUE(HasEquivalentFile(DirFooB, Results));
+ EXPECT_TRUE(HasEquivalentFile(DirFooC, Results));
+
+ // If it matches only partial names, it still works as expected.
+ Count = CommandCompletions::DiskDirectories(Twine(Prefix) + "b", Results,
+ Resolver);
+ ASSERT_EQ(2u, Count);
+ ASSERT_EQ(Count, Results.GetSize());
+ EXPECT_TRUE(HasEquivalentFile(DirBar, Results));
+ EXPECT_TRUE(HasEquivalentFile(DirBaz, Results));
+ }
};
SmallString<128> CompletionTest::BaseDir;
+SmallString<128> CompletionTest::OriginalWorkingDir;
SmallString<128> CompletionTest::DirFoo;
SmallString<128> CompletionTest::DirFooA;
// by asserting an exact result count, and verifying against known
// folders.
+ std::string Prefixes[] = {(Twine(BaseDir) + "/").str(), ""};
+
StandardTildeExpressionResolver Resolver;
StringList Results;
+
// When a directory is specified that doesn't end in a slash, it searches
// for that directory, not items under it.
size_t Count =
EXPECT_TRUE(HasEquivalentFile(BaseDir, Results));
// When the same directory ends with a slash, it finds all children.
- Count = CommandCompletions::DiskDirectories(Twine(BaseDir) + "/", Results,
- Resolver);
+ Count = CommandCompletions::DiskDirectories(Prefixes[0], Results, Resolver);
ASSERT_EQ(7u, Count);
ASSERT_EQ(Count, Results.GetSize());
EXPECT_TRUE(HasEquivalentFile(DirFoo, Results));
EXPECT_TRUE(HasEquivalentFile(DirBaz, Results));
EXPECT_TRUE(HasEquivalentFile(DirTestFolder, Results));
- // When a partial name matches, it returns all matches. If it matches both
- // a full name AND some partial names, it returns all of them.
- Count = CommandCompletions::DiskDirectories(Twine(BaseDir) + "/foo", Results,
- Resolver);
- ASSERT_EQ(4u, Count);
- ASSERT_EQ(Count, Results.GetSize());
- EXPECT_TRUE(HasEquivalentFile(DirFoo, Results));
- EXPECT_TRUE(HasEquivalentFile(DirFooA, Results));
- EXPECT_TRUE(HasEquivalentFile(DirFooB, Results));
- EXPECT_TRUE(HasEquivalentFile(DirFooC, Results));
-
- // If it matches only partial names, it still works as expected.
- Count = CommandCompletions::DiskDirectories(Twine(BaseDir) + "/b", Results,
- Resolver);
- ASSERT_EQ(2u, Count);
- ASSERT_EQ(Count, Results.GetSize());
- EXPECT_TRUE(HasEquivalentFile(DirBar, Results));
- EXPECT_TRUE(HasEquivalentFile(DirBaz, Results));
+ DoDirCompletions(Twine(BaseDir) + "/", Resolver, Results);
+ llvm::sys::fs::set_current_path(BaseDir);
+ DoDirCompletions("", Resolver, Results);
}
TEST_F(CompletionTest, FileCompletionAbsolute) {