diff --git a/lldb/unittests/Interpreter/TestCompletion.cpp b/lldb/unittests/Interpreter/TestCompletion.cpp index 5db7f83db0f9..450f7b22703e 100644 --- a/lldb/unittests/Interpreter/TestCompletion.cpp +++ b/lldb/unittests/Interpreter/TestCompletion.cpp @@ -51,6 +51,7 @@ protected: static SmallString<128> DirBar; static SmallString<128> DirBaz; static SmallString<128> DirTestFolder; + static SmallString<128> DirNested; static SmallString<128> FileAA; static SmallString<128> FileAB; @@ -65,17 +66,17 @@ protected: llvm::sys::fs::current_path(OriginalWorkingDir); ASSERT_NO_ERROR(fs::createUniqueDirectory("FsCompletion", BaseDir)); - const char *DirNames[] = {"foo", "fooa", "foob", "fooc", - "bar", "baz", "test_folder"}; + const char *DirNames[] = {"foo", "fooa", "foob", "fooc", + "bar", "baz", "test_folder", "foo/nested"}; const char *FileNames[] = {"aa1234.tmp", "ab1234.tmp", "ac1234.tmp", "foo1234.tmp", "bar1234.tmp", "baz1234.tmp"}; - SmallString<128> *Dirs[] = {&DirFoo, &DirFooA, &DirFooB, &DirFooC, - &DirBar, &DirBaz, &DirTestFolder}; + SmallString<128> *Dirs[] = {&DirFoo, &DirFooA, &DirFooB, &DirFooC, + &DirBar, &DirBaz, &DirTestFolder, &DirNested}; for (auto Dir : llvm::zip(DirNames, Dirs)) { auto &Path = *std::get<1>(Dir); Path = BaseDir; path::append(Path, std::get<0>(Dir)); - ASSERT_NO_ERROR(fs::create_directory(Path)); + ASSERT_NO_ERROR(fs::create_directories(Path)); } SmallString<128> *Files[] = {&FileAA, &FileAB, &FileAC, @@ -146,6 +147,7 @@ SmallString<128> CompletionTest::DirFooC; SmallString<128> CompletionTest::DirBar; SmallString<128> CompletionTest::DirBaz; SmallString<128> CompletionTest::DirTestFolder; +SmallString<128> CompletionTest::DirNested; SmallString<128> CompletionTest::FileAA; SmallString<128> CompletionTest::FileAB; @@ -280,6 +282,20 @@ TEST_F(CompletionTest, DirCompletionUsername) { EXPECT_TRUE(ContainsExactString( Twine("~/test_folder") + path::get_separator(), Results)); + // Check that we can complete directories in nested paths + Count = CommandCompletions::DiskDirectories("~/foo/", Results, Resolver); + ASSERT_EQ(1u, Count); + ASSERT_EQ(Count, Results.GetSize()); + EXPECT_TRUE(ContainsExactString(Twine("~/foo") + path::get_separator() + + "nested" + path::get_separator(), + Results)); + Count = CommandCompletions::DiskDirectories("~/foo/nes", Results, Resolver); + ASSERT_EQ(1u, Count); + ASSERT_EQ(Count, Results.GetSize()); + EXPECT_TRUE(ContainsExactString(Twine("~/foo") + path::get_separator() + + "nested" + path::get_separator(), + Results)); + // With ~username syntax it should return one match if there is an exact // match. // It shouldn't translate to the actual directory, it should keep the form the