mod ast;
mod lexer;
mod parser;
pub use ast::{
DeallocateTarget, DiscardTarget, ResetTarget, SetScope, SetValue, Statement,
TransactionOptions, UnlistenTarget,
};
pub use parser::parse;
pub fn as_boolean(val: &str) -> Option<bool> {
match val {
"t" | "tr" | "tru" | "true" | "y" | "ye" | "yes" | "on" | "1" => Some(true),
"f" | "fa" | "fal" | "fals" | "false" | "n" | "no" | "of" | "off" | "0" => Some(false),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn boolean_true_values() {
for s in ["t", "tr", "tru", "true", "y", "ye", "yes", "on", "1"] {
assert_eq!(as_boolean(s), Some(true), "{s:?} should be true");
}
}
#[test]
fn boolean_false_values() {
for s in [
"f", "fa", "fal", "fals", "false", "n", "no", "of", "off", "0",
] {
assert_eq!(as_boolean(s), Some(false), "{s:?} should be false");
}
}
#[test]
fn bare_o_is_ambiguous() {
assert_eq!(as_boolean("o"), None);
}
#[test]
fn invalid_boolean_rejected() {
for s in [
"", "maybe", "2", "256mb", "truth", "nope", "yep", "11", "10",
] {
assert_eq!(as_boolean(s), None, "{s:?} should not parse");
}
}
}