Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Jan 29, 2025
1 parent f89134d commit 4778141
Show file tree
Hide file tree
Showing 10 changed files with 520 additions and 1 deletion.
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ rustversion = "1.0.15"
# Cutting out `filesystem` feature
trycmd = { version = "0.15.3", default-features = false, features = ["color-auto", "diff", "examples"] }
humantime = "2.1.0"
snapbox = "0.6.16"
snapbox = { version = "0.6.16", features = ["term-svg"] }
shlex = "1.3.0"
automod = "1.0.14"
clap-cargo = { version = "0.14.1", default-features = false }
Expand Down
145 changes: 145 additions & 0 deletions tests/derive/markdown.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#![cfg(feature = "derive")]

use clap::CommandFactory;
use clap_derive::Parser;
use snapbox::file;

macro_rules! assert_help {
($Command:ty, $filename:literal) => {{
let help = <$Command>::command().render_long_help().ansi().to_string();
snapbox::assert_data_eq!(help, file![$filename]);
}};
}

#[test]
fn headers() {
/// # This is a header
/// ## second level
/// ### `additional` *styling **on ~top~ of** it*
/// regular paragraph
#[derive(Parser)]
struct Command;

assert_help!(Command, "snapshots/headers.term.svg");
}

#[test]
fn inline_styles() {
/// *emphasis* **bold** ~strike through~ `code`
///
/// *all **of ~them `combined` in~ one** line*
#[derive(Parser)]
struct Command;

assert_help!(Command, "snapshots/inline_styles.term.svg");
}

#[test]
fn links() {
/// <https://example.com/literal>
///
/// [with name](https://example.com/with%20name)
///
/// ![image](https://example.com/image)
///
/// [referencing][reference]
///
/// [reference]: https://example.com/reference
#[derive(Parser)]
struct Command;

assert_help!(Command, "snapshots/links.term.svg");
}

#[test]
fn html() {
/// <html>
/// <is>
/// <used>
/// </verbatim>
/// </html>
///
/// <inline>html</as-well>
#[derive(Parser)]
struct Command;

assert_help!(Command, "snapshots/html.term.svg");
}

#[test]
fn blocks() {
/// ```rust
/// This is a *fenced* code block.
///
/// There is not much going on in terms of **styling**.
/// ```
///
/// ---
///
/// Code blocks can also be initiated through
/// Indentation.
///
/// > This is a block quote.
/// > **Regular ~styling *should* work~ here.**
/// >
/// > # even headings
/// > and regular paragraphs.
/// >
/// > - lists
/// > - are
/// >
/// > 1. also
/// > 1. supported
/// >
/// > > nesting them
/// > > > also works (not)
///
#[derive(Parser)]
struct Command;

assert_help!(Command, "snapshots/blocks.term.svg");
}

#[test]
fn lists() {
/// Lists:
///
/// - unordered
/// - bullet
/// - lists
/// - with multiple
/// - levels
///
/// 0. numeric lists
/// 1. only care
/// 1. about the initial number
/// 2. 5. and count from there
/// 7. anything goes
/// 3. though they need an empty line
#[derive(Parser)]
struct Command;

assert_help!(Command, "snapshots/lists.term.svg");
}

#[test]
fn paragraphs() {
/// Paragraphs are separated by empty lines.
/// All lines will be joined onto one.
///
/// The first paragraph is used as short help by clap.\
/// backslashes can be used to insert hard line breaks.
///
/// | these | can |\
/// | ----- | ----- |\
/// | be | used |\
/// | for | tables|
///
/// Because tables are not yet supported.
///
#[doc = "You can also use trailing spaces for hard breaks, \nbut this is not really recommended."]
#[derive(Parser)]
struct Command;

assert_help!(Command, "snapshots/paragraphs.term.svg");
}
57 changes: 57 additions & 0 deletions tests/derive/snapshots/blocks.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions tests/derive/snapshots/headers.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions tests/derive/snapshots/html.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4778141

Please sign in to comment.