================
@@ -0,0 +1,268 @@
+//===-- ProtocolTypesTest.cpp -----------------------------------*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Protocol/ProtocolTypes.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace lldb;
+using namespace lldb_dap;
+using namespace lldb_dap::protocol;
+
+TEST(ProtocolTypesTest, ExceptionBreakpointsFilter) {
+  ExceptionBreakpointsFilter filter;
+  filter.filter = "testFilter";
+  filter.label = "Test Filter";
+  filter.description = "This is a test filter";
+  filter.defaultState = true;
+  filter.supportsCondition = true;
+  filter.conditionDescription = "Condition for test filter";
+
+  llvm::json::Value value = toJSON(filter);
+  const json::Object *obj = value.getAsObject();
+  ASSERT_NE(obj, nullptr);
+
+  EXPECT_EQ(obj->getString("filter"), "testFilter");
+  EXPECT_EQ(obj->getString("label"), "Test Filter");
+  EXPECT_EQ(obj->getString("description"), "This is a test filter");
+  EXPECT_EQ(obj->getBoolean("default"), true);
+  EXPECT_EQ(obj->getBoolean("supportsCondition"), true);
+  EXPECT_EQ(obj->getString("conditionDescription"),
+            "Condition for test filter");
----------------
ashgti wrote:

Should we make a helper for matching these with a string literal? Something 
like:

```
MATCHER_P(equalToDAP, msg,
          "Protocol Message " + llvm::to_string(msg)) {
  if (toJSON(arg) != json::parse(msg)) {
    *result_listener << llvm::formatv("expected:\n{0:2}\ngot\n{1:2}",
                                      toJSON(msg), toJSON(arg))
                            .str();
    return false;
  }
  return true;
}
```

And then use:
```
EXPECT_THAT(filter, equalToDAP(R"json({"filter": "testFilter",...})json"));
```

I think that might help improve the brevity of these tests and help account for 
some additional fields or defaults that may appear in some structs.


We might be able to make the test case into a `vector<pair<protocol::Message, 
string>>` to make it easier to add cases as well.

https://github.com/llvm/llvm-project/pull/139502
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to