From f62147f4ff3f043270fd37e51fbffdab301a791c Mon Sep 17 00:00:00 2001 From: tharun571 Date: Sun, 19 May 2024 17:41:27 +0530 Subject: [PATCH] Add tests for xparser and xinterpreter --- test/test_interpreter.cpp | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index 3d1e1bd2..eb88464b 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -56,6 +56,46 @@ TEST_SUITE("execute_request") } } +TEST_SUITE("inspect_request") +{ + TEST_CASE("good_status") + { + std::vector Args = {/*"-v", "resource-dir", "....."*/}; + xcpp::interpreter interpreter((int)Args.size(), Args.data()); + + std::string code = "std::vector"; + int cursor_pos = 11; + + nl::json result = interpreter.inspect_request( + code, + cursor_pos, + /*detail_level=*/0 + ); + + REQUIRE(result["user_expressions"] == nl::json::object()); + REQUIRE(result["found"] == true); + REQUIRE(result["status"] == "ok"); + } + + TEST_CASE("bad_status") + { + std::vector Args = {/*"-v", "resource-dir", "....."*/}; + xcpp::interpreter interpreter((int)Args.size(), Args.data()); + + std::string code = "nonExistentFunction"; + int cursor_pos = 19; + + nl::json result = interpreter.inspect_request( + code, + cursor_pos, + /*detail_level=*/0 + ); + + REQUIRE(result["found"] == false); + REQUIRE(result["status"] == "error"); + } +} + TEST_SUITE("extract_filename") { TEST_CASE("extract_filename_basic_test") @@ -98,6 +138,15 @@ TEST_SUITE("trim"){ REQUIRE(result == ""); } + /*Checks if it trims the string is empty*/ + TEST_CASE("trim_empty"){ + std::string argument = ""; + + std::string result = xcpp::trim(argument); + + REQUIRE(result == ""); + } + } TEST_SUITE("should_print_version")