aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-07-31 01:25:05 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit1f28c3c733ea3ae4234bff91e1c55e61b1ee3e96 (patch)
tree0ab52e362da03fde741ce8159ef8a4110cd1fb6a /tests
parentec1a48e7b86fcd00127dd5a88d56c42083af1d78 (diff)
Starting on asm, implementing extern function call so progress is visible
Diffstat (limited to 'tests')
-rw-r--r--tests/bytecode.amal12
-rw-r--r--tests/errors/arithmetic_incompatible_types.amal5
-rw-r--r--tests/errors/declaration_no_type.amal1
-rw-r--r--tests/errors/declaration_no_type_extern.amal1
-rw-r--r--tests/errors/empty_body_regular_func.amal1
-rw-r--r--tests/errors/non_arithmetic_type_arithmetic.amal4
-rw-r--r--tests/main.c84
7 files changed, 76 insertions, 32 deletions
diff --git a/tests/bytecode.amal b/tests/bytecode.amal
index c5b2cb3..3484b21 100644
--- a/tests/bytecode.amal
+++ b/tests/bytecode.amal
@@ -1,12 +1,14 @@
extern const printf: fn;
-const print = fn {
-
-}
-
const main = fn {
var value = 23;
value = 34;
+ const value2: i64 = 23;
+ const value3 = 2 + 5 - 1 * 10 / 2;
const str_value = "hello, world";
- print();
+ printf();
+}
+
+const print = fn {
+
} \ No newline at end of file
diff --git a/tests/errors/arithmetic_incompatible_types.amal b/tests/errors/arithmetic_incompatible_types.amal
new file mode 100644
index 0000000..367e5ed
--- /dev/null
+++ b/tests/errors/arithmetic_incompatible_types.amal
@@ -0,0 +1,5 @@
+const main = fn {
+ const value = 23;
+ const value2 = "sadsa";
+ const value3 = value + value2;
+} \ No newline at end of file
diff --git a/tests/errors/declaration_no_type.amal b/tests/errors/declaration_no_type.amal
new file mode 100644
index 0000000..fc7d4f3
--- /dev/null
+++ b/tests/errors/declaration_no_type.amal
@@ -0,0 +1 @@
+const a; \ No newline at end of file
diff --git a/tests/errors/declaration_no_type_extern.amal b/tests/errors/declaration_no_type_extern.amal
new file mode 100644
index 0000000..1d5c677
--- /dev/null
+++ b/tests/errors/declaration_no_type_extern.amal
@@ -0,0 +1 @@
+extern const a; \ No newline at end of file
diff --git a/tests/errors/empty_body_regular_func.amal b/tests/errors/empty_body_regular_func.amal
new file mode 100644
index 0000000..afc3363
--- /dev/null
+++ b/tests/errors/empty_body_regular_func.amal
@@ -0,0 +1 @@
+const func: fn; \ No newline at end of file
diff --git a/tests/errors/non_arithmetic_type_arithmetic.amal b/tests/errors/non_arithmetic_type_arithmetic.amal
new file mode 100644
index 0000000..6635d06
--- /dev/null
+++ b/tests/errors/non_arithmetic_type_arithmetic.amal
@@ -0,0 +1,4 @@
+const main = fn {
+ const value = "hello, world";
+ const value2 = value + value;
+} \ No newline at end of file
diff --git a/tests/main.c b/tests/main.c
index 1394860..5b8bad0 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -20,14 +20,14 @@ static int num_tests_run = 0;
}while(0)
static CHECK_RESULT int test_hash_map() {
- ScopedAllocator scoped_allocator;
+ ArenaAllocator arena_allocator;
HashMap hash_map;
int value;
bool has_key;
unsigned char i;
- return_if_error(scoped_allocator_init(&scoped_allocator));
- cleanup_if_error(hash_map_init(&hash_map, &scoped_allocator, sizeof(int), hash_map_compare_string, amal_hash_string));
+ return_if_error(arena_allocator_init(&arena_allocator));
+ cleanup_if_error(hash_map_init(&hash_map, &arena_allocator, sizeof(int), hash_map_compare_string, amal_hash_string));
value = 34;
return_if_error(hash_map_insert(&hash_map, create_buffer_view("hello", 5), &value));
@@ -43,7 +43,7 @@ static CHECK_RESULT int test_hash_map() {
REQUIRE_EQ_INT(34, value);
cleanup:
- scoped_allocator_deinit(&scoped_allocator);
+ arena_allocator_deinit(&arena_allocator);
return 0;
}
@@ -200,6 +200,55 @@ static void test_load_error(const char *filepath, const char *expected_error) {
free(expected_data.expected_error);
}
+static void run_all_tests() {
+ test_load("tests/main.amal");
+ test_load("tests/utf8bom.amal");
+ test_load("tests/bytecode.amal");
+
+ test_load_error("tests/errors/duplicate_declaration.amal",
+ "2:7: error: Variable with the name main was declared twice in the same scope\n"
+ "const main = fn {}\n"
+ " ^\n");
+ test_load_error("tests/errors/pub_in_closure.amal",
+ "2:5: error: Only declarations in global structs can be public\n"
+ " pub const num = 45;\n"
+ " ^\n");
+ test_load_error("tests/errors/closure_no_lhs.amal",
+ "1:1: error: Expected string, variable, closure, struct, function call or import\n"
+ "fn {}\n"
+ "^\n");
+ test_load_error("tests/errors/const_assign.amal",
+ "3:5: error: Can't assign to a const value\n"
+ " value = 34;\n"
+ " ^\n");
+ test_load_error("tests/errors/arithmetic_incompatible_types.amal",
+ "4:28: error: Can't cast type \"str\" to type \"i64\"\n"
+ " const value3 = value + value2;\n"
+ " ^\n"
+ "4:20: error: Left-hand side is of type i64\n"
+ " const value3 = value + value2;\n"
+ " ^\n"
+ "4:28: error: Right-hand side is of type str\n"
+ " const value3 = value + value2;\n"
+ " ^\n");
+ test_load_error("tests/errors/non_arithmetic_type_arithmetic.amal",
+ "3:20: error: Arithmetic operation can only be performed with the types i8, u8, i16, u16, i32, u32, i64, u64, isize and usize\n"
+ " const value2 = value + value;\n"
+ " ^\n");
+ test_load_error("tests/errors/empty_body_regular_func.amal",
+ "1:15: error: Expected function declaration. Only extern functions can have empty declarations.\n"
+ " const func: fn;\n"
+ " ^\n");
+ test_load_error("tests/errors/declaration_no_type.amal",
+ "1:8: error: A variable can't be declared without a type or assignment\n"
+ " const a;\n"
+ " ^\n");
+ test_load_error("tests/errors/declaration_no_type_extern.amal",
+ "1:15: error: A variable can't be declared without a type or assignment\n"
+ " extern const a;\n"
+ " ^\n");
+}
+
/* TODO: Restrict variables in global scope to const */
int main(int argc, char **argv) {
int result;
@@ -212,34 +261,14 @@ int main(int argc, char **argv) {
exit(1);
}
+ /* Sanity check */
return_if_error(test_hash_map());
/* Run all tests */
if(argc == 1) {
- test_load("tests/main.amal");
- test_load("tests/utf8bom.amal");
- test_load("tests/bytecode.amal");
-
- test_load_error("tests/errors/duplicate_declaration.amal",
- "2:7: error: Variable with the name main was declared twice in the same scope\n"
- "const main = fn {}\n"
- " ^\n");
- test_load_error("tests/errors/pub_in_closure.amal",
- "2:5: error: Only declarations in global structs can be public\n"
- " pub const num = 45;\n"
- " ^\n");
- test_load_error("tests/errors/closure_no_lhs.amal",
- "1:1: error: Expected string, variable, closure, struct, function call or import\n"
- "fn {}\n"
- "^\n");
- test_load_error("tests/errors/const_assign.amal",
- "3:5: error: Can't assign to a const value\n"
- " value = 34;\n"
- " ^\n");
- fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run);
+ run_all_tests();
} else if(argc == 2) {
test_load(argv[1]);
- fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run);
} else {
fprintf(stderr, "usage: test [test-file-path]\n");
fprintf(stderr, "If you run test without any files then all tests will run.\n");
@@ -249,5 +278,6 @@ int main(int argc, char **argv) {
exit(1);
}
+ fprintf(stderr, "##### %d/%d tests succeeded #####\n", num_successful_tests, num_tests_run);
return 0;
-} \ No newline at end of file
+}