commit
ca04975d54
62 files changed
+3381
No files matched your search
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <vls/Framing.hpp>
|
||||
#include <vls/Json.hpp>
|
||||
#include <vls/Server.hpp>
|
||||
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace test {
|
||||
|
||||
inline std::string frame(std::string_view text) {
|
||||
std::ostringstream output;
|
||||
Void::Testing::require(vls::write_frame(output, text).has_value());
|
||||
return output.str();
|
||||
}
|
||||
|
||||
inline std::vector<vls::Json> responses(std::string_view wire) {
|
||||
std::istringstream input{std::string{wire}};
|
||||
std::vector<vls::Json> result;
|
||||
for (;;) {
|
||||
const auto next = vls::read_frame(input);
|
||||
Void::Testing::require(next.has_value());
|
||||
if (!*next)
|
||||
return result;
|
||||
auto json = vls::parse_json(**next);
|
||||
Void::Testing::require(json.has_value());
|
||||
result.push_back(std::move(*json));
|
||||
}
|
||||
}
|
||||
|
||||
inline const vls::Json &field(const vls::Json &json, std::string_view key) {
|
||||
const auto *object = std::get_if<vls::Json::Object>(&json.value);
|
||||
Void::Testing::require(object != nullptr);
|
||||
const auto found = object->find(key);
|
||||
Void::Testing::require(found != object->end());
|
||||
return found->second;
|
||||
}
|
||||
|
||||
inline vls::Json response(vls::Server &server, std::string_view request) {
|
||||
const auto result = server.handle(request);
|
||||
Void::Testing::require(result.response.has_value());
|
||||
auto parsed = vls::parse_json(*result.response);
|
||||
Void::Testing::require(parsed.has_value());
|
||||
Void::Testing::expect(!result.exit_code.has_value());
|
||||
return std::move(*parsed);
|
||||
}
|
||||
|
||||
inline std::int64_t error_code(const vls::Json &response) {
|
||||
return std::get<std::int64_t>(field(field(response, "error"), "code").value);
|
||||
}
|
||||
|
||||
inline void expect_error(vls::Server &server, std::string_view request, std::int64_t code) {
|
||||
Void::Testing::expect_eq(error_code(response(server, request)), code);
|
||||
}
|
||||
|
||||
inline void initialize(vls::Server &server) {
|
||||
const auto result =
|
||||
response(server, R"({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}})");
|
||||
Void::Testing::expect(
|
||||
std::get<vls::Json::Object>(field(field(result, "result"), "capabilities").value).empty());
|
||||
}
|
||||
|
||||
inline constexpr std::string_view initialize_request =
|
||||
R"({"jsonrpc":"2.0","id":"init","method":"initialize","params":{"processId":null,"clientInfo":{"name":"test client","version":"1"},"locale":"en","rootUri":"file:///tmp/workspace","capabilities":{"general":{"positionEncodings":["utf-16"]}},"workspaceFolders":null,"initializationOptions":{"ignored":true},"unknownExtension":{}}})";
|
||||
inline constexpr std::string_view initialized =
|
||||
R"({"jsonrpc":"2.0","method":"initialized","params":{}})";
|
||||
inline constexpr std::string_view shutdown = R"({"jsonrpc":"2.0","id":2,"method":"shutdown"})";
|
||||
inline constexpr std::string_view exit = R"({"jsonrpc":"2.0","method":"exit"})";
|
||||
|
||||
} // namespace test
|
||||
Reference in new issue
Block a user