pub fn quote(s: &str) -> String {
format!("'{}'", s.replace("'", "''"))
}
pub fn quote_identifier(s: &str) -> String {
format!("\"{}\"", s.replace("\"", "\"\""))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_quote_simple() {
assert_eq!(quote("hello"), "'hello'");
}
#[test]
fn test_quote_with_single_quote() {
assert_eq!(quote("O'Reilly"), "'O''Reilly'");
}
#[test]
fn test_quote_empty() {
assert_eq!(quote(""), "''");
}
#[test]
fn test_quote_identifier() {
assert_eq!(quote_identifier("users"), "\"users\"");
assert_eq!(quote_identifier("user\"name"), "\"user\"\"name\"");
}
#[test]
fn test_quote_multiple_single_quotes() {
assert_eq!(quote("it's a it's"), "'it''s a it''s'");
}
#[test]
fn test_quote_only_single_quote() {
assert_eq!(quote("'"), "''''");
}
#[test]
fn test_quote_identifier_empty() {
assert_eq!(quote_identifier(""), "\"\"");
}
#[test]
fn test_quote_identifier_multiple_double_quotes() {
assert_eq!(quote_identifier("a\"b\"c"), "\"a\"\"b\"\"c\"");
}
#[test]
fn test_quote_with_special_characters() {
assert_eq!(quote("hello\nworld"), "'hello\nworld'");
}
}