Skip to content
Myr

table_line => table_divider

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

authored by David Peter · committed by David Peter · parent 5cd2821 · Browse files · 2 files+36 added−20 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+36 added−20 removed

  • other:+36 added−20 removed

2 files+36 added−20 removed

modified:src/export/markdown.rs+19 added-12 removed
1use crate::export::markup::MarkupExporter;23use super::markup::Alignment;45#[derive(Default)]6pub struct MarkdownExporter {}78impl MarkupExporter for MarkdownExporter {7 fn table_row(&self, data: &[&str]) -> String {8 format!("| {} |\n", data.join(" | "))9 fn table_row(&self, cells: &[&str]) -> String {10 format!("| {} |\n", cells.join(" | "))11 }1211 fn table_line(&self, size: usize) -> String {12 format!("|:---|{}\n", "---:|".repeat(size - 1))13 fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {14 format!(15 "|{}\n",16 cell_aligmnents17 .iter()18 .map(|a| match a {19 Alignment::Left => ":---|",20 Alignment::Right => "---:|",21 })22 .collect::<String>()23 )24 }2526 fn command(&self, cmd: &str) -> String {27 format!("`{}`", cmd)
4 unmodified lines
32#[test]33fn test_markdown_formatter_table_data() {34 let formatter = MarkdownExporter::default();3525 let actual = formatter.table_row(&["a", "b", "c"]);26 let expect = "| a | b | c |\n";2728 assert_eq!(expect, actual);36 assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");37}3839/// Check Markdown-based horizontal line formatting40#[test]33fn test_markdown_formatter_table_line() {41fn test_markdown_formatter_table_divider() {42 let formatter = MarkdownExporter::default();35 let size = 5;4337 let actual = formatter.table_line(size);38 let expect = "|:---|---:|---:|---:|---:|\n";44 let actual = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);45 let expect = "|:---|---:|:---|\n";4647 assert_eq!(expect, actual);48}49
224 unmodified lines
modified:src/export/markup.rs+17 added-8 removed
4 unmodified lines
56use super::Exporter;7use anyhow::{anyhow, Result};89pub enum Alignment {10 Left,11 Right,12}13pub trait MarkupExporter {14 fn table_results(&self, entries: &[BenchmarkResultWithRelativeSpeed], unit: Unit) -> String {15 // prepare table header strings16 let notation = format!("[{}]", unit.short_name());13 let head: [&str; 5] = [1718 // emit header19 let mut table = self.table_row(&[20 "Command",21 &format!("Mean {}", notation),22 &format!("Min {}", notation),23 &format!("Max {}", notation),24 "Relative",19 ];25 ]);2621 // emit header22 let mut table = self.table_row(&head);2327 // emit horizontal line25 table.push_str(&self.table_line(head.len()));28 table.push_str(&self.table_divider(&[29 Alignment::Left,30 Alignment::Right,31 Alignment::Right,32 Alignment::Right,33 Alignment::Right,34 ]));3536 for entry in entries {37 let measurement = &entry.result;38 // prepare data row strings
27 unmodified lines
6667 table68 }6961 fn table_row(&self, data: &[&str]) -> String;70 fn table_row(&self, cells: &[&str]) -> String;7163 fn table_line(&self, size: usize) -> String;72 fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String;7374 fn command(&self, size: &str) -> String;75}76
196 unmodified lines