plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
plum-checker/tests/examples_test.rs
#![allow(non_snake_case)]
use plum_checker::checkSource;
use plum_core::AstParser;
fn examplesDir() -> std::path::PathBuf {
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../examples")
}
fn exampleFiles() -> Vec<std::path::PathBuf> {
let mut files: Vec<_> = std::fs::read_dir(examplesDir())
.expect("examples/ directory should exist")
.filter_map(|e| e.ok())
.map(|e| e.path())
.filter(|p| p.extension().and_then(|e| e.to_str()) == Some("plum"))
.collect();
files.sort();
assert!(!files.is_empty(), "examples/ should contain at least one .plum file");
files
}
/// Every example must parse with zero ERROR/MISSING nodes and pass `checkSource`.
/// These files exist specifically to prove each piece of the currently-supported
/// grammar surface actually works end to end, not just in isolated unit tests.
#[test]
fn everyExampleParsesAndTypeChecks() {
let mut parser = tree_sitter::Parser::new();
parser.set_language(&tree_sitter_plum::LANGUAGE.into()).unwrap();
for path in exampleFiles() {
let src = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("failed to read {}: {}", path.display(), e));
let tree = parser.parse(&src, None).unwrap_or_else(|| panic!("failed to parse {}", path.display()));
assert!(
!tree.root_node().has_error(),
"{} has a parse error:\n{}",
path.display(),
tree.root_node().to_sexp()
);
let ap = AstParser::new(&src);
let source = ap.parseSource(tree.root_node());
let result = checkSource(&source);
assert!(
result.is_ok(),
"{} failed type checking: {:?}",
path.display(),
result.err().map(|errs| errs.into_iter().map(|e| e.message).collect::<Vec<_>>())
);
}
}