const CARGO_TOML: &str = include_str!("../../Cargo.toml");
const README_EN: &str = include_str!("../../README.md");
const README_ZH: &str = include_str!("../../README.zh_CN.md");
const ARC_RW_LOCK_SRC: &str = include_str!("../../src/lock/arc_rw_lock.rs");
const ARC_ASYNC_RW_LOCK_SRC: &str = include_str!("../../src/lock/arc_async_rw_lock.rs");
#[test]
fn test_readme_no_legacy_lock_api_names() {
assert!(!README_EN.contains("with_lock"));
assert!(!README_EN.contains("try_with_lock"));
assert!(!README_ZH.contains("with_lock"));
assert!(!README_ZH.contains("try_with_lock"));
}
#[test]
fn test_rw_lock_docs_use_current_trait_names() {
assert!(!ARC_RW_LOCK_SRC.contains("ReadWriteLock"));
assert!(!ARC_ASYNC_RW_LOCK_SRC.contains("AsyncReadWriteLock"));
assert!(ARC_RW_LOCK_SRC.contains("ArcRwLock, Lock"));
assert!(ARC_ASYNC_RW_LOCK_SRC.contains("ArcAsyncRwLock, AsyncLock"));
}
#[test]
fn test_readme_dependency_version_matches_cargo_toml() {
let cargo_version =
extract_package_version(CARGO_TOML).expect("Failed to extract version from Cargo.toml");
let readme_en_version = extract_readme_dependency_version(README_EN)
.expect("Failed to extract version from README.md");
let readme_zh_version = extract_readme_dependency_version(README_ZH)
.expect("Failed to extract version from README.zh_CN.md");
assert_eq!(readme_en_version, cargo_version);
assert_eq!(readme_zh_version, cargo_version);
}
fn extract_package_version(content: &str) -> Option<&str> {
for line in content.lines() {
if let Some(value) = line.strip_prefix("version = \"") {
return value.strip_suffix('"');
}
}
None
}
fn extract_readme_dependency_version(content: &str) -> Option<&str> {
for line in content.lines() {
if let Some(value) = line.trim().strip_prefix("qubit-lock = \"") {
return value.strip_suffix('"');
}
}
None
}