Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test output as comment #335

Merged
merged 11 commits into from
Jul 26, 2024
31 changes: 26 additions & 5 deletions src/tests/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,32 @@ fn stdlib_test(input: &str) {
let code =
fs::read_to_string(input).unwrap_or_else(|_| panic!("Failed to open {input} test file"));

let output = match Path::new(&input.replace(".ab", ".output.txt")).exists() {
true => fs::read_to_string(input.replace(".ab", ".output.txt"))
.unwrap_or_else(|_| panic!("Failed to open {input}.output.txt file")),
_ => "Succeded".to_string(),
};
let mut is_output = false;
let mut output = "".to_owned();
for line in code.lines() {
if line.starts_with("// Output") {
is_output = true;
continue;
} else if line.is_empty() && is_output {
is_output = false;
break;
}

if is_output {
if ! output.is_empty() {
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
output.push_str("\n");
}
output.push_str(&line.replace("//", "").trim());
}
}

if output.is_empty() {
output = match Path::new(&input.replace(".ab", ".output.txt")).exists() {
true => fs::read_to_string(input.replace(".ab", ".output.txt"))
.expect(&format!("Failed to open {input}.output.txt file")),
_ => "Succeded".to_string()
Mte90 marked this conversation as resolved.
Show resolved Hide resolved
};
}

test_amber!(code, output);
}
Expand Down
4 changes: 4 additions & 0 deletions src/tests/stdlib/array_first_index.ab
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * from "std/array"

// Output
// 2

main {
echo array_first_index([1, 2, 3, 4], 3)
}
1 change: 0 additions & 1 deletion src/tests/stdlib/array_first_index.output.txt

This file was deleted.

4 changes: 4 additions & 0 deletions src/tests/stdlib/array_search.ab
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * from "std/array"

// Output
// 6

main {
let result = array_search([1, 2, 3, 4, 3], 3)
echo result[0]+result[1]
Expand Down
1 change: 0 additions & 1 deletion src/tests/stdlib/array_search.output.txt

This file was deleted.

4 changes: 4 additions & 0 deletions src/tests/stdlib/chars.ab
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * from "std/text"

// Output
// h e l l o

main {
echo chars("hello")
}
1 change: 0 additions & 1 deletion src/tests/stdlib/chars.output.txt

This file was deleted.

4 changes: 4 additions & 0 deletions src/tests/stdlib/color_echo.ab
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * from "std/env"

// Output
// Hello Amber!

main {
color_echo("Hello Amber!", 33)
}
1 change: 0 additions & 1 deletion src/tests/stdlib/color_echo.output.txt

This file was deleted.

5 changes: 5 additions & 0 deletions src/tests/stdlib/lines.ab
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { lines } from "std/text"

// Output
// line: hello
// line: world

main {
loop line in lines("hello\nworld") {
echo "line: " + line
Expand Down
2 changes: 0 additions & 2 deletions src/tests/stdlib/lines.output.txt

This file was deleted.

Loading