use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CitationsConfig {
pub enabled: bool,
}
impl CitationsConfig {
pub fn new(enabled: bool) -> Self {
Self { enabled }
}
pub fn enabled() -> Self {
Self::new(true)
}
pub fn disabled() -> Self {
Self::new(false)
}
}
impl Default for CitationsConfig {
fn default() -> Self {
Self::disabled()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serialization_enabled() {
let config = CitationsConfig::enabled();
let json = serde_json::to_value(&config).unwrap();
assert_eq!(json, serde_json::json!({"enabled": true}));
}
#[test]
fn serialization_disabled() {
let config = CitationsConfig::disabled();
let json = serde_json::to_value(&config).unwrap();
assert_eq!(json, serde_json::json!({"enabled": false}));
}
#[test]
fn deserialization() {
let json = serde_json::json!({"enabled": true});
let config: CitationsConfig = serde_json::from_value(json).unwrap();
assert!(config.enabled);
let json = serde_json::json!({"enabled": false});
let config: CitationsConfig = serde_json::from_value(json).unwrap();
assert!(!config.enabled);
}
}