#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct CursorConfig {
pub read_uncommitted: bool,
}
impl CursorConfig {
pub fn new() -> Self {
Self::default()
}
pub fn set_read_uncommitted(
&mut self,
read_uncommitted: bool,
) -> &mut Self {
self.read_uncommitted = read_uncommitted;
self
}
pub fn with_read_uncommitted(mut self, read_uncommitted: bool) -> Self {
self.read_uncommitted = read_uncommitted;
self
}
pub fn read_uncommitted() -> Self {
Self::new().with_read_uncommitted(true)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_defaults_to_no_read_uncommitted() {
let config = CursorConfig::new();
assert!(!config.read_uncommitted);
}
#[test]
fn test_set_read_uncommitted() {
let mut config = CursorConfig::new();
config.set_read_uncommitted(true);
assert!(config.read_uncommitted);
}
#[test]
fn test_with_read_uncommitted() {
let config = CursorConfig::new().with_read_uncommitted(true);
assert!(config.read_uncommitted);
}
#[test]
fn test_read_uncommitted_factory() {
let config = CursorConfig::read_uncommitted();
assert!(config.read_uncommitted);
}
#[test]
fn test_default() {
let config = CursorConfig::default();
assert!(!config.read_uncommitted);
}
#[test]
fn test_clone_eq() {
let a = CursorConfig::read_uncommitted();
let b = a.clone();
assert_eq!(a, b);
let c = CursorConfig::new();
assert_ne!(a, c);
}
#[test]
fn test_debug_format_mentions_field() {
let config = CursorConfig::read_uncommitted();
let debug = format!("{:?}", config);
assert!(debug.contains("read_uncommitted"));
}
}