Started adding unit tests
This commit is contained in:
21
test/CMakeLists.txt
Normal file
21
test/CMakeLists.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
add_subdirectory("googletest")
|
||||
|
||||
mark_as_advanced(
|
||||
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
|
||||
gmock_build_tests gtest_build_samples gtest_build_tests
|
||||
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
|
||||
)
|
||||
|
||||
macro(package_add_test TESTNAME)
|
||||
add_executable(${TESTNAME} ${ARGN})
|
||||
target_link_libraries(${TESTNAME} gtest gmock gtest_main)
|
||||
gtest_discover_tests(${TESTNAME}
|
||||
WORKING_DIRECTORY ${PROJECT_DIR}
|
||||
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
|
||||
)
|
||||
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
|
||||
endmacro()
|
||||
|
||||
package_add_test(utility_test src/utility.cpp)
|
||||
package_add_test(parse_test src/parse.cpp)
|
||||
|
||||
1
test/googletest
Submodule
1
test/googletest
Submodule
Submodule test/googletest added at 3e0e32ba30
2
test/src/format.cpp
Normal file
2
test/src/format.cpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <format.h>
|
||||
#include <gtest/gtest.h>
|
||||
18
test/src/parse.cpp
Normal file
18
test/src/parse.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <parse.h>
|
||||
|
||||
TEST(Parse, ast_node) {
|
||||
ast_node_t ast_node1{'a'};
|
||||
ast_node_t ast_node2{'a'};
|
||||
ast_node_t ast_node3{'b'};
|
||||
|
||||
EXPECT_EQ(ast_node1 == ast_node2, true);
|
||||
EXPECT_EQ(ast_node1 == ast_node3, false);
|
||||
}
|
||||
|
||||
TEST(Parse, chars_only) {
|
||||
constexpr std::array<ast_node_t, 8> control = {'a', 'b', 'c', 'd',
|
||||
'e', 'f', 'g', 'h'};
|
||||
|
||||
EXPECT_EQ(detail::parse_string<"abcdefgh">().value, control);
|
||||
}
|
||||
9
test/src/utility.cpp
Normal file
9
test/src/utility.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <utility.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(Utility, const_pow) {
|
||||
EXPECT_EQ(detail::const_pow(10, 0), 1);
|
||||
EXPECT_EQ(detail::const_pow(0, 1), 0);
|
||||
EXPECT_EQ(detail::const_pow(2, 8), 0b1'0000'0000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user