#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct MySqlModeFlags {
pub pipes_as_concat: bool,
pub ansi_quotes: bool,
pub strict_mode: bool,
pub sqlite_division_semantics: bool,
}
impl MySqlModeFlags {
pub fn new() -> Self {
Self::default()
}
pub fn with_pipes_as_concat() -> Self {
Self { pipes_as_concat: true, ..Default::default() }
}
pub fn with_ansi_quotes() -> Self {
Self { ansi_quotes: true, ..Default::default() }
}
pub fn with_strict_mode() -> Self {
Self { strict_mode: true, ..Default::default() }
}
pub fn ansi() -> Self {
Self { pipes_as_concat: true, ansi_quotes: true, ..Default::default() }
}
pub fn with_sqlite_division_semantics() -> Self {
Self { sqlite_division_semantics: true, ..Default::default() }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_mysql_flags() {
let flags = MySqlModeFlags::default();
assert!(!flags.pipes_as_concat); assert!(!flags.ansi_quotes); assert!(!flags.strict_mode); }
#[test]
fn test_new_equals_default() {
assert_eq!(MySqlModeFlags::new(), MySqlModeFlags::default());
}
#[test]
fn test_with_pipes_as_concat() {
let flags = MySqlModeFlags::with_pipes_as_concat();
assert!(flags.pipes_as_concat);
assert!(!flags.ansi_quotes);
assert!(!flags.strict_mode);
}
#[test]
fn test_with_ansi_quotes() {
let flags = MySqlModeFlags::with_ansi_quotes();
assert!(!flags.pipes_as_concat);
assert!(flags.ansi_quotes);
assert!(!flags.strict_mode);
}
#[test]
fn test_with_strict_mode() {
let flags = MySqlModeFlags::with_strict_mode();
assert!(!flags.pipes_as_concat);
assert!(!flags.ansi_quotes);
assert!(flags.strict_mode);
}
#[test]
fn test_ansi_mode() {
let flags = MySqlModeFlags::ansi();
assert!(flags.pipes_as_concat);
assert!(flags.ansi_quotes);
assert!(!flags.strict_mode);
}
#[test]
fn test_flag_combinations() {
let flags = MySqlModeFlags {
pipes_as_concat: true,
ansi_quotes: true,
strict_mode: true,
sqlite_division_semantics: false,
};
assert!(flags.pipes_as_concat);
assert!(flags.ansi_quotes);
assert!(flags.strict_mode);
assert!(!flags.sqlite_division_semantics);
}
#[test]
fn test_with_sqlite_division_semantics() {
let flags = MySqlModeFlags::with_sqlite_division_semantics();
assert!(!flags.pipes_as_concat);
assert!(!flags.ansi_quotes);
assert!(!flags.strict_mode);
assert!(flags.sqlite_division_semantics);
}
}