From a7a275905306721b09136adc5da56f586095da6e Mon Sep 17 00:00:00 2001 From: kilroy <> Date: Fri, 28 Nov 2025 19:38:18 -0500 Subject: [PATCH] Added simple testing capabilities --- Makefile | 7 ++++++- src/main.c | 35 +---------------------------------- tests/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 35 deletions(-) create mode 100644 tests/main.c diff --git a/Makefile b/Makefile index 1cbd60c..ff6633d 100644 --- a/Makefile +++ b/Makefile @@ -30,8 +30,13 @@ $(OBJS): dir @$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ -c $*.c # Runs CUnit tests +# test: dir +# @$(CC) $(CFLAGS) -lcunit -o $(BIN_DIR)/$(NAME)_test $(TESTS_DIR)/*.c +# @$(BIN_DIR)/$(NAME)_test + +# Runs tests test: dir - @$(CC) $(CFLAGS) -lcunit -o $(BIN_DIR)/$(NAME)_test $(TESTS_DIR)/*.c + @$(CC) $(CFLAGS) -o $(BIN_DIR)/$(NAME)_test $(TESTS_DIR)/*.c @$(BIN_DIR)/$(NAME)_test # Run valgrind memory checker on executable diff --git a/src/main.c b/src/main.c index 35c671e..4f8b275 100644 --- a/src/main.c +++ b/src/main.c @@ -5,41 +5,8 @@ int main(void) { - // C-style to string - string a; - a.chars = "Manual transformation of C-style to String"; - a.length = strlen(a.chars); + string a = StrLit("Hello, world!"); PrintStr(a); - // Automatic c-style to string - string b = CStyleToLengthString_Assign("Function transformation of C-style to String"); - PrintStr(b); - - // String assigning (shallow copy) and copying (deep copy) - char xx[] = "String Assign Copy"; - char yy[] = "String Deep Copy"; - string x = CStyleToLengthString_Assign(xx); - string y = CStyleToLengthString_Assign(yy); - string c = x; - PrintStr(c); - string d = StringCopy(y); - PrintStr(d); - x.chars[3] = '!'; - y.chars[3] = '!'; - PrintStr(c); - PrintStr(d); - - // Manual string slicing - string e; - e.chars = &a.chars[7]; - e.length = 14; - PrintStr(e); - - // Automatic string slicing (by length or by index range) - string f = StringSlice_Length(a, 7, 14); - string g = StringSlice_Index(a, 7, 21); - PrintStr(f); - PrintStr(g); - return 0; } diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..35c671e --- /dev/null +++ b/tests/main.c @@ -0,0 +1,45 @@ +#include "../include/lenstr.h" +#include +#include +#include + +int main(void) +{ + // C-style to string + string a; + a.chars = "Manual transformation of C-style to String"; + a.length = strlen(a.chars); + PrintStr(a); + + // Automatic c-style to string + string b = CStyleToLengthString_Assign("Function transformation of C-style to String"); + PrintStr(b); + + // String assigning (shallow copy) and copying (deep copy) + char xx[] = "String Assign Copy"; + char yy[] = "String Deep Copy"; + string x = CStyleToLengthString_Assign(xx); + string y = CStyleToLengthString_Assign(yy); + string c = x; + PrintStr(c); + string d = StringCopy(y); + PrintStr(d); + x.chars[3] = '!'; + y.chars[3] = '!'; + PrintStr(c); + PrintStr(d); + + // Manual string slicing + string e; + e.chars = &a.chars[7]; + e.length = 14; + PrintStr(e); + + // Automatic string slicing (by length or by index range) + string f = StringSlice_Length(a, 7, 14); + string g = StringSlice_Index(a, 7, 21); + PrintStr(f); + PrintStr(g); + + return 0; +}