From 7fd7b2c33f8e1e3a36bf78fb15e9c03258a424af Mon Sep 17 00:00:00 2001 From: tharun571 Date: Tue, 28 May 2024 18:12:15 +0530 Subject: [PATCH] Add test for xinterpreter --- test/test_interpreter.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index 19424838..2d479939 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -645,4 +645,32 @@ TEST_SUITE("xutils_handler"){ } } } -#endif \ No newline at end of file +#endif + +TEST_SUITE("complete_request") +{ + TEST_CASE("completion_test") + { + std::vector Args = {/*"-v", "resource-dir", "....."*/}; + xcpp::interpreter interpreter((int)Args.size(), Args.data()); + + nl::json execute = interpreter.execute_request("#include ", false, false, nl::json::object(), false); + + REQUIRE(execute["status"] == "ok"); + + std::string code = "st"; + int cursor_pos = 2; + nl::json result = interpreter.complete_request(code, cursor_pos); + + REQUIRE(result["cursor_start"] == 0); + REQUIRE(result["cursor_end"] == 2); + REQUIRE(result["status"] == "ok"); + size_t found = 0; + for (auto& r : result["matches"]) { + if (r == "static" || r == "struct") { + found++; + } + } + REQUIRE(found == 2); + } +} \ No newline at end of file