[ledger] Core: haléře, dates, the event log and apply(), merchant keys and rules, one-to-one matching, import planning
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//! Mandatory test 1 (b): no floating-point type appears anywhere in the core. Money, dates, matching,
|
||||
//! subscriptions and the forecast are all integers, so the whole workspace is scanned.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn rust_files(dir: &Path, out: &mut Vec<PathBuf>) {
|
||||
for entry in std::fs::read_dir(dir).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
if path.is_dir() {
|
||||
if path.file_name().is_some_and(|n| n == "target") {
|
||||
continue;
|
||||
}
|
||||
rust_files(&path, out);
|
||||
} else if path.extension().is_some_and(|e| e == "rs") {
|
||||
out.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_float_type_in_any_source_file() {
|
||||
let crates = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
|
||||
let mut files = Vec::new();
|
||||
rust_files(crates, &mut files);
|
||||
assert!(files.len() > 10, "the scan found too few files: {}", files.len());
|
||||
|
||||
// Spelled apart so this file does not match itself.
|
||||
let banned = [concat!("f", "32"), concat!("f", "64")];
|
||||
let mut hits = Vec::new();
|
||||
for file in &files {
|
||||
let text = std::fs::read_to_string(file).unwrap();
|
||||
for (n, line) in text.lines().enumerate() {
|
||||
let words = line.split(|c: char| !(c.is_ascii_alphanumeric() || c == '_'));
|
||||
if words.into_iter().any(|w| banned.contains(&w)) {
|
||||
hits.push(format!("{}:{}: {}", file.display(), n + 1, line.trim()));
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(hits.is_empty(), "floating point in the core:\n{}", hits.join("\n"));
|
||||
}
|
||||
Reference in New Issue
Block a user