diff --git a/src/tests/validity.rs b/src/tests/validity.rs index 35f9f7e5..aea72643 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -19,160 +19,6 @@ fn validity_test(input: &str) { test_amber!(code, output); } -#[test] -fn infinite_loop() { - let code = " - let a = 0 - main { - loop { - a += 1 - if a == 5 { - continue - } - $printf \"{a} \"$? - if a == 10 { - break - } - } - } - "; - test_amber!(code, "1 2 3 4 6 7 8 9 10 "); -} - -#[test] -fn modulo_operator() { - let code = " - let a = 10 % 3 - echo a - "; - test_amber!(code, "1"); -} - -#[test] -fn modulo_shorthand() { - let code = " - let a = 10 - a %= 3 - echo a - "; - test_amber!(code, "1"); -} - -#[test] -fn function() { - let code = " - fun test() { - return \"Hello World\" - } - echo test() - "; - test_amber!(code, "Hello World"); -} - -#[test] -fn function_with_args() { - let code = " - fun test(a, b) { - return \"{a} {b}\" - } - echo test(\"Hello\", \"World\") - "; - test_amber!(code, "Hello World"); -} - -#[test] -fn function_with_args_different_types() { - let code = " - fun test(a, b) { - return a + b - } - echo test(\"Hello\", \"World\") - echo test(11, 42) - "; - test_amber!(code, "HelloWorld\n53"); -} - -#[test] -fn function_with_typed_args() { - let code = " - fun test(a: Num, b: Num) { - return a + b - } - echo test(11, 42) - "; - test_amber!(code, "53"); -} - -#[test] -fn function_with_typed_different_args() { - let code = " - fun test(a: Num, b: Text) { - echo a - echo b - } - test(11, \"Hello\") - "; - test_amber!(code, "11\nHello"); -} - -#[test] -fn function_with_typed_args_text() { - let code = " - pub fun test(a: Text, b: Text) { - echo a + b - } - test(\"Hello\", \"World\") - "; - test_amber!(code, "HelloWorld"); -} - -#[test] -fn import_existing_file() { - let code = " - import * from \"test_files/str/trim.ab\" - echo trim(\" Hello World \") - "; - test_amber!(code, "Hello World"); -} - -#[test] -fn import_existing_nested_file() { - let code = " - import * from \"test_files/is_even.ab\" - echo is_even(10) - "; - test_amber!(code, "even"); -} - -#[test] -fn public_import() { - let code = " - import * from \"test_files/is_even.ab\" - echo trim(\" test \") - "; - test_amber!(code, "test"); -} - -#[test] -fn function_ref_swap() { - let code = " - fun swap(ref a, ref b) { - let temp = a - a = b - b = temp - } - - let a = 12 - let b = 24 - - swap(a, b) - - echo a - echo b - "; - test_amber!(code, "24\n12"); -} - #[test] fn function_ref_text_escaped() { let code = " diff --git a/src/tests/validity/function.ab b/src/tests/validity/function.ab new file mode 100644 index 00000000..ebefdc32 --- /dev/null +++ b/src/tests/validity/function.ab @@ -0,0 +1,4 @@ +fun test() { + return \"Hello World\" +} +echo test() \ No newline at end of file diff --git a/src/tests/validity/function.output.txt b/src/tests/validity/function.output.txt new file mode 100644 index 00000000..5e1c309d --- /dev/null +++ b/src/tests/validity/function.output.txt @@ -0,0 +1 @@ +Hello World \ No newline at end of file diff --git a/src/tests/validity/function_ref_swap.ab b/src/tests/validity/function_ref_swap.ab new file mode 100644 index 00000000..01ccaa7d --- /dev/null +++ b/src/tests/validity/function_ref_swap.ab @@ -0,0 +1,13 @@ +fun swap(ref a, ref b) { + let temp = a + a = b + b = temp +} + +let a = 12 +let b = 24 + +swap(a, b) + +echo a +echo b \ No newline at end of file diff --git a/src/tests/validity/function_ref_swap.output.txt b/src/tests/validity/function_ref_swap.output.txt new file mode 100644 index 00000000..ccb1bebc --- /dev/null +++ b/src/tests/validity/function_ref_swap.output.txt @@ -0,0 +1,2 @@ +24 +12 \ No newline at end of file diff --git a/src/tests/validity/function_with_args.ab b/src/tests/validity/function_with_args.ab new file mode 100644 index 00000000..99bffde2 --- /dev/null +++ b/src/tests/validity/function_with_args.ab @@ -0,0 +1,4 @@ +fun test(a, b) { + return \"{a} {b}\" +} +echo test(\"Hello\", \"World\") \ No newline at end of file diff --git a/src/tests/validity/function_with_args.output.txt b/src/tests/validity/function_with_args.output.txt new file mode 100644 index 00000000..5e1c309d --- /dev/null +++ b/src/tests/validity/function_with_args.output.txt @@ -0,0 +1 @@ +Hello World \ No newline at end of file diff --git a/src/tests/validity/function_with_args_different_types.ab b/src/tests/validity/function_with_args_different_types.ab new file mode 100644 index 00000000..c28ee55e --- /dev/null +++ b/src/tests/validity/function_with_args_different_types.ab @@ -0,0 +1,5 @@ +fun test(a, b) { + return a + b +} +echo test(\"Hello\", \"World\") +echo test(11, 42) \ No newline at end of file diff --git a/src/tests/validity/function_with_args_different_types.output.txt b/src/tests/validity/function_with_args_different_types.output.txt new file mode 100644 index 00000000..96b11281 --- /dev/null +++ b/src/tests/validity/function_with_args_different_types.output.txt @@ -0,0 +1,2 @@ +HelloWorld +53 \ No newline at end of file diff --git a/src/tests/validity/function_with_typed_args.ab b/src/tests/validity/function_with_typed_args.ab new file mode 100644 index 00000000..4a58ef0f --- /dev/null +++ b/src/tests/validity/function_with_typed_args.ab @@ -0,0 +1,4 @@ +fun test(a: Num, b: Num) { + return a + b +} +echo test(11, 42) \ No newline at end of file diff --git a/src/tests/validity/function_with_typed_args.output.txt b/src/tests/validity/function_with_typed_args.output.txt new file mode 100644 index 00000000..8783e305 --- /dev/null +++ b/src/tests/validity/function_with_typed_args.output.txt @@ -0,0 +1 @@ +53 \ No newline at end of file diff --git a/src/tests/validity/function_with_typed_args_text.ab b/src/tests/validity/function_with_typed_args_text.ab new file mode 100644 index 00000000..a533931a --- /dev/null +++ b/src/tests/validity/function_with_typed_args_text.ab @@ -0,0 +1,4 @@ +pub fun test(a: Text, b: Text) { + echo a + b +} +test(\"Hello\", \"World\") \ No newline at end of file diff --git a/src/tests/validity/function_with_typed_args_text.output.txt b/src/tests/validity/function_with_typed_args_text.output.txt new file mode 100644 index 00000000..8970971f --- /dev/null +++ b/src/tests/validity/function_with_typed_args_text.output.txt @@ -0,0 +1 @@ +HelloWorld \ No newline at end of file diff --git a/src/tests/validity/function_with_typed_different_args.ab b/src/tests/validity/function_with_typed_different_args.ab new file mode 100644 index 00000000..4120b6b1 --- /dev/null +++ b/src/tests/validity/function_with_typed_different_args.ab @@ -0,0 +1,5 @@ +fun test(a: Num, b: Text) { + echo a + echo b +} +test(11, \"Hello\") \ No newline at end of file diff --git a/src/tests/validity/function_with_typed_different_args.output.txt b/src/tests/validity/function_with_typed_different_args.output.txt new file mode 100644 index 00000000..f959a4b2 --- /dev/null +++ b/src/tests/validity/function_with_typed_different_args.output.txt @@ -0,0 +1,2 @@ +11 +Hello \ No newline at end of file diff --git a/src/tests/validity/import_existing_file.ab b/src/tests/validity/import_existing_file.ab new file mode 100644 index 00000000..d1ca9a7d --- /dev/null +++ b/src/tests/validity/import_existing_file.ab @@ -0,0 +1,2 @@ +import * from "test_files/str/trim.ab" +echo trim(" Hello World ") \ No newline at end of file diff --git a/src/tests/validity/import_existing_file.output.txt b/src/tests/validity/import_existing_file.output.txt new file mode 100644 index 00000000..5e1c309d --- /dev/null +++ b/src/tests/validity/import_existing_file.output.txt @@ -0,0 +1 @@ +Hello World \ No newline at end of file diff --git a/src/tests/validity/import_existing_nested_file.ab b/src/tests/validity/import_existing_nested_file.ab new file mode 100644 index 00000000..5c1d71dd --- /dev/null +++ b/src/tests/validity/import_existing_nested_file.ab @@ -0,0 +1,2 @@ +import * from "test_files/is_even.ab" +echo is_even(10) \ No newline at end of file diff --git a/src/tests/validity/import_existing_nested_file.output.txt b/src/tests/validity/import_existing_nested_file.output.txt new file mode 100644 index 00000000..21a82c71 --- /dev/null +++ b/src/tests/validity/import_existing_nested_file.output.txt @@ -0,0 +1 @@ +even \ No newline at end of file diff --git a/src/tests/validity/infinite_loop.ab b/src/tests/validity/infinite_loop.ab new file mode 100644 index 00000000..06a6be46 --- /dev/null +++ b/src/tests/validity/infinite_loop.ab @@ -0,0 +1,13 @@ +let a = 0 +main { + loop { + a += 1 + if a == 5 { + continue + } + $printf \"{a} \"$? + if a == 10 { + break + } + } +} \ No newline at end of file diff --git a/src/tests/validity/infinite_loop.output.txt b/src/tests/validity/infinite_loop.output.txt new file mode 100644 index 00000000..c3dbb8e7 --- /dev/null +++ b/src/tests/validity/infinite_loop.output.txt @@ -0,0 +1 @@ +1 2 3 4 6 7 8 9 10 \ No newline at end of file diff --git a/src/tests/validity/modulo_operator.ab b/src/tests/validity/modulo_operator.ab new file mode 100644 index 00000000..92ba45ce --- /dev/null +++ b/src/tests/validity/modulo_operator.ab @@ -0,0 +1,2 @@ +let a = 10 % 3 +echo a \ No newline at end of file diff --git a/src/tests/validity/modulo_operator.output.txt b/src/tests/validity/modulo_operator.output.txt new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/src/tests/validity/modulo_operator.output.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/src/tests/validity/modulo_shorthand.ab b/src/tests/validity/modulo_shorthand.ab new file mode 100644 index 00000000..e998a111 --- /dev/null +++ b/src/tests/validity/modulo_shorthand.ab @@ -0,0 +1,3 @@ +let a = 10 +a %= 3 +echo a \ No newline at end of file diff --git a/src/tests/validity/modulo_shorthand.output.txt b/src/tests/validity/modulo_shorthand.output.txt new file mode 100644 index 00000000..56a6051c --- /dev/null +++ b/src/tests/validity/modulo_shorthand.output.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/src/tests/validity/public_import.ab b/src/tests/validity/public_import.ab new file mode 100644 index 00000000..49efa62d --- /dev/null +++ b/src/tests/validity/public_import.ab @@ -0,0 +1,2 @@ +import * from "test_files/is_even.ab" +echo trim(" test ") \ No newline at end of file diff --git a/src/tests/validity/public_import.output.txt b/src/tests/validity/public_import.output.txt new file mode 100644 index 00000000..30d74d25 --- /dev/null +++ b/src/tests/validity/public_import.output.txt @@ -0,0 +1 @@ +test \ No newline at end of file