mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-12 02:22:35 +00:00
47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
use crate::export::markup::MarkupExporter;
|
|
|
|
use super::markup::Alignment;
|
|
|
|
#[derive(Default)]
|
|
pub struct MarkdownExporter {}
|
|
|
|
impl MarkupExporter for MarkdownExporter {
|
|
fn table_row(&self, cells: &[&str]) -> String {
|
|
format!("| {} |\n", cells.join(" | "))
|
|
}
|
|
|
|
fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {
|
|
format!(
|
|
"|{}\n",
|
|
cell_aligmnents
|
|
.iter()
|
|
.map(|a| match a {
|
|
Alignment::Left => ":---|",
|
|
Alignment::Right => "---:|",
|
|
})
|
|
.collect::<String>()
|
|
)
|
|
}
|
|
|
|
fn command(&self, cmd: &str) -> String {
|
|
format!("`{cmd}`")
|
|
}
|
|
}
|
|
|
|
/// Check Markdown-based data row formatting
|
|
#[test]
|
|
fn test_markdown_formatter_table_data() {
|
|
let formatter = MarkdownExporter::default();
|
|
|
|
assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");
|
|
}
|
|
|
|
/// Check Markdown-based horizontal line formatting
|
|
#[test]
|
|
fn test_markdown_formatter_table_divider() {
|
|
let formatter = MarkdownExporter::default();
|
|
|
|
let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);
|
|
assert_eq!(divider, "|:---|---:|:---|\n");
|
|
}
|