aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/bytecode.amal9
-rw-r--r--tests/errors/extern_closure_one_return_value.amal1
-rw-r--r--tests/errors/too_long_var_name.amal1
-rw-r--r--tests/main.c22
4 files changed, 30 insertions, 3 deletions
diff --git a/tests/bytecode.amal b/tests/bytecode.amal
index dd9bd3d..096f921 100644
--- a/tests/bytecode.amal
+++ b/tests/bytecode.amal
@@ -1,4 +1,5 @@
-extern const printf: fn;
+extern const print_extern: fn;
+extern const print_extern_num: fn(num: i32);
const main = fn {
var value = 23;
@@ -6,9 +7,8 @@ const main = fn {
const value2: i64 = 23;
const value3 = 2 + 5 - 1 * 10 / 2;
const str_value = "hello, world";
- //printf();
print();
- const result = print_num(value3);
+ const result = print_num(1337);
}
const print = fn {
@@ -16,5 +16,8 @@ const print = fn {
}
const print_num = fn(num: i32) i32 {
+ print_extern();
+ print_extern_num(num);
+ print_extern_num(8080);
return num;
} \ No newline at end of file
diff --git a/tests/errors/extern_closure_one_return_value.amal b/tests/errors/extern_closure_one_return_value.amal
new file mode 100644
index 0000000..982897f
--- /dev/null
+++ b/tests/errors/extern_closure_one_return_value.amal
@@ -0,0 +1 @@
+extern const func: fn() i32, i32; \ No newline at end of file
diff --git a/tests/errors/too_long_var_name.amal b/tests/errors/too_long_var_name.amal
new file mode 100644
index 0000000..eff8ff1
--- /dev/null
+++ b/tests/errors/too_long_var_name.amal
@@ -0,0 +1 @@
+extern const veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylongname: fn; \ No newline at end of file
diff --git a/tests/main.c b/tests/main.c
index 3336c46..05725f7 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -131,6 +131,16 @@ static CHECK_RESULT int get_thread_count_env_var(int *thread_count) {
return 0;
}
+static int print_extern() {
+ printf("hello from amalgam extern func, print_extern!\n");
+ return 0;
+}
+
+static int print_extern_num(i64 num) {
+ printf("hello from amalgam extern func, print_extern_num, value: %ld!\n", num);
+ return 0;
+}
+
static void test_load(const char *filepath) {
amal_compiler_options options;
amal_program program;
@@ -146,6 +156,16 @@ static void test_load(const char *filepath) {
fprintf(stderr, "Failed to initialize amal program\n");
FAIL_TEST(full_path);
}
+
+ if(amal_program_add_extern_func(&program, create_buffer_view("print_extern", 12), print_extern, 0) != 0) {
+ fprintf(stderr, "Unexpected error (alloc failure)\n");
+ FAIL_TEST(full_path);
+ }
+ if(amal_program_add_extern_func(&program, create_buffer_view("print_extern_num", 16), print_extern_num, sizeof(i64)) != 0) {
+ fprintf(stderr, "Unexpected error (alloc failure)\n");
+ FAIL_TEST(full_path);
+ }
+
result = amal_compiler_load_file(&options, &program, filepath);
if(result != AMAL_COMPILER_OK) {
fprintf(stderr, "Failed to load file %s, result: %d\n", full_path, result);
@@ -252,6 +272,8 @@ static void run_all_tests() {
" ^\n");
test_load_error("tests/errors/no_main_func.amal", NULL);
test_load_error("tests/errors/closure_duplicate_param_name.amal", "TODO: Add expected error here");
+ test_load_error("tests/errors/extern_closure_one_return_value.amal", "TODO: Add expected error here");
+ test_load_error("tests/errors/too_long_var_name.amal", "TODO: Add expected error here");
}
/* TODO: Restrict variables in global scope to const */