diff --git a/libs/cstring/test/cstring.cpp b/libs/cstring/test/cstring.cpp new file mode 100644 index 00000000..e3d82194 --- /dev/null +++ b/libs/cstring/test/cstring.cpp @@ -0,0 +1,48 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP +#define SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP +# define TESTSPR_CPP_INCLUDE +#endif + +#include "./memcmp.cpp" +#include "./strcmp.cpp" +#include "./strcoll.cpp" +#include "./strncmp.cpp" +#include "./memchr.cpp" +#include "./strchr.cpp" +#include "./strcspn.cpp" +#include "./strpbrk.cpp" +#include "./strrchr.cpp" +#include "./strspn.cpp" +#include "./strstr.cpp" +#include "./strlen.cpp" + +#ifdef TESTSPR_CPP_INCLUDE_DISABLE_SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP +# undef TESTSPR_CPP_INCLUDE +#endif + +namespace testspr { + static void cstring_test() { + testspr::cstring_memcmp_test(); + testspr::cstring_strcmp_test(); + testspr::cstring_strcoll_test(); + testspr::cstring_strncmp_test(); + testspr::cstring_memchr_test(); + testspr::cstring_strchr_test(); + testspr::cstring_strcspn_test(); + testspr::cstring_strpbrk_test(); + testspr::cstring_strrchr_test(); + testspr::cstring_strspn_test(); + testspr::cstring_strstr_test(); + testspr::cstring_strlen_test(); + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_CSTRING_CPP diff --git a/libs/cstring/test/memchr.cpp b/libs/cstring/test/memchr.cpp new file mode 100644 index 00000000..0eca7887 --- /dev/null +++ b/libs/cstring/test/memchr.cpp @@ -0,0 +1,28 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_MEMCHR_CPP +#define SPROUT_LIBS_CSTRING_TEST_MEMCHR_CPP + +#include +#include +#include + +namespace testspr { + static void cstring_memchr_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR unsigned char buf[] = "abcdef\0ghij"; + SPROUT_STATIC_CONSTEXPR unsigned char b = 'h'; + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::memchr(buf, b, 12); + TESTSPR_BOTH_ASSERT(sprout::distance(buf, reinterpret_cast(found)) == 8); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_memchr_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_MEMCHR_CPP diff --git a/libs/cstring/test/memcmp.cpp b/libs/cstring/test/memcmp.cpp new file mode 100644 index 00000000..aa0c5f9d --- /dev/null +++ b/libs/cstring/test/memcmp.cpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_MEMCMP_CPP +#define SPROUT_LIBS_CSTRING_TEST_MEMCMP_CPP + +#include +#include + +namespace testspr { + static void cstring_memcmp_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR unsigned char buf[] = "\0abc\0de"; + SPROUT_STATIC_CONSTEXPR unsigned char buf2[] = "\0abc\0de"; + SPROUT_STATIC_CONSTEXPR unsigned char buf3[] = "\0abcdef"; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::memcmp(buf, buf2, 7); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::memcmp(buf, buf3, 7); + TESTSPR_BOTH_ASSERT(result < 0); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_memcmp_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_MEMCMP_CPP diff --git a/libs/cstring/test/strchr.cpp b/libs/cstring/test/strchr.cpp new file mode 100644 index 00000000..fb6e583f --- /dev/null +++ b/libs/cstring/test/strchr.cpp @@ -0,0 +1,28 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRCHR_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRCHR_CPP + +#include +#include +#include + +namespace testspr { + static void cstring_strchr_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "abcdefghijklmnabcdefghijklmn"; + SPROUT_STATIC_CONSTEXPR char c = 'd'; + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strchr(str, c); + TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 3); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strchr_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCHR_CPP diff --git a/libs/cstring/test/strcmp.cpp b/libs/cstring/test/strcmp.cpp new file mode 100644 index 00000000..a10d6305 --- /dev/null +++ b/libs/cstring/test/strcmp.cpp @@ -0,0 +1,42 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRCMP_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRCMP_CPP + +#include +#include + +namespace testspr { + static void cstring_strcmp_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "ABC"; + SPROUT_STATIC_CONSTEXPR char str1[] = "ABC"; + SPROUT_STATIC_CONSTEXPR char str2[] = "ABD"; + SPROUT_STATIC_CONSTEXPR char str3[] = "B"; + SPROUT_STATIC_CONSTEXPR char str4[] = "AAAA"; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str1); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str2); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str3); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcmp(str, str4); + TESTSPR_BOTH_ASSERT(result > 0); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strcmp_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCMP_CPP diff --git a/libs/cstring/test/strcoll.cpp b/libs/cstring/test/strcoll.cpp new file mode 100644 index 00000000..5ecb3507 --- /dev/null +++ b/libs/cstring/test/strcoll.cpp @@ -0,0 +1,42 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRCOLL_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRCOLL_CPP + +#include +#include + +namespace testspr { + static void cstring_strcoll_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "ABC"; + SPROUT_STATIC_CONSTEXPR char str1[] = "ABC"; + SPROUT_STATIC_CONSTEXPR char str2[] = "ABD"; + SPROUT_STATIC_CONSTEXPR char str3[] = "B"; + SPROUT_STATIC_CONSTEXPR char str4[] = "AAAA"; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str1); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str2); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str3); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcoll(str, str4); + TESTSPR_BOTH_ASSERT(result > 0); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strcoll_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCOLL_CPP diff --git a/libs/cstring/test/strcspn.cpp b/libs/cstring/test/strcspn.cpp new file mode 100644 index 00000000..efe96ebd --- /dev/null +++ b/libs/cstring/test/strcspn.cpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRCSPN_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRCSPN_CPP + +#include +#include + +namespace testspr { + static void cstring_strcspn_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "abcdefgabcdefghij"; + SPROUT_STATIC_CONSTEXPR char str1[] = "hj"; + SPROUT_STATIC_CONSTEXPR char str2[] = "ghj"; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcspn(str, str1); + TESTSPR_BOTH_ASSERT(result == 14); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strcspn(str, str2); + TESTSPR_BOTH_ASSERT(result == 6); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strcspn_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRCSPN_CPP diff --git a/libs/cstring/test/strlen.cpp b/libs/cstring/test/strlen.cpp new file mode 100644 index 00000000..6b774805 --- /dev/null +++ b/libs/cstring/test/strlen.cpp @@ -0,0 +1,31 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRLEN_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRLEN_CPP + +#include +#include + +namespace testspr { + static void cstring_strlen_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str1[] = "today"; + SPROUT_STATIC_CONSTEXPR char str2[] = "hello world"; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strlen(str1); + TESTSPR_BOTH_ASSERT(result == 5); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strlen(str2); + TESTSPR_BOTH_ASSERT(result == 11); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strlen_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRLEN_CPP diff --git a/libs/cstring/test/strncmp.cpp b/libs/cstring/test/strncmp.cpp new file mode 100644 index 00000000..e8e343d1 --- /dev/null +++ b/libs/cstring/test/strncmp.cpp @@ -0,0 +1,57 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRNCMP_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRNCMP_CPP + +#include +#include + +namespace testspr { + static void cstring_strncmp_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "ABC"; + SPROUT_STATIC_CONSTEXPR char str1[] = "ABD"; + SPROUT_STATIC_CONSTEXPR char str2[] = "ABC"; + SPROUT_STATIC_CONSTEXPR char str3[] = "AAA"; + SPROUT_STATIC_CONSTEXPR char str4[] = "ABCD"; + SPROUT_STATIC_CONSTEXPR char str5[] = "AB"; + SPROUT_STATIC_CONSTEXPR char str6[] = "B"; + SPROUT_STATIC_CONSTEXPR char str7[] = "A"; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str1, 2); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str2, 2); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str3, 2); + TESTSPR_BOTH_ASSERT(result > 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str4, 2); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str5, 2); + TESTSPR_BOTH_ASSERT(result == 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str6, 2); + TESTSPR_BOTH_ASSERT(result < 0); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strncmp(str, str7, 2); + TESTSPR_BOTH_ASSERT(result > 0); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strncmp_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRNCMP_CPP diff --git a/libs/cstring/test/strpbrk.cpp b/libs/cstring/test/strpbrk.cpp new file mode 100644 index 00000000..e0b33cb6 --- /dev/null +++ b/libs/cstring/test/strpbrk.cpp @@ -0,0 +1,33 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRPBRK_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRPBRK_CPP + +#include +#include +#include + +namespace testspr { + static void cstring_strpbrk_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "abcdefgabcdefghij"; + SPROUT_STATIC_CONSTEXPR char str1[] = "ghsp"; + SPROUT_STATIC_CONSTEXPR char str2[] = "sp"; + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strpbrk(str, str1); + TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 6); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strpbrk(str, str2); + TESTSPR_BOTH_ASSERT(!found); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strpbrk_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRPBRK_CPP diff --git a/libs/cstring/test/strrchr.cpp b/libs/cstring/test/strrchr.cpp new file mode 100644 index 00000000..97dbcdbf --- /dev/null +++ b/libs/cstring/test/strrchr.cpp @@ -0,0 +1,28 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRRCHR_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRRCHR_CPP + +#include +#include +#include + +namespace testspr { + static void cstring_strrchr_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "abcdefghijklmnabcdefghijklmn"; + SPROUT_STATIC_CONSTEXPR char c = 'd'; + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strrchr(str, c); + TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 17); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strrchr_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRRCHR_CPP diff --git a/libs/cstring/test/strspn.cpp b/libs/cstring/test/strspn.cpp new file mode 100644 index 00000000..97587f10 --- /dev/null +++ b/libs/cstring/test/strspn.cpp @@ -0,0 +1,32 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRSPN_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRSPN_CPP + +#include +#include + +namespace testspr { + static void cstring_strspn_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "abcdefgabcdefghij"; + SPROUT_STATIC_CONSTEXPR char str1[] = "abcfg"; + SPROUT_STATIC_CONSTEXPR char str2[] = "gfedcba"; + + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strspn(str, str1); + TESTSPR_BOTH_ASSERT(result == 3); + } + { + SPROUT_STATIC_CONSTEXPR auto result = sprout::strspn(str, str2); + TESTSPR_BOTH_ASSERT(result == 14); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strspn_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRSPN_CPP diff --git a/libs/cstring/test/strstr.cpp b/libs/cstring/test/strstr.cpp new file mode 100644 index 00000000..28dbb40b --- /dev/null +++ b/libs/cstring/test/strstr.cpp @@ -0,0 +1,43 @@ +#ifndef SPROUT_LIBS_CSTRING_TEST_STRSTR_CPP +#define SPROUT_LIBS_CSTRING_TEST_STRSTR_CPP + +#include +#include +#include + +namespace testspr { + static void cstring_strstr_test() { + using namespace sprout; + { + SPROUT_STATIC_CONSTEXPR char str[] = "abcdefghijklmn"; + SPROUT_STATIC_CONSTEXPR char str1[] = "defgh"; + SPROUT_STATIC_CONSTEXPR char str2[] = "xyz"; + SPROUT_STATIC_CONSTEXPR char str3[] = "abcdefghijklmnopqr"; + SPROUT_STATIC_CONSTEXPR char str4[] = ""; + + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str1); + TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 3); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str2); + TESTSPR_BOTH_ASSERT(!found); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str3); + TESTSPR_BOTH_ASSERT(!found); + } + { + SPROUT_STATIC_CONSTEXPR auto found = sprout::strstr(str, str4); + TESTSPR_BOTH_ASSERT(sprout::distance(str, found) == 0); + } + } + } +} // namespace testspr + +#ifndef TESTSPR_CPP_INCLUDE +# define TESTSPR_TEST_FUNCTION testspr::cstring_strstr_test +# include +#endif + +#endif // #ifndef SPROUT_LIBS_CSTRING_TEST_STRSTR_CPP diff --git a/testspr/sprout.cpp b/testspr/sprout.cpp index 1e4d839a..4caf18a2 100644 --- a/testspr/sprout.cpp +++ b/testspr/sprout.cpp @@ -14,6 +14,7 @@ #include "../libs/variant/test/variant.cpp" #include "../libs/algorithm/test/algorithm.cpp" #include "../libs/random/test/random.cpp" +#include "../libs/cstring/test/cstring.cpp" #ifdef TESTSPR_CPP_INCLUDE_DISABLE_TESTSPR_SPROUT_HPP # undef TESTSPR_CPP_INCLUDE @@ -29,6 +30,7 @@ namespace testspr { testspr::variant_test(); testspr::algorithm_test(); testspr::random_test(); + testspr::cstring_test(); } } // namespace testspr