pub mod context;
pub mod lint;
pub mod tracking;
pub use context::{FileContext, SexContext};
pub use lint::{LintResult, SexLintError, SexLintWarning, SexLinter};
pub use tracking::EffectTracker;
use std::path::Path;
pub fn is_sex_file(path: &Path) -> bool {
let path_str = path.to_string_lossy();
if path_str.ends_with(".sex.dol") {
return true;
}
for component in path.components() {
if component.as_os_str() == "sex" {
return true;
}
}
false
}
pub fn file_sex_context(path: &Path) -> SexContext {
if is_sex_file(path) {
SexContext::Sex
} else {
SexContext::Pure
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sex_file_detection_with_extension() {
assert!(is_sex_file(Path::new("io.sex.dol")));
assert!(is_sex_file(Path::new("globals.sex.dol")));
assert!(is_sex_file(Path::new("src/ffi.sex.dol")));
}
#[test]
fn test_sex_file_detection_in_directory() {
assert!(is_sex_file(Path::new("src/sex/globals.dol")));
assert!(is_sex_file(Path::new("sex/ffi.dol")));
assert!(is_sex_file(Path::new("modules/sex/io.dol")));
}
#[test]
fn test_pure_file_detection() {
assert!(!is_sex_file(Path::new("container.dol")));
assert!(!is_sex_file(Path::new("src/genes/process.dol")));
assert!(!is_sex_file(Path::new("traits/lifecycle.dol")));
}
#[test]
fn test_file_sex_context() {
assert_eq!(file_sex_context(Path::new("io.sex.dol")), SexContext::Sex);
assert_eq!(
file_sex_context(Path::new("container.dol")),
SexContext::Pure
);
}
}