Added simple testing capabilities
This commit is contained in:
7
Makefile
7
Makefile
@@ -30,8 +30,13 @@ $(OBJS): dir
|
|||||||
@$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ -c $*.c
|
@$(CC) $(CFLAGS) -o $(BUILD_DIR)/$@ -c $*.c
|
||||||
|
|
||||||
# Runs CUnit tests
|
# Runs CUnit tests
|
||||||
|
# test: dir
|
||||||
|
# @$(CC) $(CFLAGS) -lcunit -o $(BIN_DIR)/$(NAME)_test $(TESTS_DIR)/*.c
|
||||||
|
# @$(BIN_DIR)/$(NAME)_test
|
||||||
|
|
||||||
|
# Runs tests
|
||||||
test: dir
|
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
|
@$(BIN_DIR)/$(NAME)_test
|
||||||
|
|
||||||
# Run valgrind memory checker on executable
|
# Run valgrind memory checker on executable
|
||||||
|
|||||||
35
src/main.c
35
src/main.c
@@ -5,41 +5,8 @@
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// C-style to string
|
string a = StrLit("Hello, world!");
|
||||||
string a;
|
|
||||||
a.chars = "Manual transformation of C-style to String";
|
|
||||||
a.length = strlen(a.chars);
|
|
||||||
PrintStr(a);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
45
tests/main.c
Normal file
45
tests/main.c
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include "../include/lenstr.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user