use std::time::Duration;
#[derive(Debug, Clone)]
pub struct ReplConfig {
pub max_memory: usize,
pub timeout: Duration,
pub maxdepth: usize,
pub debug: bool,
}
impl Default for ReplConfig {
fn default() -> Self {
Self {
max_memory: 1024 * 1024, timeout: Duration::from_millis(5000), maxdepth: 100,
debug: false,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_repl_default_config() {
let config = ReplConfig::default();
assert_eq!(config.max_memory, 1024 * 1024);
assert_eq!(config.timeout, Duration::from_millis(5000));
assert_eq!(config.maxdepth, 100);
assert!(!config.debug);
}
#[test]
fn test_repl_config_clone() {
let config = ReplConfig {
max_memory: 2048,
timeout: Duration::from_secs(10),
maxdepth: 50,
debug: true,
};
let cloned = config.clone();
assert_eq!(cloned.max_memory, 2048);
assert_eq!(cloned.timeout, Duration::from_secs(10));
assert_eq!(cloned.maxdepth, 50);
assert!(cloned.debug);
}
#[test]
fn test_repl_config_debug_trait() {
let config = ReplConfig::default();
let debug_str = format!("{:?}", config);
assert!(debug_str.contains("ReplConfig"));
assert!(debug_str.contains("max_memory"));
assert!(debug_str.contains("timeout"));
assert!(debug_str.contains("maxdepth"));
assert!(debug_str.contains("debug"));
}
#[test]
fn test_repl_config_custom_max_memory() {
let config = ReplConfig {
max_memory: 512 * 1024, ..Default::default()
};
assert_eq!(config.max_memory, 512 * 1024);
assert_eq!(config.timeout, Duration::from_millis(5000));
assert_eq!(config.maxdepth, 100);
assert!(!config.debug);
}
#[test]
fn test_repl_config_custom_timeout() {
let config = ReplConfig {
timeout: Duration::from_secs(30),
..Default::default()
};
assert_eq!(config.timeout, Duration::from_secs(30));
assert_eq!(config.max_memory, 1024 * 1024);
assert_eq!(config.maxdepth, 100);
assert!(!config.debug);
}
#[test]
fn test_repl_config_custom_maxdepth() {
let config = ReplConfig {
maxdepth: 200,
..Default::default()
};
assert_eq!(config.maxdepth, 200);
assert_eq!(config.max_memory, 1024 * 1024);
assert_eq!(config.timeout, Duration::from_millis(5000));
assert!(!config.debug);
}
#[test]
fn test_repl_config_debug_enabled() {
let config = ReplConfig {
debug: true,
..Default::default()
};
assert!(config.debug);
assert_eq!(config.max_memory, 1024 * 1024);
assert_eq!(config.timeout, Duration::from_millis(5000));
assert_eq!(config.maxdepth, 100);
}
#[test]
fn test_repl_config_sandbox_settings() {
let config = ReplConfig {
max_memory: 256 * 1024, timeout: Duration::from_millis(500), maxdepth: 25, debug: false,
};
assert_eq!(config.max_memory, 256 * 1024);
assert_eq!(config.timeout, Duration::from_millis(500));
assert_eq!(config.maxdepth, 25);
assert!(!config.debug);
}
#[test]
fn test_repl_config_production_settings() {
let config = ReplConfig {
max_memory: 10 * 1024 * 1024, timeout: Duration::from_secs(60), maxdepth: 500, debug: false,
};
assert_eq!(config.max_memory, 10 * 1024 * 1024);
assert_eq!(config.timeout, Duration::from_secs(60));
assert_eq!(config.maxdepth, 500);
assert!(!config.debug);
}
#[test]
fn test_repl_config_debug_development_settings() {
let config = ReplConfig {
max_memory: 2 * 1024 * 1024, timeout: Duration::from_secs(120), maxdepth: 100,
debug: true,
};
assert_eq!(config.max_memory, 2 * 1024 * 1024);
assert_eq!(config.timeout, Duration::from_secs(120));
assert_eq!(config.maxdepth, 100);
assert!(config.debug);
}
#[test]
fn test_repl_config_timeout_zero() {
let config = ReplConfig {
timeout: Duration::ZERO,
..Default::default()
};
assert_eq!(config.timeout, Duration::ZERO);
}
#[test]
fn test_repl_config_maxdepth_zero() {
let config = ReplConfig {
maxdepth: 0,
..Default::default()
};
assert_eq!(config.maxdepth, 0);
}
#[test]
fn test_repl_config_max_memory_zero() {
let config = ReplConfig {
max_memory: 0,
..Default::default()
};
assert_eq!(config.max_memory, 0);
}
#[test]
fn test_repl_config_default_values_are_reasonable() {
let config = ReplConfig::default();
assert!(config.max_memory >= 1024 * 1024);
assert!(config.timeout >= Duration::from_millis(1000));
assert!(config.maxdepth >= 50);
assert!(!config.debug);
}
#[test]
fn test_repl_config_clone_independence() {
let mut config = ReplConfig::default();
let cloned = config.clone();
config.max_memory = 999;
config.debug = true;
assert_eq!(cloned.max_memory, 1024 * 1024);
assert!(!cloned.debug);
assert_eq!(config.max_memory, 999);
assert!(config.debug);
}
#[test]
fn test_repl_config_timeout_conversions() {
let config = ReplConfig {
timeout: Duration::from_millis(5000),
..Default::default()
};
assert_eq!(config.timeout.as_secs(), 5);
assert_eq!(config.timeout.as_millis(), 5000);
}
#[test]
fn test_repl_config_large_values() {
let config = ReplConfig {
max_memory: usize::MAX,
timeout: Duration::MAX,
maxdepth: usize::MAX,
debug: true,
};
assert_eq!(config.max_memory, usize::MAX);
assert_eq!(config.timeout, Duration::MAX);
assert_eq!(config.maxdepth, usize::MAX);
}
}