Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/xinspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
45 changes: 45 additions & 0 deletions test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,43 @@ TEST_SUITE("execute_request")
REQUIRE(result["status"] == "ok");
}

TEST_CASE("fetch_documentation_of_member_or_parameter")
{
std::vector<const char*> 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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we require internet connection for this test to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

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<nl::json> promise;
std::future<nl::json> 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<const char*> Args = {"resource-dir"};
Expand Down Expand Up @@ -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<bool, std::smatch> result = xcpp::is_inspect_request(code, re_expression);
REQUIRE(result.first == false);
}

}

#if !defined(XEUS_CPP_EMSCRIPTEN_WASM_BUILD)
Expand Down
Loading