use yog_ids::script_problem;
use yog_script_analyze::index::ClassIndex;
use yog_script_analyze::{check, check_with};
fn codes(problems: Vec<yog_data::Diagnostic>) -> Vec<String> {
problems
.into_iter()
.filter_map(|d| d.code.map(|c| c.to_string()))
.collect()
}
fn game(mc: &str) -> ClassIndex {
ClassIndex {
mc: mc.into(),
classes: vec![],
}
}
const SRC: &str = "targets mc 1.20.1..26.2;\n\n#if MC >= 1.21\ni32 Armor() => 2;\n#else\ni32 Armor() => \"old\";\n#endif\n";
#[test]
fn each_version_reads_its_branch() {
assert!(codes(check_with("a.yns", SRC, Some(&game("1.21.1"))).problems).is_empty());
assert_eq!(
codes(check_with("a.yns", SRC, Some(&game("1.20.1"))).problems),
[script_problem::TYPE_MISMATCH]
);
assert!(codes(check("a.yns", SRC).problems).is_empty());
}
#[test]
fn directives_are_a_yns_files_and_well_formed() {
assert_eq!(
codes(check("A.ys", "#if MC >= 1.21\n#endif\n").problems),
[script_problem::DIRECTIVE]
);
let open = "targets mc 1.20.1..26.2;\n#if MC >= 1.21\n";
assert_eq!(
codes(check("a.yns", open).problems),
[script_problem::DIRECTIVE]
);
let tag = "bool F(Block b) => b in #minecraft:logs;\n";
assert!(!codes(check("A.ys", tag).problems).contains(&script_problem::DIRECTIVE.to_string()));
}