Skip to content

Commit ed4b3cf

Browse files
committed
Adding unit tests for CapabilitiesEventBody serialization logic.
1 parent ec01a3e commit ed4b3cf

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

lldb/tools/lldb-dap/Protocol/ProtocolTypes.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,36 +249,39 @@ llvm::json::Value toJSON(const AdapterFeature &);
249249
/// Information about the capabilities of a debug adapter.
250250
struct Capabilities {
251251
/// The supported features for this adapter.
252-
llvm::DenseSet<AdapterFeature> supportedFeatures;
252+
llvm::DenseSet<AdapterFeature> supportedFeatures{};
253253

254254
/// Available exception filter options for the `setExceptionBreakpoints`
255255
/// request.
256256
std::optional<std::vector<ExceptionBreakpointsFilter>>
257-
exceptionBreakpointFilters;
257+
exceptionBreakpointFilters{};
258258

259259
/// The set of characters that should trigger completion in a REPL. If not
260260
/// specified, the UI should assume the `.` character.
261-
std::optional<std::vector<std::string>> completionTriggerCharacters;
261+
std::optional<std::vector<std::string>> completionTriggerCharacters =
262+
std::nullopt;
262263

263264
/// The set of additional module information exposed by the debug adapter.
264-
std::optional<std::vector<ColumnDescriptor>> additionalModuleColumns;
265+
std::optional<std::vector<ColumnDescriptor>> additionalModuleColumns =
266+
std::nullopt;
265267

266268
/// Checksum algorithms supported by the debug adapter.
267-
std::optional<std::vector<ChecksumAlgorithm>> supportedChecksumAlgorithms;
269+
std::optional<std::vector<ChecksumAlgorithm>> supportedChecksumAlgorithms =
270+
std::nullopt;
268271

269272
/// Modes of breakpoints supported by the debug adapter, such as 'hardware' or
270273
/// 'software'. If present, the client may allow the user to select a mode and
271274
/// include it in its `setBreakpoints` request.
272275
///
273276
/// Clients may present the first applicable mode in this array as the
274277
/// 'default' mode in gestures that set breakpoints.
275-
std::optional<std::vector<BreakpointMode>> breakpointModes;
278+
std::optional<std::vector<BreakpointMode>> breakpointModes = std::nullopt;
276279

277280
/// lldb-dap Extensions
278281
/// @{
279282

280283
/// The version of the adapter.
281-
std::optional<std::string> lldbExtVersion;
284+
std::optional<std::string> lldbExtVersion = std::nullopt;
282285

283286
/// @}
284287
};

lldb/unittests/DAP/ProtocolTypesTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Protocol/ProtocolTypes.h"
10+
#include "Protocol/ProtocolEvents.h"
1011
#include "Protocol/ProtocolRequests.h"
1112
#include "llvm/ADT/StringRef.h"
1213
#include "llvm/Support/JSON.h"
1314
#include "llvm/Testing/Support/Error.h"
1415
#include "gmock/gmock.h"
1516
#include "gtest/gtest.h"
17+
#include <optional>
1618

1719
using namespace llvm;
1820
using namespace lldb;
@@ -666,3 +668,18 @@ TEST(ProtocolTypesTest, ThreadResponseBody) {
666668
// Validate toJSON
667669
EXPECT_EQ(json, pp(body));
668670
}
671+
672+
TEST(ProtocolTypesTest, CapabilitiesEventBody) {
673+
const CapabilitiesEventBody body{Capabilities{/*supportedFeatures=*/{
674+
eAdapterFeatureANSIStyling,
675+
eAdapterFeatureBreakpointLocationsRequest,
676+
}}};
677+
const StringRef json = R"({
678+
"capabilities": {
679+
"supportsANSIStyling": true,
680+
"supportsBreakpointLocationsRequest": true
681+
}
682+
})";
683+
// Validate toJSON
684+
EXPECT_EQ(json, pp(body));
685+
}

0 commit comments

Comments
 (0)