[Lldb-commits] [lldb] 5b97a5b - [lldb-dap] Add unit tests for GetString and GetBoolean
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Sun May 11 16:20:36 PDT 2025
Author: Jonas Devlieghere
Date: 2025-05-11T16:20:30-07:00
New Revision: 5b97a5b2ae6368a9c1ad220d3b1d94c545578bed
URL: https://github.com/llvm/llvm-project/commit/5b97a5b2ae6368a9c1ad220d3b1d94c545578bed
DIFF: https://github.com/llvm/llvm-project/commit/5b97a5b2ae6368a9c1ad220d3b1d94c545578bed.diff
LOG: [lldb-dap] Add unit tests for GetString and GetBoolean
These are simple functions but they're used a lot. Add some simple unit
tests for them.
Added:
Modified:
lldb/unittests/DAP/JSONUtilsTest.cpp
Removed:
################################################################################
diff --git a/lldb/unittests/DAP/JSONUtilsTest.cpp b/lldb/unittests/DAP/JSONUtilsTest.cpp
index 0cf42a1c08870..2dbd1de899ece 100644
--- a/lldb/unittests/DAP/JSONUtilsTest.cpp
+++ b/lldb/unittests/DAP/JSONUtilsTest.cpp
@@ -16,9 +16,72 @@ using namespace lldb;
using namespace lldb_dap;
TEST(JSONUtilsTest, GetAsString) {
- StringRef str = "foo";
- json::Value value("foo");
- EXPECT_EQ(str, GetAsString(value));
+ json::Value string_value("foo");
+ EXPECT_EQ(GetAsString(string_value), "foo");
+
+ json::Value int_value(42);
+ EXPECT_EQ(GetAsString(int_value), "");
+
+ json::Value null_value(nullptr);
+ EXPECT_EQ(GetAsString(null_value), "");
+}
+
+TEST(JSONUtilsTest, GetString_Ref) {
+ json::Object obj;
+ obj.try_emplace("key", "value");
+
+ auto result = GetString(obj, "key");
+ ASSERT_TRUE(result.has_value());
+ EXPECT_EQ(result.value(), "value");
+
+ result = GetString(obj, "nonexistent_key");
+ EXPECT_FALSE(result.has_value());
+}
+
+TEST(JSONUtilsTest, GetString_Pointer) {
+ json::Object obj;
+ obj.try_emplace("key", "value");
+
+ auto result = GetString(&obj, "key");
+ ASSERT_TRUE(result.has_value());
+ EXPECT_EQ(result.value(), "value");
+
+ result = GetString(nullptr, "key");
+ EXPECT_FALSE(result.has_value());
+}
+
+TEST(JSONUtilsTest, GetBoolean_Ref) {
+ json::Object obj;
+ obj.try_emplace("key_true", true);
+ obj.try_emplace("key_false", false);
+ obj.try_emplace("key_int", 1);
+
+ auto result = GetBoolean(obj, "key_true");
+ ASSERT_TRUE(result.has_value());
+ EXPECT_TRUE(result.value());
+
+ result = GetBoolean(obj, "key_false");
+ ASSERT_TRUE(result.has_value());
+ EXPECT_FALSE(result.value());
+
+ result = GetBoolean(obj, "key_int");
+ ASSERT_TRUE(result.has_value());
+ EXPECT_TRUE(result.value());
+
+ result = GetBoolean(obj, "nonexistent_key");
+ EXPECT_FALSE(result.has_value());
+}
+
+TEST(JSONUtilsTest, GetBoolean_Pointer) {
+ json::Object obj;
+ obj.try_emplace("key", true);
+
+ auto result = GetBoolean(&obj, "key");
+ ASSERT_TRUE(result.has_value());
+ EXPECT_TRUE(result.value());
+
+ result = GetBoolean(nullptr, "key");
+ EXPECT_FALSE(result.has_value());
}
TEST(JSONUtilsTest, CreateModule) {
More information about the lldb-commits
mailing list