use escriba_lisp::ApplyPlan;
const BLUE: &str = "blue";
fn boot_plan() -> ApplyPlan {
escriba::default_plan(false).expect("the default boot plan builds")
}
#[test]
fn render_registry_resolves_blue_sources() {
let eco = escriba_render::gpu::build_ecosystem();
assert_eq!(
eco.resolve("scratch.b"),
escriba_render::langs::BLUE,
"`.b` must resolve to blue — escriba_render::langs registers it",
);
assert_eq!(
eco.resolve("Bluefile"),
escriba_render::langs::BLUE,
"a Bluefile is a blue program and has no extension to match on",
);
}
#[test]
fn boot_plan_declares_the_blue_major_mode() {
let plan = boot_plan();
let mode = plan
.major_modes
.iter()
.find(|m| m.name == BLUE)
.expect("blnvim-defaults.lisp must carry `(defmode :name \"blue\" …)`");
assert!(
mode.extensions.iter().any(|e| e == "b"),
"blue's extension is `.b`: {:?}",
mode.extensions,
);
assert_eq!(mode.commentstring, "# %s", "blue comments are `#` to EOL");
assert!(
mode.tree_sitter.is_empty(),
"blue must claim no tree-sitter grammar — none exists; got {:?}",
mode.tree_sitter,
);
}
#[test]
fn boot_plan_binds_the_blue_language_server() {
let plan = boot_plan();
let lsp = plan
.lsp_servers
.iter()
.find(|s| s.filetypes.iter().any(|f| f == BLUE))
.expect("escriba-lspconfig must carry a `(deflsp …)` for blue");
assert_eq!(lsp.command, "blue");
assert_eq!(lsp.args, vec!["lsp"]);
assert!(
lsp.root_markers.iter().any(|m| m == "Bluefile"),
"a Bluefile roots a blue project: {:?}",
lsp.root_markers,
);
assert!(!lsp.manual_only, "blue should auto-attach like its peers");
}
#[test]
fn boot_plan_binds_the_blue_formatter() {
let plan = boot_plan();
let fmt = plan
.formatters
.iter()
.find(|f| f.filetype == BLUE)
.expect("escriba-conform must carry a `(defformatter :filetype \"blue\" …)`");
assert_eq!(fmt.command, "blue");
assert!(
fmt.args.iter().any(|a| a == "--write"),
"`blue fmt` without --write is a no-op filter: {:?}",
fmt.args,
);
assert!(
fmt.args.iter().any(|a| a == "$FILE"),
"`blue fmt` takes a FILE, it does not read stdin: {:?}",
fmt.args,
);
}
#[test]
fn boot_plan_gates_blue_on_its_one_formatting() {
let plan = boot_plan();
let gate = plan
.gates
.iter()
.find(|g| g.filetype == BLUE)
.expect("escriba-conform must carry the blue-canonical gate");
assert_eq!(gate.on_event, "BufWritePre");
assert_eq!(gate.action, "auto-fix");
assert!(
gate.command.contains("--check"),
"the check half must be `--check`, not a rewrite: {:?}",
gate.command,
);
assert!(
gate.auto_fix.contains("--write"),
"the repair half must actually write: {:?}",
gate.auto_fix,
);
}
#[test]
fn every_blue_leg_agrees_on_the_filetype_name() {
let plan = boot_plan();
let mode = plan
.major_modes
.iter()
.find(|m| m.name == BLUE)
.expect("blue major mode");
let mut orphans: Vec<&str> = Vec::new();
if !plan
.lsp_servers
.iter()
.any(|s| s.filetypes.iter().any(|f| *f == mode.name))
{
orphans.push("deflsp");
}
if !plan.formatters.iter().any(|f| f.filetype == mode.name) {
orphans.push("defformatter");
}
if !plan.gates.iter().any(|g| g.filetype == mode.name) {
orphans.push("defgate");
}
assert!(
orphans.is_empty(),
"these legs no longer reference the `{}` major mode: {:?}",
mode.name,
orphans,
);
let eco = escriba_render::gpu::build_ecosystem();
for ext in &mode.extensions {
let probe = ["probe.", ext].concat();
assert_eq!(
eco.resolve(&probe),
escriba_render::langs::BLUE,
"`(defmode :name \"blue\")` claims `.{ext}` but the render \
registry does not — escriba_render::langs::BLUE_SELECTORS is \
out of step with blnvim-defaults.lisp",
);
}
}