aboutsummaryrefslogtreecommitdiffstats
path: root/unit
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-11-10 22:47:03 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-11-10 22:47:03 +0200
commit2638802ccd0d0776ebf1867181d4e3950a147074 (patch)
treecc535cc46c41d5dd347a7630f316cf1c84d00045 /unit
parent6d77eb748a6b15b9f473ab86371bfa474898cef1 (diff)
downloadck-2638802ccd0d0776ebf1867181d4e3950a147074.tar.gz
ck-2638802ccd0d0776ebf1867181d4e3950a147074.tar.bz2
ck-2638802ccd0d0776ebf1867181d4e3950a147074.zip
Home dir
Diffstat (limited to 'unit')
-rw-r--r--unit/ck-test.c52
1 files changed, 37 insertions, 15 deletions
diff --git a/unit/ck-test.c b/unit/ck-test.c
index 1264431..8d8ee08 100644
--- a/unit/ck-test.c
+++ b/unit/ck-test.c
@@ -3,38 +3,60 @@
#include <string.h>
#include "cklist.h"
+#include "ckutil.h"
/* total number of unit tests */
#define TOTAL 2
-#define CK_UNIT_TESTS \
- X(ck_list_init, "Basic cklist test") \
- X(ck_list_exists, "Test list exists function")
+#define CK_UNIT_TESTS \
+ X(ck_list_test, "Basic cklist test") \
+ X(ck_str_utils_test, "Test string utility functions") \
-void ck_list_init() {
- cklist *ckl1 = list_make_new();
+void ck_list_test() {
+ /* init and add */
+ cklist *ckl = list_make_new();
cklist *ckl2 = list_make_and_add("first");
list_add(ckl2, "second");
- list_add(ckl1, "first");
- list_add(ckl1, "second");
- assert(strcmp(list_get_at(ckl1, 0),
+ list_add(ckl, "first");
+ list_add(ckl, "second");
+ assert(strcmp(list_get_at(ckl, 0),
list_get_at(ckl2, 0)) == 0);
- assert(strcmp(list_get_at(ckl1, 1),
+ assert(strcmp(list_get_at(ckl, 1),
list_get_at(ckl2, 1)) == 0);
- list_free(ckl1);
list_free(ckl2);
-}
-void ck_list_exists() {
- cklist *ckl = list_make_new();
- list_add(ckl, "first");
- list_add(ckl, "second");
+ /* exists */
assert(list_exists(ckl, "first"));
assert(list_exists(ckl, "second"));
assert(!list_exists(ckl, "thrid"));
list_free(ckl);
}
+void ck_str_utils_test() {
+ /* make_ck_config_name */
+ char ck_conf_path[STR_M];
+ str_make_ck_config_name(ck_conf_path, "/test/path/.config", "emacs");
+ assert(strcmp(ck_conf_path, "emacs/.config") == 0);
+
+ /* str_is_empty */
+ assert(str_is_empty(""));
+ assert(str_is_empty(" "));
+ assert(str_is_empty("\t"));
+
+ /* swap ~ and home */
+ char str[STR_M] = "";
+ char str2[STR_M] = "";
+ /* getenv("HOME") -> /home/user */
+ char home[STR_S] = "/home/user";
+ char testpath[STR_S] = "/home/user/file";
+ assert(swap_home_with_tilde(str, testpath, home) == 0);
+ assert(strcmp(str, "~/file") == 0);
+ assert(swap_tilde_with_home(str2, str, home) == 0);
+ assert(strcmp(str2, testpath) == 0);
+ assert(swap_home_with_tilde(str, "/not/starting/with/home", home));
+ assert(swap_tilde_with_home(str2, "/not/starting/with/tilde", home));
+}
+
int main() {
int count = 1;
#define X(TEST, DESC) \