use std::path::{Path, PathBuf};
use aura_lang::fmt::format_source;
use aura_lang::lexer::Lexer;
use aura_lang::parser::Parser;
fn repo_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.canonicalize()
.expect("repo root")
}
fn committed() -> String {
std::fs::read_to_string(repo_root().join("llms.txt")).expect("llms.txt at the repository root")
}
#[test]
fn the_committed_reference_matches_the_generator() {
let generated = aura_lang::agentdocs::render();
let normalise = |s: &str| s.replace("\r\n", "\n");
assert_eq!(
normalise(&committed()),
normalise(&generated),
"llms.txt is out of date — regenerate it with `aura docs --agent -o llms.txt`"
);
}
#[test]
fn every_example_in_the_reference_parses() {
let text = committed();
let blocks = aura_blocks(&text);
assert!(
blocks.len() >= 8,
"found only {} aura blocks — the extractor is probably broken, and finding \
none would let this pass for the wrong reason",
blocks.len()
);
for (i, block) in blocks.iter().enumerate() {
let tokens = Lexer::new(block, 0)
.tokenize()
.unwrap_or_else(|d| panic!("block {i} does not lex: {}\n{block}", d.message));
Parser::new(tokens)
.parse_module()
.unwrap_or_else(|ds| panic!("block {i} does not parse: {}\n{block}", ds[0].message));
}
}
#[test]
fn every_example_in_the_reference_is_canonically_formatted() {
let text = committed();
let mut offenders = Vec::new();
for (i, block) in aura_blocks(&text).iter().enumerate() {
if let Ok(formatted) = format_source(block) {
if formatted != *block {
offenders.push(format!("block {i}:\n{block}--- expected:\n{formatted}"));
}
}
}
assert!(
offenders.is_empty(),
"examples are not `aura fmt` output:\n{}",
offenders.join("\n")
);
}
fn aura_blocks(md: &str) -> Vec<String> {
let mut out = Vec::new();
let mut lines = md.lines();
while let Some(line) = lines.next() {
if line.trim() != "```aura" {
continue;
}
let mut block = String::new();
for body in lines.by_ref() {
if body.trim() == "```" {
break;
}
block.push_str(body);
block.push('\n');
}
if !block.trim().is_empty() {
out.push(block);
}
}
out
}