Files
core/test/rust/native/standard.rs
T
2026-11-03 03:32:07 +00:00

74 lines
2.6 KiB
Rust

use super::{Directory, fixture};
use dever::compiler::{build, project::Project};
#[test]
fn native_text_numeric_and_math_interfaces_execute_without_a_runtime() {
let directory = Directory::new();
let project = Project::load(&fixture().with_file_name("standard.dever")).unwrap();
let program = project.check().unwrap();
for entry in ["textVerify", "numericVerify"] {
let index = program
.functions
.iter()
.position(|function| function.signature.name == entry)
.unwrap();
assert!(build::runtime_features(&program, &program.reachable([index])).is_empty());
let binary =
build::build(&program, &project.sources, entry, &directory.0.join(entry)).unwrap();
let result = std::process::Command::new(binary).output().unwrap();
assert!(
result.status.success(),
"{entry}: {}",
String::from_utf8_lossy(&result.stderr)
);
assert_eq!(result.stdout, b"true\n", "{entry}");
}
}
#[test]
fn decimal_round_fault_keeps_the_original_library_position() {
let directory = Directory::new();
let project = Project::load(&fixture().with_file_name("standard.dever")).unwrap();
let program = project.check().unwrap();
let binary = build::build(
&program,
&project.sources,
"invalidRound",
&directory.0.join("invalid"),
)
.unwrap();
let result = std::process::Command::new(binary).output().unwrap();
assert!(!result.status.success());
let error = String::from_utf8(result.stderr).unwrap();
assert!(error.contains("Decimal rounding fault"), "{error}");
let source = project
.sources
.iter()
.find(|source| source.path.ends_with("lib/decimal.dever"))
.unwrap();
let (line, column) = source.position(
source
.text
.find("dever.system.decimalRound(value, places)")
.unwrap(),
);
assert!(
error.contains(&format!("{}:{line}:{column}:", source.path.display())),
"{error}"
);
}
#[test]
fn user_packages_cannot_claim_standard_namespaces() {
for name in ["text", "int", "decimal", "float", "math", "uuid"] {
let directory = Directory::new();
std::fs::write(directory.0.join(format!("{name}.dever")), "unused").unwrap();
let result = Project::load(&directory.0);
let error = match result {
Ok(_) => panic!("reserved package accepted"),
Err(error) => error,
};
assert!(error.contains("reserved standard namespace"), "{error}");
}
}