Skip to content

Commit 08bd44c

Browse files
author
Marek Suchánek
committed
Add tests for snippet files; #13
1 parent 77ef8c5 commit 08bd44c

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Minimal snippet
2+
3+
4+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
////
2+
Base the file name on the snippet title. For example:
3+
* file name: snip-my-snippet-a.adoc
4+
* Title: .My snippet A
5+
6+
A snippet is not a module. Consider storing snippet files in a separate snippets folder.
7+
8+
Indicate the content type in one of the following ways:
9+
Add the prefix snip- or snip_ to the file name.
10+
Add the following attribute before the title:
11+
:_content-type: SNIPPET
12+
////
13+
14+
.Some notes in a snippet file
15+
////
16+
The title is optional in a snippet. Use the block title syntax, such as .My snippet A, rather than a numbered heading, such as = My snippet A.
17+
18+
In the title of snippets, include nouns or noun phrases that are used in the body text. This helps readers and search engines find the information quickly. Do not start the title of snippets with a verb. See also _Wording of headings_ in _The IBM Style Guide_.
19+
20+
Do not specify an ID for the snippet title.
21+
////
22+
23+
A text snippet is a small fragment of text that is stored in an AsciiDoc file. Text snippets contain content that is reused in multiple modules or assemblies, for example:
24+
25+
* A step or series of steps in a procedure
26+
* A disclaimer, for example, for technology preview or beta releases
27+
28+
[NOTE]
29+
--
30+
Additional guidance or advice that improves product configuration, performance, or supportability.
31+
--
32+
33+
[IMPORTANT]
34+
--
35+
Advisory information essential to the completion of a task. Users must not disregard this information.
36+
--
37+
38+
[WARNING]
39+
--
40+
Information about potential system damage, data loss, or a support-related issue if the user disregards this admonition. Explain the problem, cause, and offer a solution that works. If available, offer information to avoid the problem in the future or state where to find more information.
41+
--
42+

src/main.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ fn main() -> Result<()> {
8383
// * It must be generated after the other modules so that it can use their include statements
8484
if let Some(title) = cmdline_args.value_of("include-in") {
8585
// Gather all include statements for the other modules
86-
// TODO: Figure out if this can be done without calling .to_owned on all the Strings
8786
let include_statements: Vec<String> = non_populated
8887
.into_iter()
8988
.map(|module| module.include_statement)
@@ -205,6 +204,20 @@ mod tests {
205204
assert_eq!(reference.text, pre_generated);
206205
}
207206

207+
/// Test that we generate the snippet file that we expect.
208+
#[test]
209+
fn test_snippet_file() {
210+
let mod_type = ModuleType::Snippet;
211+
let mod_title = "Some notes in a snippet file";
212+
let options = basic_options();
213+
let snippet = Module::new(mod_type, mod_title, &options);
214+
215+
let pre_generated =
216+
include_str!("../data/generated/snip_some-notes-in-a-snippet-file.adoc");
217+
218+
assert_eq!(snippet.text, pre_generated);
219+
}
220+
208221
// These values strip down the modules to the bare minimum.
209222
fn minimal_options() -> Options {
210223
Options {
@@ -267,4 +280,17 @@ mod tests {
267280

268281
assert_eq!(reference.text, pre_generated);
269282
}
283+
284+
/// Test that we generate the snippet file that we expect.
285+
#[test]
286+
fn test_minimal_snippet() {
287+
let mod_type = ModuleType::Snippet;
288+
let mod_title = "Minimal snippet";
289+
let options = minimal_options();
290+
let snippet = Module::new(mod_type, mod_title, &options);
291+
292+
let pre_generated = include_str!("../data/generated/minimal-snippet.adoc");
293+
294+
assert_eq!(snippet.text, pre_generated);
295+
}
270296
}

0 commit comments

Comments
 (0)