Skip to content

Commit 2dbe8da

Browse files
authored
Add test cases for xparser (#47)
1 parent f33ae90 commit 2dbe8da

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/xparser.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
#ifndef XEUS_CPP_PARSER_HPP
1111
#define XEUS_CPP_PARSER_HPP
1212

13+
#include "xeus-cpp/xeus_cpp_config.hpp"
14+
1315
#include <string>
1416

1517
namespace xcpp
16-
{
18+
{
19+
XEUS_CPP_API
1720
std::string trim(const std::string& str);
1821
}
1922
#endif

test/test_interpreter.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "xeus-cpp/xmanager.hpp"
1313
#include "xeus-cpp/xutils.hpp"
1414

15+
#include "../src/xparser.hpp"
16+
1517
TEST_SUITE("execute_request")
1618
{
1719
TEST_CASE("fetch_documentation")
@@ -50,6 +52,37 @@ TEST_SUITE("extract_filename")
5052
}
5153
}
5254

55+
TEST_SUITE("trim"){
56+
57+
TEST_CASE("trim_basic_test"){
58+
std::string argument = "argument";
59+
60+
std::string result = xcpp::trim(argument);
61+
62+
REQUIRE(result == "argument");
63+
}
64+
65+
/*Checks if it trims the string which
66+
has an empty space at the start and in the end*/
67+
TEST_CASE("trim_start_and_end"){
68+
std::string argument = " argument ";
69+
70+
std::string result = xcpp::trim(argument);
71+
72+
REQUIRE(result == "argument");
73+
}
74+
75+
/*Checks if it trims the string which has no characters*/
76+
TEST_CASE("trim_empty"){
77+
std::string argument = " ";
78+
79+
std::string result = xcpp::trim(argument);
80+
81+
REQUIRE(result == "");
82+
}
83+
84+
}
85+
5386
TEST_SUITE("should_print_version")
5487
{
5588
// This test case checks if the function `should_print_version` correctly identifies

0 commit comments

Comments
 (0)