mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-01 08:50:19 +00:00
Merge pull request #947 from Likio3000/codex/fix-markdown-backticks
Preserve backticks in Markdown command names
This commit is contained in:
2 files changed
+50
-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,27 @@ fn invalid_command_options_preserve_export_files() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn markdown_export_preserves_backticks_and_pipes_in_command_names() {
|
||||
let _settings = snapshot_settings().bind_to_scope();
|
||||
assert_cmd_snapshot!(hyperfine_debug()
|
||||
.arg("--style=none")
|
||||
.arg("--export-markdown=-")
|
||||
.arg("--command-name=echo `uname` | cat")
|
||||
.arg("sleep 1"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|
||||
|:---|---:|---:|---:|---:|
|
||||
| `` echo `uname` \| cat `` | 1.000 ± 0.000 | 1.000 | 1.000 | 1.00 |
|
||||
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unused_parameters_are_shown_in_benchmark_name() {
|
||||
hyperfine()
|
||||
|
||||
Reference in new issue
Block a user