safethrow() and Maybe struct
This commit is contained in:
@@ -6,6 +6,7 @@ void test_all(){
|
||||
test_hashtable();
|
||||
test_string();
|
||||
test_dtsod();
|
||||
test_safethrow();
|
||||
printf("\e[96m---------------------------------------\e[0m\n");
|
||||
}
|
||||
|
||||
|
||||
43
tests/test_safethrow.c
Normal file
43
tests/test_safethrow.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "tests.h"
|
||||
|
||||
Maybe dont_throw(){
|
||||
return SUCCESS(Uni(UInt64, 9/2));
|
||||
}
|
||||
|
||||
Maybe throw_error(){
|
||||
safethrow("test exception");
|
||||
}
|
||||
|
||||
Maybe throw_errcode(){
|
||||
safethrow(ERR_NULLPTR);
|
||||
}
|
||||
|
||||
Maybe test_maybe(){
|
||||
printf("\e[94mdont_throw returns \e[92m");
|
||||
throwNext(dont_throw(),rez0)
|
||||
printMaybe(rez0);
|
||||
printf("\n");
|
||||
throwNext(throw_error(),rez1)
|
||||
printMaybe(rez1);
|
||||
throw("test_maybe failed");
|
||||
return MaybeNull;
|
||||
}
|
||||
|
||||
|
||||
Maybe c(){ throwNext(throw_errcode(),_) return MaybeNull; }
|
||||
Maybe b(){ throwNext(c(),_) return MaybeNull; }
|
||||
Maybe a(){ throwNext(b(),_) return MaybeNull; }
|
||||
|
||||
void test_safethrow(){
|
||||
printf("\e[96m-----------[test_safethrow]-----------\n");
|
||||
optime("test_safethrow", 1, ({
|
||||
Maybe e=test_maybe();
|
||||
printf("\e[94mthrow_error:\n\e[92m");
|
||||
printMaybe(e);
|
||||
Maybe_free(e);
|
||||
printf("\e[94mthrow_errcode:\n\e[92m");
|
||||
e=a();
|
||||
printMaybe(e);
|
||||
Maybe_free(e);
|
||||
}));
|
||||
}
|
||||
@@ -6,10 +6,10 @@ void test_string(){
|
||||
printf("\e[96m-------------[test_string]-------------\n");
|
||||
char c[]="0123456789abcdef";
|
||||
string s=string_cpFromCharPtr(c);
|
||||
printf("\e[92m\"%s\" -> string_cpFromCharPtr()\n",c);
|
||||
printf("\e[92m\"%s\" \e[94m-> string_cpFromCharPtr()\n",c);
|
||||
if(s.length!=16) throw("string created with incorrect length");
|
||||
char* p=string_cpToCptr(s);
|
||||
printf("\e[92mstring_cpToCptr() -> \"%s\"\n",p);
|
||||
printf("\e[94mstring_cpToCptr() -> \e[92m\"%s\"\n",p);
|
||||
free(p);
|
||||
free(s.ptr);
|
||||
}));
|
||||
|
||||
@@ -8,4 +8,5 @@ void test_searchtree();
|
||||
void test_autoarr();
|
||||
void test_hashtable();
|
||||
void test_string();
|
||||
void test_dtsod();
|
||||
void test_dtsod();
|
||||
void test_safethrow();
|
||||
Reference in New Issue
Block a user