gargoyle/test/twine.c

73 lines
2.8 KiB
C

#include <CUnit/Basic.h>
#include <gargoyle/test/twine.h>
#include <gargoyle/twine.h>
int init_suite_twine(void) {
return CUE_SUCCESS;
}
int clean_suite_twine(void) {
return CUE_SUCCESS;
}
void twine_test_is_sep(void) {
CU_ASSERT_TRUE(gargoyle_is_sep('-'));
CU_ASSERT_TRUE(gargoyle_is_sep('_'));
CU_ASSERT_FALSE(gargoyle_is_sep('*'));
CU_ASSERT_FALSE(gargoyle_is_sep('u'));
}
void twine_test_is_eql(void) {
CU_ASSERT_TRUE(gargoyle_is_eql('U', 'u'));
CU_ASSERT_TRUE(gargoyle_is_eql('p', 'p'));
CU_ASSERT_FALSE(gargoyle_is_eql('l', 't'));
CU_ASSERT_TRUE(gargoyle_is_eql('i', 'i'));
CU_ASSERT_TRUE(gargoyle_is_eql('M', 'M'));
CU_ASSERT_TRUE(gargoyle_is_eql('e', 'e'));
CU_ASSERT_FALSE(gargoyle_is_eql('g', 'R'));
CU_ASSERT_FALSE(gargoyle_is_eql('F', 'h'));
}
void twine_test_cmp(void) {
CU_ASSERT_TRUE(gargoyle_cmp("", "", 0, 0));
CU_ASSERT_TRUE(gargoyle_cmp("", "", 0, GARGOYLE_FLG_FLXBL));
CU_ASSERT_TRUE(gargoyle_cmp("", "", 100, 0));
CU_ASSERT_TRUE(gargoyle_cmp("", "", 100, GARGOYLE_FLG_FLXBL));
CU_ASSERT_FALSE(gargoyle_cmp("", "w", 1, 0));
CU_ASSERT_FALSE(gargoyle_cmp("w", "", 1, 0));
CU_ASSERT_TRUE(gargoyle_cmp("spooky", "spooky", 42, 0));
CU_ASSERT_FALSE(gargoyle_cmp("thunderfury", "blessed blade of the windseeker", 11, 0));
CU_ASSERT_FALSE(gargoyle_cmp("thunderfury", "blessed blade of the windseeker", 31, 0));
CU_ASSERT_FALSE(gargoyle_cmp("blessed blade of the windseeker", "thunderfury", 11, 0));
CU_ASSERT_FALSE(gargoyle_cmp("blessed blade of the windseeker", "thunderfury", 31, 0));
CU_ASSERT_TRUE(gargoyle_cmp("abcdEFGH", "ABCDefgh", 8, GARGOYLE_FLG_FLXBL));
CU_ASSERT_TRUE(gargoyle_cmp("ABCDefgh", "abcdEFGH", 8, GARGOYLE_FLG_FLXBL));
CU_ASSERT_TRUE(gargoyle_cmp("hyper-speed", "HYPER_SPEED", 11, GARGOYLE_FLG_FLXBL));
CU_ASSERT_TRUE(gargoyle_cmp("HYPER_SPEED", "hyper-speed", 11, GARGOYLE_FLG_FLXBL));
CU_ASSERT_FALSE(gargoyle_cmp("-", "_", 1, 0));
CU_ASSERT_TRUE(gargoyle_cmp("-", "_", 1, GARGOYLE_FLG_FLXBL));
CU_ASSERT_FALSE(gargoyle_cmp("_", "-", 1, 0));
CU_ASSERT_TRUE(gargoyle_cmp("_", "-", 1, GARGOYLE_FLG_FLXBL));
}
void twine_test_cpy(void) {
char smol_str[10];
gargoyle_cpy(smol_str, "", sizeof(smol_str), GARGOYLE_FLG_FILL0);
CU_ASSERT_NSTRING_EQUAL(smol_str, "\0\0\0\0\0\0\0\0\0\0", 10);
gargoyle_cpy(smol_str, "waldo", 5, 0);
CU_ASSERT_STRING_EQUAL(smol_str, "waldo");
gargoyle_cpy(smol_str, "hi", 3, GARGOYLE_FLG_FILL0);
CU_ASSERT_STRING_EQUAL(smol_str, "hi");
CU_ASSERT_NSTRING_EQUAL(smol_str, "hi\0do\0\0\0\0\0", 10);
gargoyle_cpy(smol_str, "lol", 3, 0);
CU_ASSERT_STRING_EQUAL(smol_str, "loldo");
CU_ASSERT_NSTRING_EQUAL(smol_str, "loldo\0\0\0\0\0", 10);
gargoyle_cpy(smol_str + 5, "spooky", 5, GARGOYLE_FLG_FILL0);
CU_ASSERT_STRING_EQUAL(smol_str, "loldospoo");
CU_ASSERT_NSTRING_EQUAL(smol_str, "loldospoo\0", 10);
}