mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-28 08:08:58 +00:00
Preserve backticks in Markdown command names
This commit is contained in:
1 parent
a6c301099b
commit
a760e75f2f
2 files changed
+41
-1
No files matched your search
+29
-1
@@ -24,7 +24,19 @@ impl MarkupExporter for MarkdownExporter {
|
||||
}
|
||||
|
||||
fn command(&self, cmd: &str) -> String {
|
||||
format!("`{cmd}`")
|
||||
let longest_backtick_run = cmd
|
||||
.split(|character| character != '`')
|
||||
.map(str::len)
|
||||
.max()
|
||||
.unwrap_or(0);
|
||||
|
||||
if longest_backtick_run == 0 {
|
||||
format!("`{cmd}`")
|
||||
} else {
|
||||
// Use a longer delimiter and keep command backticks separate from it.
|
||||
let delimiter = "`".repeat(longest_backtick_run + 1);
|
||||
format!("{delimiter} {cmd} {delimiter}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +56,19 @@ fn test_markdown_formatter_table_divider() {
|
||||
let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);
|
||||
assert_eq!(divider, "|:---|---:|:---|\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_markdown_formatter_command_with_backticks() {
|
||||
let formatter = MarkdownExporter::default();
|
||||
|
||||
for (command, expected) in [
|
||||
("echo `uname`", "`` echo `uname` ``"),
|
||||
("echo ``quoted``", "``` echo ``quoted`` ```"),
|
||||
("`` `quoted` ``", "``` `` `quoted` `` ```"),
|
||||
("`", "`` ` ``"),
|
||||
("echo ```", "```` echo ``` ````"),
|
||||
(" echo `uname` ", "`` echo `uname` ``"),
|
||||
] {
|
||||
assert_eq!(formatter.command(command), expected, "{command:?}");
|
||||
}
|
||||
}
|
||||
@@ -929,6 +929,18 @@ fn invalid_command_options_preserve_export_files() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markdown_export_preserves_backticks_and_pipes_in_command_names() {
|
||||
hyperfine_debug()
|
||||
.arg("--style=none")
|
||||
.arg("--export-markdown=-")
|
||||
.arg("--command-name=echo `uname` | cat")
|
||||
.arg("sleep 1")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("| `` echo `uname` \\| cat `` |"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unused_parameters_are_shown_in_benchmark_name() {
|
||||
hyperfine()
|
||||
|
||||
Reference in new issue
Block a user