void Env_free_r(Env *e) { if (e == NULL || *e == NULL) return; Env_free_r(&(*e)->rest); Env_free(e); *e = NULL; }
char * all_tests() { mu_suite_start(); mu_run_test(test_init); mu_run_test(test_global); mu_run_test(test_local); Env_free(global); return NULL; }
char * test_local() { Env * local_scope = Env_new(global); Symbol * local_sym1, * local_sym2; local_sym1 = (Symbol *) malloc(sizeof(Symbol)); local_sym2 = (Symbol *) malloc(sizeof(Symbol)); local_sym1->type = 3; local_sym2->type = 4; Env_put(local_scope, strdup("baz"), local_sym1); // new id name Env_put(local_scope, strdup("foo"), local_sym2); // already in global mu_assert(Env_get(local_scope, "baz")->type == 3, "Wrong type"); mu_assert(Env_get(local_scope, "foo")->type == 4, "Wrong type"); // test inheritance mu_assert(Env_get(local_scope, "bar") != NULL, "Cannot find global symbol"); mu_assert(Env_get(local_scope, "bar")->type == 2, "Wrong type"); Env_free(local_scope); return NULL; }