~qpfiffer/lair

a2a338c77bf61f44bd0cac6a210a802a815a9790 — Quinlan Pfiffer 3 months ago fb7a38d
More useful tests

* Tweak No such function error to include bad function name
4 files changed, 11 insertions(+), 7 deletions(-)

M src/eval.c
M src/unit_test.c
M t/equality.den
M t/string_range.den
M src/eval.c => src/eval.c +4 -2
@@ 263,7 263,7 @@ static const struct _lair_type *_lair_call_runtime_function(struct _lair_runtime

static const struct _lair_type *_lair_call_function(struct _lair_runtime *r, const struct _lair_ast *ast_node, struct _lair_env *env) {
	if (!_is_callable(ast_node)) {
		char buf[128] = {0};
		char buf[512] = {0};
		snprintf(buf, sizeof(buf), "Cannot call a non-function: %s", _friendly_enum(ast_node->atom.type));
		check(r, _is_callable(ast_node), ERR_RUNTIME, buf);
	}


@@ 303,7 303,9 @@ static const struct _lair_type *_lair_call_function(struct _lair_runtime *r, con
		cur_env = (struct _lair_env *)cur_env->parent;
	}

	throw_exception(r, ERR_RUNTIME, "No such function.");
	char buf[512] = {0};
	snprintf(buf, sizeof(buf), "No such function: %s", func_name);
	throw_exception(r, ERR_RUNTIME, buf);
	return NULL;
}


M src/unit_test.c => src/unit_test.c +5 -0
@@ 51,6 51,10 @@ int test_equality() {
	return _run_program("t/equality.den");
}

int test_equality_disparate() {
	return _expect_failure("t/equality_disparate.den");
}

int test_functions_all_the_way_down() {
	return _run_program("t/functions_all_the_way_down.den");
}


@@ 113,6 117,7 @@ int main(int argc, char *argv[]) {
	run_test(test_assignment_no_function);
	run_test(test_basic);
	run_test(test_equality);
	run_test(test_equality_disparate);
	run_test(test_functions_all_the_way_down);
	run_test(test_id_function);
	run_test(test_loop);

M t/equality.den => t/equality.den +0 -2
@@ 15,5 15,3 @@ println ! isEqual 4 3
println ! complexBranching 1 1
println ! complexBranching 2 1
println ! complexBranching 2 2
println ! brokenNoTrue 4 4
println ! isEqual 4 "a"

M t/string_range.den => t/string_range.den +2 -3
@@ 1,3 1,2 @@
! println ! "This is a test string".1

! println ! "This is a test string".1..10
println "This is a test string".1
println "This is a test string".1..10