Skip to content

Commit

Permalink
parser: mark all other options structs (except top-level) nonexhaustive
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Jun 17, 2023
1 parent a14b0b6 commit 4ddd159
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 123 deletions.
59 changes: 29 additions & 30 deletions fuzz/fuzz_targets/all_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,36 @@ use comrak::{
};

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;
extension.tasklist = true;
extension.superscript = true;
extension.header_ids = Some("user-content-".to_string());
extension.footnotes = true;
extension.description_lists = true;
extension.front_matter_delimiter = Some("---".to_string());
extension.shortcodes = true;

let mut parse = ParseOptions::default();
parse.smart = true;
parse.default_info_string = Some("rust".to_string());
parse.relaxed_tasklist_matching = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.full_info_string = true;
render.width = 80;
render.unsafe_ = true;
render.escape = true;
render.list_style = ListStyleType::Star;
render.sourcepos = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
tasklist: true,
superscript: true,
header_ids: Some("user-content-".to_string()),
footnotes: true,
description_lists: true,
front_matter_delimiter: Some("---".to_string()),
shortcodes: true,
},
parse: ParseOptions {
smart: true,
default_info_string: Some("rust".to_string()),
relaxed_tasklist_matching: true,
},
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
full_info_string: true,
width: 80,
unsafe_: true,
escape: true,
list_style: ListStyleType::Star,
sourcepos: true,
},
},
&Options { extension, parse, render },
);
});
10 changes: 3 additions & 7 deletions fuzz/fuzz_targets/cli_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ use libfuzzer_sys::fuzz_target;

use comrak::{
markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, Plugins,
RenderPlugins,
};

// Note that we end up fuzzing Syntect here.

fuzz_target!(|s: &str| {
let adapter = SyntectAdapter::new("base16-ocean.dark");
let plugins = Plugins {
render: RenderPlugins {
codefence_syntax_highlighter: Some(&adapter),
..Default::default()
},
};

let mut plugins = Plugins::default();
plugins.render.codefence_syntax_highlighter = Some(&adapter);

markdown_to_html_with_plugins(s, &Default::default(), &plugins);
});
26 changes: 13 additions & 13 deletions fuzz/fuzz_targets/gfm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
// options are routinely used by Commonmarker users.

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.unsafe_ = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
..Default::default()
},
extension,
parse: Default::default(),
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
..Default::default()
},
render,
},
);
});
28 changes: 14 additions & 14 deletions fuzz/fuzz_targets/gfm_footnotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
// options are routinely used by Commonmarker users.

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;
extension.footnotes = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.unsafe_ = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
footnotes: true,
..Default::default()
},
extension,
parse: Default::default(),
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
..Default::default()
},
render,
},
);
});
28 changes: 14 additions & 14 deletions fuzz/fuzz_targets/gfm_sourcepos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
// options are routinely used by Commonmarker users.

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.unsafe_ = true;
render.sourcepos = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
..Default::default()
},
extension,
parse: Default::default(),
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
sourcepos: true,
..Default::default()
},
render,
},
);
});
56 changes: 28 additions & 28 deletions fuzz/fuzz_targets/quadratic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,19 @@ struct FuzzExtensionOptions {

impl FuzzExtensionOptions {
fn to_options(&self) -> ExtensionOptions {
ExtensionOptions {
strikethrough: self.strikethrough,
tagfilter: self.tagfilter,
table: self.table,
autolink: self.autolink,
tasklist: self.tasklist,
superscript: self.superscript,
footnotes: self.footnotes,
description_lists: self.description_lists,
shortcodes: self.shortcodes,
front_matter_delimiter: None,
header_ids: None,
}
let mut extension = ExtensionOptions::default();
extension.strikethrough = self.strikethrough;
extension.tagfilter = self.tagfilter;
extension.table = self.table;
extension.autolink = self.autolink;
extension.tasklist = self.tasklist;
extension.superscript = self.superscript;
extension.footnotes = self.footnotes;
extension.description_lists = self.description_lists;
extension.shortcodes = self.shortcodes;
extension.front_matter_delimiter = None;
extension.header_ids = None;
extension
}
}

Expand All @@ -220,11 +220,11 @@ struct FuzzParseOptions {

impl FuzzParseOptions {
fn to_options(&self) -> ParseOptions {
ParseOptions {
smart: self.smart,
default_info_string: None,
relaxed_tasklist_matching: self.relaxed_tasklist_matching,
}
let mut parse = ParseOptions::default();
parse.smart = self.smart;
parse.default_info_string = None;
parse.relaxed_tasklist_matching = self.relaxed_tasklist_matching;
parse
}
}

Expand All @@ -242,16 +242,16 @@ struct FuzzRenderOptions {

impl FuzzRenderOptions {
fn to_options(&self) -> RenderOptions {
RenderOptions {
hardbreaks: self.hardbreaks,
github_pre_lang: self.github_pre_lang,
full_info_string: self.full_info_string,
width: self.width,
unsafe_: self.unsafe_,
escape: self.escape,
list_style: self.list_style,
sourcepos: self.sourcepos,
}
let mut render = RenderOptions::default();
render.hardbreaks = self.hardbreaks;
render.github_pre_lang = self.github_pre_lang;
render.full_info_string = self.full_info_string;
render.width = self.width;
render.unsafe_ = self.unsafe_;
render.escape = self.escape;
render.list_style = self.list_style;
render.sourcepos = self.sourcepos;
render
}
}

Expand Down
32 changes: 17 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,25 @@ fn main() -> Result<(), Box<dyn Error>> {
extension.shortcodes = cli.gemojis;
}

let mut parse = ParseOptions::default();
parse.smart = cli.smart;
parse.default_info_string = cli.default_info_string;
parse.relaxed_tasklist_matching = cli.relaxed_tasklist_character;

let mut render = RenderOptions::default();
render.hardbreaks = cli.hardbreaks;
render.github_pre_lang = cli.github_pre_lang || cli.gfm;
render.full_info_string = cli.full_info_string;
render.width = cli.width;
render.unsafe_ = cli.unsafe_;
render.escape = cli.escape;
render.list_style = cli.list_style.into();
render.sourcepos = cli.sourcepos;

let options = Options {
extension,
parse: ParseOptions {
smart: cli.smart,
default_info_string: cli.default_info_string,
relaxed_tasklist_matching: cli.relaxed_tasklist_character,
},
render: RenderOptions {
hardbreaks: cli.hardbreaks,
github_pre_lang: cli.github_pre_lang || cli.gfm,
full_info_string: cli.full_info_string,
width: cli.width,
unsafe_: cli.unsafe_,
escape: cli.escape,
list_style: cli.list_style.into(),
sourcepos: cli.sourcepos,
},
parse,
render,
};

let syntax_highlighter: Option<&dyn SyntaxHighlighterAdapter>;
Expand Down
6 changes: 4 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ pub struct Options {
pub render: RenderOptions,
}

// NOTE: The shortcodes feature adds a new field, so mark this as non-exhaustive since it's part of
// the public API
#[non_exhaustive]
#[derive(Default, Debug, Clone)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
Expand Down Expand Up @@ -348,6 +346,7 @@ pub struct ExtensionOptions {
pub shortcodes: bool,
}

#[non_exhaustive]
#[derive(Default, Debug, Clone)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
/// Options for parser functions.
Expand Down Expand Up @@ -384,6 +383,7 @@ pub struct ParseOptions {
pub relaxed_tasklist_matching: bool,
}

#[non_exhaustive]
#[derive(Default, Debug, Clone, Copy)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
/// Options for formatter functions.
Expand Down Expand Up @@ -532,13 +532,15 @@ pub struct RenderOptions {
pub sourcepos: bool,
}

#[non_exhaustive]
#[derive(Default, Debug)]
/// Umbrella plugins struct.
pub struct Plugins<'p> {
/// Configure render-time plugins.
pub render: RenderPlugins<'p>,
}

#[non_exhaustive]
#[derive(Default)]
/// Plugins for alternative rendering.
pub struct RenderPlugins<'p> {
Expand Down

0 comments on commit 4ddd159

Please sign in to comment.