use compact_str::CompactString;
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DataRepresentation {
pub source_type: CompactString,
pub target_type: CompactString,
pub function: CompactString,
}
pub type RepresentationsMap = HashMap<(CompactString, CompactString), DataRepresentation>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_data_representation_creation() {
let repr = DataRepresentation {
source_type: "bytea".into(),
target_type: "image/png".into(),
function: "bytea_to_png".into(),
};
assert_eq!(repr.source_type.as_str(), "bytea");
assert_eq!(repr.target_type.as_str(), "image/png");
assert_eq!(repr.function.as_str(), "bytea_to_png");
}
#[test]
fn test_representations_map() {
let mut map: RepresentationsMap = HashMap::new();
let repr = DataRepresentation {
source_type: "bytea".into(),
target_type: "text".into(),
function: "encode".into(),
};
map.insert(("bytea".into(), "text".into()), repr.clone());
assert_eq!(map.get(&("bytea".into(), "text".into())), Some(&repr));
assert!(!map.contains_key(&("text".into(), "bytea".into())));
}
#[test]
fn test_data_representation_equality() {
let a = DataRepresentation {
source_type: "int".into(),
target_type: "text".into(),
function: "int_to_text".into(),
};
let b = a.clone();
assert_eq!(a, b);
}
}