1 //===- Protocol.cpp - LSP JSON protocol unit tests ------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Tools/lsp-server-support/Protocol.h"
11 #include "gtest/gtest.h"
14 using namespace mlir::lsp
;
15 using namespace testing
;
19 TEST(ProtocolTest
, DiagnosticTagPresent
) {
20 Diagnostic diagnostic
;
21 diagnostic
.tags
.push_back(DiagnosticTag::Unnecessary
);
23 llvm::json::Value json
= toJSON(diagnostic
);
24 const llvm::json::Object
*o
= json
.getAsObject();
25 const llvm::json::Array
*v
= o
->get("tags")->getAsArray();
26 EXPECT_EQ(*v
, llvm::json::Array
{1});
29 llvm::json::Path::Root root
= llvm::json::Path::Root();
30 bool success
= fromJSON(json
, parsed
, llvm::json::Path(root
));
32 ASSERT_EQ(parsed
.tags
.size(), (size_t)1);
33 EXPECT_EQ(parsed
.tags
.at(0), DiagnosticTag::Unnecessary
);
36 TEST(ProtocolTest
, DiagnosticTagNotPresent
) {
37 Diagnostic diagnostic
;
39 llvm::json::Value json
= toJSON(diagnostic
);
40 const llvm::json::Object
*o
= json
.getAsObject();
41 const llvm::json::Value
*v
= o
->get("tags");
42 EXPECT_EQ(v
, nullptr);
45 llvm::json::Path::Root root
= llvm::json::Path::Root();
46 bool success
= fromJSON(json
, parsed
, llvm::json::Path(root
));
48 EXPECT_TRUE(parsed
.tags
.empty());