commit
ca04975d54
62 files changed
+3381
No files matched your search
@@ -0,0 +1,109 @@
|
||||
#include "TestSupport.hpp"
|
||||
|
||||
#include <Void/System/Process.hpp>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
// These are upstream integration requirements, deliberately ordinary failing
|
||||
// tests until a verified StrictJson revision implements the complete grammar.
|
||||
Void::Testing::Test decimal_and_exponent_json_values() {
|
||||
for (const auto number : {"0.0", "-0.5", "1.25", "1e3", "1E+3", "-2.5e-2", "0e0"}) {
|
||||
const auto parsed = vls::parse_json(std::string{"{\"ignored\":"} + number + "}");
|
||||
Void::Testing::expect(parsed.has_value());
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test decimal_initialization_options_and_unknown_fields() {
|
||||
for (const auto number : {"1.5", "-2.5e-2", "1E+3"}) {
|
||||
vls::Server server;
|
||||
const auto reply = test::response(
|
||||
server,
|
||||
std::string{
|
||||
R"({"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":null,"rootUri":null,"capabilities":{},"initializationOptions":{"scale":)"} +
|
||||
number + R"(},"extension":2.75e1}})");
|
||||
const auto *object = std::get_if<vls::Json::Object>(&reply.value);
|
||||
Void::Testing::require(object != nullptr);
|
||||
Void::Testing::expect(object->contains("result"));
|
||||
Void::Testing::expect(!object->contains("error"));
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test fractional_and_out_of_range_numeric_ids_are_invalid_requests() {
|
||||
for (const auto id : {"1.5", "1e-1", "2147483648.0", "-2147483649.0", "1e50"}) {
|
||||
vls::Server server;
|
||||
const auto reply = test::response(server, std::string{"{\"jsonrpc\":\"2.0\",\"id\":"} + id +
|
||||
R"(,"method":"initialize","params":{}})");
|
||||
Void::Testing::expect_eq(test::error_code(reply), std::int64_t{-32600});
|
||||
Void::Testing::expect(
|
||||
std::holds_alternative<std::nullptr_t>(test::field(reply, "id").value));
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test integer_valued_number_ids_preserve_value() {
|
||||
const std::pair<std::string_view, std::int64_t> cases[] = {{"1.0", 1},
|
||||
{"1e0", 1},
|
||||
{"-0.0", 0},
|
||||
{"2.147483647e9", 2147483647},
|
||||
{"-2.147483648e9", -2147483648}};
|
||||
for (const auto &[id, expected] : cases) {
|
||||
vls::Server server;
|
||||
const auto reply =
|
||||
test::response(server, std::string{"{\"jsonrpc\":\"2.0\",\"id\":"} + std::string{id} +
|
||||
R"(,"method":"initialize","params":{}})");
|
||||
const auto *object = std::get_if<vls::Json::Object>(&reply.value);
|
||||
Void::Testing::require(object != nullptr);
|
||||
Void::Testing::require(object->contains("result"));
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(test::field(reply, "id").value), expected);
|
||||
}
|
||||
}
|
||||
|
||||
Void::Testing::Test numeric_ids_through_executable() {
|
||||
using namespace std::chrono_literals;
|
||||
const auto input =
|
||||
test::frame(R"({"jsonrpc":"2.0","id":1e0,"method":"initialize","params":{}})") +
|
||||
test::frame(R"({"jsonrpc":"2.0","id":2.0,"method":"unknown"})") +
|
||||
test::frame(R"({"jsonrpc":"2.0","id":-2.147483648e9,"method":"unknown"})") +
|
||||
test::frame(R"({"jsonrpc":"2.0","id":1.5,"method":"unknown"})") +
|
||||
test::frame(R"({"jsonrpc":"2.0","id":2.147483647e9,"method":"shutdown"})") +
|
||||
test::frame(test::exit);
|
||||
const auto output = Void::Process::run(VLS_EXECUTABLE, {"--stdio"}, input, 2s);
|
||||
Void::Testing::require(output.has_value());
|
||||
Void::Testing::expect_eq(output->exit_code, 0);
|
||||
Void::Testing::expect(output->err.empty());
|
||||
const auto replies = test::responses(output->out);
|
||||
Void::Testing::require_eq(replies.size(), std::size_t{5});
|
||||
Void::Testing::require(std::get<vls::Json::Object>(replies[0].value).contains("result"));
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(test::field(replies[0], "id").value),
|
||||
std::int64_t{1});
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(test::field(replies[1], "id").value),
|
||||
std::int64_t{2});
|
||||
Void::Testing::expect_eq(test::error_code(replies[1]), std::int64_t{-32601});
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(test::field(replies[2], "id").value),
|
||||
std::int64_t{-2147483648});
|
||||
Void::Testing::expect_eq(test::error_code(replies[2]), std::int64_t{-32601});
|
||||
Void::Testing::expect_eq(test::error_code(replies[3]), std::int64_t{-32600});
|
||||
Void::Testing::expect(
|
||||
std::holds_alternative<std::nullptr_t>(test::field(replies[3], "id").value));
|
||||
Void::Testing::expect_eq(std::get<std::int64_t>(test::field(replies[4], "id").value),
|
||||
std::int64_t{2147483647});
|
||||
Void::Testing::expect(
|
||||
std::holds_alternative<std::nullptr_t>(test::field(replies[4], "result").value));
|
||||
}
|
||||
|
||||
Void::Testing::Test decimal_initialization_through_executable() {
|
||||
using namespace std::chrono_literals;
|
||||
const auto input =
|
||||
test::frame(
|
||||
R"({"jsonrpc":"2.0","id":1,"method":"initialize","params":{"capabilities":{},"initializationOptions":{"scale":1.5,"exponent":-2.5e-2},"unknown":1E+3}})") +
|
||||
test::frame(test::initialized) + test::frame(test::shutdown) + test::frame(test::exit);
|
||||
const auto output = Void::Process::run(VLS_EXECUTABLE, {"--stdio"}, input, 2s);
|
||||
Void::Testing::require(output.has_value());
|
||||
Void::Testing::expect_eq(output->exit_code, 0);
|
||||
Void::Testing::expect(output->err.empty());
|
||||
const auto replies = test::responses(output->out);
|
||||
Void::Testing::require_eq(replies.size(), std::size_t{2});
|
||||
const auto *object = std::get_if<vls::Json::Object>(&replies[0].value);
|
||||
Void::Testing::require(object != nullptr);
|
||||
Void::Testing::expect(object->contains("result"));
|
||||
Void::Testing::expect(!object->contains("error"));
|
||||
}
|
||||
Reference in new issue
Block a user