User Guide
string_utils.cpp
Go to the documentation of this file.
1 #include <catch2/catch_test_macros.hpp>
2 #include <catch2/matchers/catch_matchers_string.hpp>
3 
4 #include "utils/string_utils.hpp"
5 
6 using namespace nmodl;
7 
8 TEST_CASE("ends_with") {
9  SECTION("empty substring") {
10  REQUIRE(stringutils::ends_with("abcde", ""));
11  }
12 
13  SECTION("empty str") {
14  REQUIRE(!stringutils::ends_with("", "abc"));
15  }
16 
17  SECTION("both empty") {
18  REQUIRE(stringutils::ends_with("", ""));
19  }
20  SECTION("match") {
21  REQUIRE(stringutils::ends_with("abcde", "de"));
22  }
23 
24  SECTION("mismatch") {
25  REQUIRE(!stringutils::ends_with("abcde", "d"));
26  }
27 
28  SECTION("oversized") {
29  REQUIRE(!stringutils::ends_with("abcde", "--abcde"));
30  }
31 }
32 
33 TEST_CASE("starts_with") {
34  SECTION("empty substring") {
35  REQUIRE(stringutils::starts_with("abcde", ""));
36  }
37 
38  SECTION("empty str") {
39  REQUIRE(!stringutils::starts_with("", "abc"));
40  }
41 
42  SECTION("both empty") {
43  REQUIRE(stringutils::starts_with("", ""));
44  }
45  SECTION("match") {
46  REQUIRE(stringutils::starts_with("abcde", "ab"));
47  }
48 
49  SECTION("mismatch") {
50  REQUIRE(!stringutils::starts_with("abcde", "b"));
51  }
52 
53  SECTION("oversized") {
54  REQUIRE(!stringutils::starts_with("abcde", "abcde++"));
55  }
56 }
57 
58 TEST_CASE("join_arguments") {
59  SECTION("both empty") {
60  REQUIRE(stringutils::join_arguments("", "") == "");
61  }
62 
63  SECTION("lhs emtpy") {
64  REQUIRE(stringutils::join_arguments("", "foo, bar") == "foo, bar");
65  }
66 
67  SECTION("rhs empty") {
68  REQUIRE(stringutils::join_arguments("foo", "") == "foo");
69  }
70 
71  SECTION("neither empty") {
72  REQUIRE(stringutils::join_arguments("foo", "bar") == "foo, bar");
73  }
74 }
nmodl::stringutils::starts_with
static bool starts_with(const std::string &haystack, const std::string &needle)
Check if haystack starts with needle.
Definition: string_utils.hpp:154
nmodl::stringutils::join_arguments
std::string join_arguments(const std::string &lhs, const std::string &rhs)
Joint two (list of) arguments.
Definition: string_utils.cpp:30
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
string_utils.hpp
Implement string manipulation functions.
TEST_CASE
TEST_CASE("ends_with")
Definition: string_utils.cpp:8
nmodl::stringutils::ends_with
static bool ends_with(const std::string &haystack, const std::string &needle)
Check if haystack ends with needle.
Definition: string_utils.hpp:135