Skip to content

Commit 96bb39f

Browse files
committed
Add tests for array_map w/ flags
Signed-off-by: Alecto Irene Perez <[email protected]>
1 parent dd294dc commit 96bb39f

File tree

2 files changed

+70
-13
lines changed

2 files changed

+70
-13
lines changed

CMakeLists.txt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,32 @@ if(PROJECT_IS_TOP_LEVEL)
8787
https://github.com/fmtlib/fmt.git
8888
master)
8989

90-
91-
# TODO: Write tests
92-
# find_or_fetch(
93-
# Catch2
94-
# https://github.com/catchorg/catch2.git
95-
# devel
96-
# 3.0.0)
90+
find_or_fetch(
91+
Catch2
92+
https://github.com/catchorg/catch2.git
93+
devel
94+
3.0.0)
9795

9896
FetchContent_MakeAvailable(${remote_dependencies})
9997

98+
add_executable(test_arglet
99+
test/test_arglet.cpp)
100+
target_link_libraries(test_arglet PRIVATE
101+
arglet::arglet
102+
fmt::fmt
103+
Catch2::Catch2WithMain)
100104
add_source_dir(
101105
examples # the name of the directory
102106
arglet::arglet # Libraries to link against
103107
fmt::fmt)
104108

105109
# Append places where Catch2 might be to the CMake Module path, so we can
106110
# use the function catch_discover_tests
107-
# TODO: Write tests
108-
# list(APPEND CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/lib/cmake/Catch2)
109-
# list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
110-
# include(CTest)
111-
# include(Catch)
112-
# catch_discover_tests(...)
111+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_INSTALL_PREFIX}/lib/cmake/Catch2)
112+
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
113+
include(CTest)
114+
include(Catch)
115+
catch_discover_tests(test_arglet)
113116
endif()
114117

115118

test/test_arglet.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <arglet/flags.hpp>
2+
#include <catch2/catch_test_macros.hpp>
3+
#include <catch2/generators/catch_generators.hpp>
4+
5+
TEST_CASE("Check that we can create flag maps") {
6+
using namespace arglet::flags;
7+
using tuplet::tuple;
8+
using std::string_view_literals::operator""sv;
9+
10+
auto tup = tuple {
11+
flag_arg<1, 1> {'d', "--dragon_fruit"},
12+
flag_arg<1, 1> {'v', "--version"},
13+
flag_arg<1, 1> {'e', "--eggplant"},
14+
flag_arg<1, 1> {'b', "--banana"},
15+
flag_arg<1, 1> {'c', "--cantelope"},
16+
flag_arg<1, 1> {'h', "--help"},
17+
flag_arg<0, 1> {{}, "--fondue"},
18+
flag_arg<1, 1> {'a', "--apple"},
19+
flag_arg<0, 1> {{}, "--glacier"},
20+
flag_arg<1, 0> {'g', {}},
21+
};
22+
23+
auto short_args = make_short_flag_map(tup);
24+
auto long_args = make_long_flag_map(tup);
25+
26+
REQUIRE(
27+
short_args.get_keys()
28+
== std::array {'a', 'b', 'c', 'd', 'e', 'g', 'h', 'v'});
29+
30+
REQUIRE(
31+
long_args.get_keys()
32+
== std::array {
33+
"--apple"sv,
34+
"--banana"sv,
35+
"--cantelope"sv,
36+
"--dragon_fruit"sv,
37+
"--eggplant"sv,
38+
"--fondue"sv,
39+
"--glacier"sv,
40+
"--help"sv,
41+
"--version"sv});
42+
43+
SECTION("Check that the search function works") {
44+
for (char ch = 'a'; ch <= 'z'; ch++) {
45+
auto idx = short_args.search(ch);
46+
47+
if (idx > 0) {
48+
REQUIRE(ch >= short_args[idx].key);
49+
} else {
50+
REQUIRE(ch < short_args[1].key);
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)