aboutsummaryrefslogtreecommitdiff
path: root/lldb
diff options
context:
space:
mode:
authorAlex Langford <alangford@apple.com>2023-04-07 11:41:54 -0700
committerAlex Langford <alangford@apple.com>2023-04-07 13:50:27 -0700
commitde5f96e99aedd641cc0bbb9ae4a156db4ae3c4c4 (patch)
tree8fa8fc4de14e3659de008589652910750fa1b536 /lldb
parent33cf2a39cb11681068b1abaa20ffe1d4d732ae38 (diff)
downloadllvm-de5f96e99aedd641cc0bbb9ae4a156db4ae3c4c4.zip
llvm-de5f96e99aedd641cc0bbb9ae4a156db4ae3c4c4.tar.gz
llvm-de5f96e99aedd641cc0bbb9ae4a156db4ae3c4c4.tar.bz2
[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
Diffstat (limited to 'lldb')
-rw-r--r--lldb/include/lldb/Utility/FileSpec.h4
-rw-r--r--lldb/unittests/Utility/FileSpecTest.cpp56
2 files changed, 58 insertions, 2 deletions
diff --git a/lldb/include/lldb/Utility/FileSpec.h b/lldb/include/lldb/Utility/FileSpec.h
index e4d3d12..08fd101 100644
--- a/lldb/include/lldb/Utility/FileSpec.h
+++ b/lldb/include/lldb/Utility/FileSpec.h
@@ -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;
diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp
index 7678124..96f1995 100644
--- a/lldb/unittests/Utility/FileSpecTest.cpp
+++ b/lldb/unittests/Utility/FileSpecTest.cpp
@@ -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());
+}