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
Provenance
- Commit
8c05fd0- Tree
2c70803- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
5cd2821
2 files changed+36 added−20 removed
modified:src/export/markdown.rs+19 added-12 removed
1 use crate::export::markup::MarkupExporter;2 3+use super::markup::Alignment;4+5 #[derive(Default)]6 pub struct MarkdownExporter {}7 8 impl 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 }12 11- 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 }25 26 fn command(&self, cmd: &str) -> String {27 format!("`{}`", cmd)4 unmodified lines32 #[test]33 fn test_markdown_formatter_table_data() {34 let formatter = MarkdownExporter::default();35 25- let actual = formatter.table_row(&["a", "b", "c"]);26- let expect = "| a | b | c |\n";27-28- assert_eq!(expect, actual);36+ assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");37 }38 39 /// Check Markdown-based horizontal line formatting40 #[test]33-fn test_markdown_formatter_table_line() {41+fn test_markdown_formatter_table_divider() {42 let formatter = MarkdownExporter::default();35- let size = 5;43 37- 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";46 47 assert_eq!(expect, actual);48 }49 224 unmodified linesmodified:src/export/markup.rs+17 added-8 removed
4 unmodified lines5 6 use super::Exporter;7 use anyhow::{anyhow, Result};8 9+pub enum Alignment {10+ Left,11+ Right,12+}13 pub 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] = [17+18+ // 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+ ]);26 21- // emit header22- let mut table = self.table_row(&head);23-27 // 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+ ]));35 36 for entry in entries {37 let measurement = &entry.result;38 // prepare data row strings27 unmodified lines66 67 table68 }69 61- fn table_row(&self, data: &[&str]) -> String;70+ fn table_row(&self, cells: &[&str]) -> String;71 63- fn table_line(&self, size: usize) -> String;72+ fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String;73 74 fn command(&self, size: &str) -> String;75 }76 196 unmodified lines