[lldb] Add unittests for a few FileSpec methods

This adds tests for:
- FileSpec::TestFileNameExtensions
- FileSpec::TestFileNameStrippingExtension
- FileSpec::IsSourceImplementationFile

This additionally updates incorrect documentation.

Differential Revision: https://reviews.llvm.org/D147801
This commit is contained in:
Alex Langford
2023-04-07 11:41:54 -07:00
parent 33cf2a39cb
commit de5f96e99a
2 changed files with 58 additions and 2 deletions

View File

@@ -253,7 +253,7 @@ public:
/// (files with a ".c", ".cpp", ".m", ".mm" (many more) extension).
///
/// \return
/// \b true if the filespec represents an implementation source
/// \b true if the FileSpec represents an implementation source
/// file, \b false otherwise.
bool IsSourceImplementationFile() const;
@@ -327,7 +327,7 @@ public:
/// Returns a ConstString that represents the extension of the filename for
/// this FileSpec object. If this object does not represent a file, or the
/// filename has no extension, ConstString(nullptr) is returned. The dot
/// ('.') character is not returned as part of the extension
/// ('.') character is the first character in the returned string.
///
/// \return Returns the extension of the file as a ConstString object.
ConstString GetFileNameExtension() const;

View File

@@ -448,3 +448,59 @@ TEST(FileSpecTest, TestAbsoluteCaching) {
file.PrependPathComponent("/tmp");
EXPECT_TRUE(file.IsAbsolute());
}
TEST(FileSpecTest, TestFileNameExtensions) {
FileSpec dylib = PosixSpec("/tmp/foo.dylib");
FileSpec exe = PosixSpec("/tmp/foo");
FileSpec dSYM = PosixSpec("/tmp/foo.dSYM/");
FileSpec just_dot = PosixSpec("/tmp/bar.");
EXPECT_TRUE(dylib.GetFileNameExtension() == ".dylib");
EXPECT_TRUE(exe.GetFileNameExtension() == ConstString(nullptr));
EXPECT_TRUE(dSYM.GetFileNameExtension() == ".dSYM");
EXPECT_TRUE(just_dot.GetFileNameExtension() == ".");
FileSpec dll = WindowsSpec("C:\\tmp\\foo.dll");
FileSpec win_noext = WindowsSpec("C:\\tmp\\foo");
EXPECT_TRUE(dll.GetFileNameExtension() == ".dll");
EXPECT_TRUE(win_noext.GetFileNameExtension() == ConstString(nullptr));
}
TEST(FileSpecTest, TestFileNameStrippingExtension) {
FileSpec dylib = PosixSpec("/tmp/foo.dylib");
FileSpec exe = PosixSpec("/tmp/foo");
FileSpec just_dot = PosixSpec("/tmp/bar.");
EXPECT_TRUE(dylib.GetFileNameStrippingExtension() == "foo");
EXPECT_TRUE(exe.GetFileNameStrippingExtension() == "foo");
EXPECT_TRUE(just_dot.GetFileNameStrippingExtension() == "bar");
FileSpec dll = WindowsSpec("C:\\tmp\\foo.dll");
FileSpec win_noext = WindowsSpec("C:\\tmp\\foo");
EXPECT_TRUE(dll.GetFileNameStrippingExtension() == "foo");
EXPECT_TRUE(win_noext.GetFileNameStrippingExtension() == "foo");
}
TEST(FileSpecTest, TestIsSourceImplementationFile) {
FileSpec c_src = PosixSpec("/tmp/foo.c");
FileSpec txt_file = PosixSpec("/tmp/foo.txt");
FileSpec executable = PosixSpec("/tmp/foo");
FileSpec just_dot = PosixSpec("/tmp/bar.");
EXPECT_TRUE(c_src.IsSourceImplementationFile());
EXPECT_FALSE(txt_file.IsSourceImplementationFile());
EXPECT_FALSE(executable.IsSourceImplementationFile());
EXPECT_FALSE(just_dot.IsSourceImplementationFile());
FileSpec cpp_src = WindowsSpec("C:\\tmp\\foo.cpp");
FileSpec dll = WindowsSpec("C:\\tmp\\foo.dll");
FileSpec win_noext = WindowsSpec("C:\\tmp\\foo");
FileSpec exe = WindowsSpec("C:\\tmp\\foo.exe");
EXPECT_TRUE(cpp_src.IsSourceImplementationFile());
EXPECT_FALSE(dll.IsSourceImplementationFile());
EXPECT_FALSE(win_noext.IsSourceImplementationFile());
EXPECT_FALSE(exe.IsSourceImplementationFile());
}