Files
hyperfine/src/export/markdown.rs
T

46 lines
1.2 KiB
Rust
Raw Normal View History

2022-05-15 21:09:33 +02:00
use crate::export::markup::MarkupExporter;
2022-02-06 17:44:28 +01:00
2022-05-15 21:28:35 +02:00
use super::markup::Alignment;
#[derive(Default)]
2022-05-15 21:09:33 +02:00
pub struct MarkdownExporter {}
2022-05-15 21:09:33 +02:00
impl MarkupExporter for MarkdownExporter {
2022-05-15 21:28:35 +02:00
fn table_row(&self, cells: &[&str]) -> String {
format!("| {} |\n", cells.join(" | "))
}
2022-05-15 21:28:35 +02:00
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 {
2024-05-31 13:26:35 -07:00
format!("`{cmd}`")
}
}
/// Check Markdown-based data row formatting
#[test]
fn test_markdown_formatter_table_data() {
2022-05-15 21:09:33 +02:00
let formatter = MarkdownExporter::default();
2022-05-15 21:28:35 +02:00
assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");
}
/// Check Markdown-based horizontal line formatting
#[test]
2022-05-15 21:28:35 +02:00
fn test_markdown_formatter_table_divider() {
2022-05-15 21:09:33 +02:00
let formatter = MarkdownExporter::default();
2022-05-15 21:29:36 +02:00
let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);
assert_eq!(divider, "|:---|---:|:---|\n");
}