diff --git a/Cargo.toml b/Cargo.toml index ab560fe..ad2d8c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,3 +26,4 @@ members = [ [features] suite = [] # test suite suite_bench = [] # bench test suite +deterministic = [] # for stable fuzzing diff --git a/src/lib.rs b/src/lib.rs index 37001dd..ed46d78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -322,6 +322,16 @@ impl OrderedListStyle { } } +#[cfg(not(feature = "deterministic"))] +type Map = std::collections::HashMap; +#[cfg(feature = "deterministic")] +type Map = std::collections::BTreeMap; + +#[cfg(not(feature = "deterministic"))] +type Set = std::collections::HashSet; +#[cfg(feature = "deterministic")] +type Set = std::collections::BTreeSet; + pub struct Parser<'s> { src: &'s str, @@ -340,7 +350,7 @@ pub struct Parser<'s> { /// Footnote references in the order they were encountered, without duplicates. footnote_references: Vec<&'s str>, /// Cache of footnotes to emit at the end. - footnotes: std::collections::HashMap<&'s str, block::Tree>, + footnotes: Map<&'s str, block::Tree>, /// Next or current footnote being parsed and emitted. footnote_index: usize, /// Currently within a footnote. @@ -364,7 +374,7 @@ struct Heading { /// Because of potential future references, an initial pass is required to obtain all definitions. struct PrePass<'s> { /// Link definitions and their attributes. - link_definitions: std::collections::HashMap<&'s str, (CowStr<'s>, attr::Attributes<'s>)>, + link_definitions: Map<&'s str, (CowStr<'s>, attr::Attributes<'s>)>, /// Cache of all heading ids. headings: Vec, /// Indices to headings sorted lexicographically. @@ -374,9 +384,9 @@ struct PrePass<'s> { impl<'s> PrePass<'s> { #[must_use] fn new(src: &'s str, mut tree: block::Tree) -> Self { - let mut link_definitions = std::collections::HashMap::new(); + let mut link_definitions = Map::new(); let mut headings: Vec = Vec::new(); - let mut used_ids: std::collections::HashSet<&str> = std::collections::HashSet::new(); + let mut used_ids: Set<&str> = Set::new(); let mut inlines = span::InlineSpans::new(src); @@ -520,7 +530,7 @@ impl<'s> Parser<'s> { block_attributes: Attributes::new(), table_head_row: false, footnote_references: Vec::new(), - footnotes: std::collections::HashMap::new(), + footnotes: Map::new(), footnote_index: 0, footnote_active: false, inlines: span::InlineSpans::new(src), diff --git a/tests/afl/Cargo.toml b/tests/afl/Cargo.toml index 91530e3..adf9924 100644 --- a/tests/afl/Cargo.toml +++ b/tests/afl/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] afl = "0.11" -jotdown = { path = "../../" } +jotdown = { path = "../../", features = ["deterministic"] } [[bin]] name = "gen"