Skip to content

Commit

Permalink
feat(test): still moving
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Jul 11, 2024
1 parent 4645ac7 commit 30213de
Show file tree
Hide file tree
Showing 27 changed files with 79 additions and 154 deletions.
154 changes: 0 additions & 154 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "
Expand Down
4 changes: 4 additions & 0 deletions src/tests/validity/function.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fun test() {
return \"Hello World\"
}
echo test()
1 change: 1 addition & 0 deletions src/tests/validity/function.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
13 changes: 13 additions & 0 deletions src/tests/validity/function_ref_swap.ab
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/tests/validity/function_ref_swap.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
24
12
4 changes: 4 additions & 0 deletions src/tests/validity/function_with_args.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fun test(a, b) {
return \"{a} {b}\"
}
echo test(\"Hello\", \"World\")
1 change: 1 addition & 0 deletions src/tests/validity/function_with_args.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
5 changes: 5 additions & 0 deletions src/tests/validity/function_with_args_different_types.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fun test(a, b) {
return a + b
}
echo test(\"Hello\", \"World\")
echo test(11, 42)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HelloWorld
53
4 changes: 4 additions & 0 deletions src/tests/validity/function_with_typed_args.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fun test(a: Num, b: Num) {
return a + b
}
echo test(11, 42)
1 change: 1 addition & 0 deletions src/tests/validity/function_with_typed_args.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
53
4 changes: 4 additions & 0 deletions src/tests/validity/function_with_typed_args_text.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub fun test(a: Text, b: Text) {
echo a + b
}
test(\"Hello\", \"World\")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HelloWorld
5 changes: 5 additions & 0 deletions src/tests/validity/function_with_typed_different_args.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fun test(a: Num, b: Text) {
echo a
echo b
}
test(11, \"Hello\")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
11
Hello
2 changes: 2 additions & 0 deletions src/tests/validity/import_existing_file.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * from "test_files/str/trim.ab"
echo trim(" Hello World ")
1 change: 1 addition & 0 deletions src/tests/validity/import_existing_file.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
2 changes: 2 additions & 0 deletions src/tests/validity/import_existing_nested_file.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * from "test_files/is_even.ab"
echo is_even(10)
1 change: 1 addition & 0 deletions src/tests/validity/import_existing_nested_file.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
even
13 changes: 13 additions & 0 deletions src/tests/validity/infinite_loop.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let a = 0
main {
loop {
a += 1
if a == 5 {
continue
}
$printf \"{a} \"$?
if a == 10 {
break
}
}
}
1 change: 1 addition & 0 deletions src/tests/validity/infinite_loop.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 3 4 6 7 8 9 10
2 changes: 2 additions & 0 deletions src/tests/validity/modulo_operator.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let a = 10 % 3
echo a
1 change: 1 addition & 0 deletions src/tests/validity/modulo_operator.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
3 changes: 3 additions & 0 deletions src/tests/validity/modulo_shorthand.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let a = 10
a %= 3
echo a
1 change: 1 addition & 0 deletions src/tests/validity/modulo_shorthand.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
2 changes: 2 additions & 0 deletions src/tests/validity/public_import.ab
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * from "test_files/is_even.ab"
echo trim(" test ")
1 change: 1 addition & 0 deletions src/tests/validity/public_import.output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test

0 comments on commit 30213de

Please sign in to comment.