#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct ModuleRead {
pub source: String,
pub target: String,
}
impl ModuleRead {
#[must_use]
pub fn new(source: impl Into<String>, target: impl Into<String>) -> Self {
Self {
source: source.into(),
target: target.into(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new() {
let read = ModuleRead::new("my.module", "java.sql");
assert_eq!("my.module", read.source);
assert_eq!("java.sql", read.target);
}
#[test]
fn test_new_with_string() {
let read = ModuleRead::new(String::from("source.module"), String::from("target.module"));
assert_eq!("source.module", read.source);
assert_eq!("target.module", read.target);
}
#[test]
fn test_clone() {
let read = ModuleRead::new("my.module", "java.sql");
let cloned = read.clone();
assert_eq!(read, cloned);
}
#[test]
fn test_debug() {
let read = ModuleRead::new("my.module", "java.sql");
let debug_str = format!("{read:?}");
assert!(debug_str.contains("my.module"));
assert!(debug_str.contains("java.sql"));
}
#[test]
fn test_equality() {
let read1 = ModuleRead::new("my.module", "java.sql");
let read2 = ModuleRead::new("my.module", "java.sql");
let read3 = ModuleRead::new("my.module", "java.xml");
assert_eq!(read1, read2);
assert_ne!(read1, read3);
}
#[test]
fn test_hash() {
use std::collections::HashSet;
let mut set = HashSet::new();
set.insert(ModuleRead::new("my.module", "java.sql"));
set.insert(ModuleRead::new("my.module", "java.sql"));
set.insert(ModuleRead::new("my.module", "java.xml"));
assert_eq!(2, set.len());
}
#[test]
fn test_all_unnamed_target() {
let read = ModuleRead::new("my.module", "ALL-UNNAMED");
assert_eq!("ALL-UNNAMED", read.target);
}
#[test]
fn test_empty_strings() {
let read = ModuleRead::new("", "");
assert_eq!("", read.source);
assert_eq!("", read.target);
}
#[test]
fn test_complex_module_names() {
let read = ModuleRead::new("com.example.app.module", "org.library.core");
assert_eq!("com.example.app.module", read.source);
assert_eq!("org.library.core", read.target);
}
}