diff --git a/src/lib.rs b/src/lib.rs index bb3a52c..c4d2e83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,8 +2,11 @@ #![feature(trait_alias)] #![feature(path_file_prefix)] #![feature(is_sorted)] +#![feature(test)] // TODO: #![warn(missing_docs)] +extern crate test; + #[cfg(feature = "compare")] pub mod compare; diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index c78f899..2ff7566 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -250,3 +250,25 @@ fn export_keyword<'s>(input: OrgSource<'s>) -> Res, OrgSource<'s>> take_while1(|c: char| c.is_alphanumeric() || "-_".contains(c)), )))(input) } + +#[cfg(test)] +mod tests { + use test::Bencher; + + use super::*; + use crate::context::Context; + use crate::context::ContextElement; + use crate::context::GlobalSettings; + use crate::context::List; + use crate::parser::OrgSource; + + #[bench] + fn bench_affiliated_keyword(b: &mut Bencher) { + let input = OrgSource::new("#+CAPTION[*foo*]: bar *baz*"); + let global_settings = GlobalSettings::default(); + let initial_context = ContextElement::document_context(); + let initial_context = Context::new(&global_settings, List::new(&initial_context)); + + b.iter(|| assert!(affiliated_keyword(&initial_context, input).is_ok())); + } +}