symbol.test.c (933B)
1 #include "symbol.h" 2 #include <stdlib.h> 3 #include <stdbool.h> 4 #include <assert.h> 5 #include <string.h> 6 7 bool 8 test_repr_of_intern_is_iso() 9 { 10 char *test = "abc"; 11 return strcmp(repr(intern(test)), test) == 0; 12 } 13 14 bool 15 test_intern_of_repr_is_id() 16 { 17 char *test = "abc"; 18 symbol s = intern(test); 19 return intern(repr(s)) == s; 20 } 21 22 void 23 test_intern_a_lot_of_strings() 24 { 25 char str[5]; 26 for (size_t i = 0; i < 1000; i++) { 27 for (size_t c = 0; c < 5; c++) { 28 str[c] = 'a' + ((i + c) % 26); 29 } 30 (void)intern(str); 31 } 32 } 33 34 void 35 test_intern_many_frames(size_t depth) 36 { 37 if (depth == 0) return; 38 char str[5]; 39 for (size_t i = 0; i < 5; i++) str[i] = random(); 40 symbol s = intern(str); 41 test_intern_many_frames(depth - 1); 42 assert(intern(str) == s); 43 assert(strcmp(repr(s), str) == 0); 44 } 45 46 int 47 main() { 48 assert(test_repr_of_intern_is_iso()); 49 assert(test_intern_of_repr_is_id()); 50 test_intern_a_lot_of_strings(); 51 test_intern_many_frames(1000); 52 }