use itertools::Itertools;
use crate::{assert, assert::Assert};
#[test]
fn test_go() {
macro_rules! test_case {
($name:expr) => {
include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/testcases/eval/go/",
$name,
))
};
}
fn ignore_bad_lines(x: &str, bad: &[&str]) -> String {
x.lines()
.filter(|x| !bad.iter().any(|b| x.contains(b)))
.join("\n")
}
let assert = Assert::new();
assert.conformance_except(
test_case!("assign.star"),
&[
"hasfields()", ],
);
assert.conformance(test_case!("bool.star"));
assert.conformance(&ignore_bad_lines(
test_case!("builtin.star"),
&[
"[] not in {123: \"\"}", "set(",
"(myset)",
"(myset,",
"hasfields()",
"(hf)",
"(hf,",
"(hf,",
"hf.",
"(setfield,",
"True in range(3)",
"\"one\" in range(10)",
"dir({})[:3]",
"dir([])[:3]",
],
));
assert.conformance(test_case!("control.star"));
assert.conformance_except(
&ignore_bad_lines(
test_case!("dict.star"),
&[
"unknown binary op: dict \\\\+ dict", "cannot insert into frozen hash table", "cannot clear frozen hash table",
"assert.eq(a, 1)", "assert.eq(x, {1: 2, 2: 4, 0: 2})",
],
),
&[
"Verify position of an \"unhashable key\"", "Verify position of a \"duplicate key\"", "Verify position of an \"unhashable key\"", ],
);
assert.conformance(&ignore_bad_lines(
test_case!("float.star"),
&[
"1229999999999999973",
"9223372036854775808",
"1000000000000000000",
"1230000000000000049",
"9223372036854775807",
"p53",
"maxint64",
"int too large to convert to float",
"int(1e100)",
"1000000 * 1000000 * 1000000",
"int overflow in starlark-rust",
],
));
assert.conformance(&ignore_bad_lines(
test_case!("function.star"),
&[
"eq(str", "frozen list", "called recursively", "hf", ],
));
assert.conformance_except(
&ignore_bad_lines(
test_case!("misc.star"),
&[
"'<built-in function freeze>'", ],
),
&[
"cyclic data structures", ],
);
assert.conformance(&ignore_bad_lines(
test_case!("tuple.star"),
&[
"1000000 * 1000000", ],
));
}
#[test]
fn test_in_range() {
assert::all_true(
r#"
not (True in range(3))
not ("one" in range(10))
"#,
);
}