Skip to content

Commit acd7ff7

Browse files
author
Marek Suchánek
committed
Tests for file name and anchor prefixes; #21
1 parent e17848c commit acd7ff7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/module.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,29 @@ impl Input {
195195
///
196196
/// The file name is based on the module ID,
197197
/// with an optional prefix and the `.adoc` extension.
198+
///
199+
/// # Examples
200+
///
201+
/// ```
202+
/// use newdoc::{ContentType, Input, Options};
203+
///
204+
/// let mod_type = ContentType::Concept;
205+
/// let title = "Default file name configuration";
206+
/// let options = Options::default();
207+
/// let input = Input::new(mod_type, title, &options);
208+
///
209+
/// assert_eq!("con_default-file-name-configuration.adoc", input.file_name());
210+
///
211+
/// let mod_type = ContentType::Concept;
212+
/// let title = "No prefix file name configuration";
213+
/// let options = Options {
214+
/// file_prefixes: false,
215+
/// ..Default::default()
216+
/// };
217+
/// let input = Input::new(mod_type, title, &options);
218+
///
219+
/// assert_eq!("no-prefix-file-name-configuration.adoc", input.file_name());
220+
/// ```
198221
#[must_use]
199222
pub fn file_name(&self) -> String {
200223
// Add a prefix only if they're enabled.
@@ -214,6 +237,28 @@ impl Input {
214237
/// Prepare the AsciiDoc anchor or ID.
215238
///
216239
/// The anchor is based on the module ID, with an optional prefix.
240+
///
241+
/// # Examples
242+
///
243+
/// ```
244+
/// use newdoc::{ContentType, Input, Options};
245+
///
246+
/// let mod_type = ContentType::Concept;
247+
/// let title = "Default anchor configuration";
248+
/// let options = Options::default();
249+
/// let input = Input::new(mod_type, title, &options);
250+
///
251+
/// assert_eq!("default-anchor-configuration", input.anchor());
252+
///
253+
/// let mod_type = ContentType::Concept;
254+
/// let title = "Prefix anchor configuration";
255+
/// let options = Options {
256+
/// anchor_prefixes: true,
257+
/// ..Default::default()
258+
/// };
259+
/// let input = Input::new(mod_type, title, &options);
260+
///
261+
/// assert_eq!("con_prefix-anchor-configuration", input.anchor());
217262
#[must_use]
218263
pub fn anchor(&self) -> String {
219264
// Add a prefix only if they're enabled.

0 commit comments

Comments
 (0)