Skip to content
Myr

Preserve backticks in Markdown command names

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Eric Soler · committed by David Peter · parent a6c3010 · Browse files · 2 files+41 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+41 added−1 removed

  • tests:+12 added−0 removed
  • other:+29 added−1 removed

2 files+41 added−1 removed

modified:src/export/markdown.rs+29 added-1 removed
22 unmodified lines
23 )24 }2526 fn command(&self, cmd: &str) -> String {27 let longest_backtick_run = cmd28 .split(|character| character != '`')29 .map(str::len)30 .max()31 .unwrap_or(0);3233 if longest_backtick_run == 0 {27 format!("`{cmd}`")34 format!("`{cmd}`")35 } else {36 // Use a longer delimiter and keep command backticks separate from it.37 let delimiter = "`".repeat(longest_backtick_run + 1);38 format!("{delimiter} {cmd} {delimiter}")39 }40 }41}4243/// Check Markdown-based data row formatting
11 unmodified lines
5556 let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);57 assert_eq!(divider, "|:---|---:|:---|\n");58}5960#[test]61fn test_markdown_formatter_command_with_backticks() {62 let formatter = MarkdownExporter::default();6364 for (command, expected) in [65 ("echo `uname`", "`` echo `uname` ``"),66 ("echo ``quoted``", "``` echo ``quoted`` ```"),67 ("`` `quoted` ``", "``` `` `quoted` `` ```"),68 ("`", "`` ` ``"),69 ("echo ```", "```` echo ``` ````"),70 (" echo `uname` ", "`` echo `uname` ``"),71 ] {72 assert_eq!(formatter.command(command), expected, "{command:?}");73 }74}
modified:tests/integration_tests.rs+12 added
928 unmodified lines
929 }930}931932#[test]933fn markdown_export_preserves_backticks_and_pipes_in_command_names() {934 hyperfine_debug()935 .arg("--style=none")936 .arg("--export-markdown=-")937 .arg("--command-name=echo `uname` | cat")938 .arg("sleep 1")939 .assert()940 .success()941 .stdout(predicate::str::contains("| `` echo `uname` \\| cat `` |"));942}943944#[test]945fn unused_parameters_are_shown_in_benchmark_name() {946 hyperfine()947 .arg("--runs=2")948 .arg("--parameter-list")
82 unmodified lines