Skip to content

Commit 5337d4c

Browse files
author
kr-2003
committed
added tests for xinspect
1 parent 48767d6 commit 5337d4c

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/xinspect.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace xcpp
132132
if (std::regex_search(to_inspect, method, std::regex(R"((.*)\.(\w*)$)")))
133133
{
134134
std::string type_name = find_type_slow(method[1]);
135+
type_name = (type_name.empty()) ? method[1] : type_name;
135136

136137
if (!type_name.empty())
137138
{

test/test_interpreter.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,43 @@ TEST_SUITE("execute_request")
134134
REQUIRE(result["status"] == "ok");
135135
}
136136

137+
TEST_CASE("fetch_documentation_of_member_or_parameter")
138+
{
139+
std::vector<const char*> Args = {/*"-v", "resource-dir", "....."*/};
140+
xcpp::interpreter interpreter((int)Args.size(), Args.data());
141+
142+
std::string code = "?std::vector.push_back";
143+
std::string inspect_result = "https://en.cppreference.com/w/cpp/container/vector/push_back";
144+
nl::json user_expressions = nl::json::object();
145+
xeus::execute_request_config config;
146+
config.silent = false;
147+
config.store_history = false;
148+
config.allow_stdin = false;
149+
nl::json header = nl::json::object();
150+
xeus::xrequest_context::guid_list id = {};
151+
xeus::xrequest_context context(header, id);
152+
153+
std::promise<nl::json> promise;
154+
std::future<nl::json> future = promise.get_future();
155+
auto callback = [&promise](nl::json result) {
156+
promise.set_value(result);
157+
};
158+
159+
interpreter.execute_request(
160+
std::move(context),
161+
std::move(callback),
162+
code,
163+
std::move(config),
164+
user_expressions
165+
);
166+
nl::json result = future.get();
167+
REQUIRE(result["payload"][0]["data"]["text/plain"] == inspect_result);
168+
REQUIRE(result["user_expressions"] == nl::json::object());
169+
REQUIRE(result["found"] == true);
170+
REQUIRE(result["status"] == "ok");
171+
}
172+
173+
137174
TEST_CASE("bad_status")
138175
{
139176
std::vector<const char*> Args = {"resource-dir"};
@@ -840,6 +877,27 @@ TEST_SUITE("xinspect"){
840877
cmp.child_value = "nonexistentMethod";
841878
REQUIRE(cmp(node) == false);
842879
}
880+
881+
TEST_CASE("find_type_slow"){
882+
std::string expression = "int";
883+
std::string result = xcpp::find_type_slow(expression);
884+
std::cout << result << std::endl;
885+
bool res = (result == "<unnamed>" || result == "");
886+
REQUIRE(res);
887+
888+
expression = "std::vector<int>";
889+
result = xcpp::find_type_slow(expression);
890+
std::cout << result << std::endl;
891+
REQUIRE(result == "<unnamed>");
892+
}
893+
894+
TEST_CASE("is_inspect_request"){
895+
std::string code = "vector";
896+
std::regex re_expression(R"(non_matching_pattern)");
897+
std::pair<bool, std::smatch> result = xcpp::is_inspect_request(code, re_expression);
898+
REQUIRE(result.first == false);
899+
}
900+
843901
}
844902

845903
TEST_SUITE("xassist"){

0 commit comments

Comments
 (0)