diff --git a/src/xinspect.cpp b/src/xinspect.cpp index 1cd54c36..2511a5ac 100644 --- a/src/xinspect.cpp +++ b/src/xinspect.cpp @@ -132,6 +132,7 @@ namespace xcpp if (std::regex_search(to_inspect, method, std::regex(R"((.*)\.(\w*)$)"))) { std::string type_name = find_type_slow(method[1]); + type_name = (type_name.empty()) ? method[1] : type_name; if (!type_name.empty()) { diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index fd18eb35..435cd839 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -134,6 +134,43 @@ TEST_SUITE("execute_request") REQUIRE(result["status"] == "ok"); } + TEST_CASE("fetch_documentation_of_member_or_parameter") + { + std::vector Args = {/*"-v", "resource-dir", "....."*/}; + xcpp::interpreter interpreter((int)Args.size(), Args.data()); + + std::string code = "?std::vector.push_back"; + std::string inspect_result = "https://en.cppreference.com/w/cpp/container/vector/push_back"; + nl::json user_expressions = nl::json::object(); + xeus::execute_request_config config; + config.silent = false; + config.store_history = false; + config.allow_stdin = false; + nl::json header = nl::json::object(); + xeus::xrequest_context::guid_list id = {}; + xeus::xrequest_context context(header, id); + + std::promise promise; + std::future future = promise.get_future(); + auto callback = [&promise](nl::json result) { + promise.set_value(result); + }; + + interpreter.execute_request( + std::move(context), + std::move(callback), + code, + std::move(config), + user_expressions + ); + nl::json result = future.get(); + REQUIRE(result["payload"][0]["data"]["text/plain"] == inspect_result); + REQUIRE(result["user_expressions"] == nl::json::object()); + REQUIRE(result["found"] == true); + REQUIRE(result["status"] == "ok"); + } + + TEST_CASE("bad_status") { std::vector Args = {"resource-dir"}; @@ -852,6 +889,14 @@ TEST_SUITE("xinspect"){ cmp.child_value = "nonexistentMethod"; REQUIRE(cmp(node) == false); } + + TEST_CASE("is_inspect_request"){ + std::string code = "vector"; + std::regex re_expression(R"(non_matching_pattern)"); + std::pair result = xcpp::is_inspect_request(code, re_expression); + REQUIRE(result.first == false); + } + } #if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)