use nom::{
branch::alt,
bytes::complete::tag,
combinator::{into, map, opt, value},
sequence::preceded,
Parser,
};
use crate::{
input::Input,
intermediate::{ASN1Type, ASN1Value, BOOLEAN, FALSE, TRUE},
};
use super::{common::skip_ws_and_comments, constraint::constraints, error::ParserResult};
pub fn boolean_value(input: Input<'_>) -> ParserResult<'_, ASN1Value> {
alt((
value(ASN1Value::Boolean(true), skip_ws_and_comments(tag(TRUE))),
value(ASN1Value::Boolean(false), skip_ws_and_comments(tag(FALSE))),
))
.parse(input)
}
pub fn boolean(input: Input<'_>) -> ParserResult<'_, ASN1Type> {
map(
into(skip_ws_and_comments(preceded(
tag(BOOLEAN),
skip_ws_and_comments(opt(constraints)),
))),
ASN1Type::Boolean,
)
.parse(input)
}
#[cfg(test)]
mod tests {
use crate::intermediate::types::Boolean;
use super::*;
#[test]
fn parses_boolean() {
assert_eq!(
boolean(" --who would put a comment here?--BOOLEAN".into())
.unwrap()
.1,
ASN1Type::Boolean(Boolean {
constraints: vec![]
})
)
}
}