Adapt to new markup exporter changes
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 2443383 · Browse files · 1 file·+26 added−39 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+26 added−39 removed
- other:+26 added−39 removed
Provenance
- Commit
eb0ccc8- Tree
32aba7a- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
2443383
1 file changed+26 added−39 removed
modified:src/export/orgmode.rs+26 added-39 removed
1-use super::Exporter;2-use crate::benchmark::benchmark_result::BenchmarkResult;3-use crate::benchmark::relative_speed;4-use crate::export::markup::MarkupFormatter;5-use crate::util::units::Unit;1+use super::markup::Alignment;2+use crate::export::markup::MarkupExporter;3 7-use anyhow::{anyhow, Result};8-4 #[derive(Default)]10-pub struct OrgmodeFormatter;5+pub struct OrgmodeExporter {}6 12-impl MarkupFormatter for OrgmodeFormatter {13- fn table_data(&self, data: &[&str]) -> String {7+impl MarkupExporter for OrgmodeExporter {8+ fn table_row(&self, cells: &[&str]) -> String {9 format!(10 "| {} | {} |\n",16- data.first().unwrap(),17- &data[1..].join(" | ")11+ cells.first().unwrap(),12+ &cells[1..].join(" | ")13 )14 }15 21- fn table_line(&self, size: usize) -> String {22- format!("|{}--|\n", "--+".repeat(size - 1))16+ fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {17+ format!("|{}--|\n", "--+".repeat(cell_aligmnents.len() - 1))18 }19 20 fn command(&self, cmd: &str) -> String {21 format!("={}=", cmd)22 }23 }24 30-#[derive(Default)]31-pub struct OrgmodeExporter {}32-33-impl Exporter for OrgmodeExporter {34- fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {35- let unit = self.unit(results, unit);36- let entries = relative_speed::compute(results);37- if entries.is_none() {38- return Err(anyhow!(39- "Relative speed comparison is not available for Emacs org-mode export."40- ));41- }42-43- let formatter = OrgmodeFormatter::default();44- let table = formatter.table_results(&entries.unwrap(), unit);45- Ok(table.as_bytes().to_vec())46- }47-}48-25 /// Check Emacs org-mode data row formatting26 #[test]27 fn test_orgmode_formatter_table_data() {52- let formatter = OrgmodeFormatter::default();53- let data = vec!["a", "b", "c"];28+ let exporter = OrgmodeExporter::default();29 55- let actual = formatter.table_data(&data);30+ let actual = exporter.table_row(&["a", "b", "c"]);31 let expect = "| a | b | c |\n";32 33 assert_eq!(expect, actual);34 }35 36 /// Check Emacs org-mode horizontal line formatting37 #[test]38 fn test_orgmode_formatter_table_line() {64- let formatter = OrgmodeFormatter::default();65- let size = 5;39+ let exporter = OrgmodeExporter::default();40 67- let actual = formatter.table_line(size);41+ let actual = exporter.table_divider(&[42+ Alignment::Left,43+ Alignment::Left,44+ Alignment::Left,45+ Alignment::Left,46+ Alignment::Left,47+ ]);48 let expect = "|--+--+--+--+--|\n";49 50 assert_eq!(expect, actual);51 }15 unmodified lines67 /// This also demonstrates that the first entry's units (ms) are used to set68 /// the units for all entries when the time unit is not given.69 #[test]70 fn test_orgmode_format_ms() {71+ use super::Exporter;72+ use crate::benchmark::benchmark_result::BenchmarkResult;73 use std::collections::BTreeMap;74+75 let exporter = OrgmodeExporter::default();76 77 let results = vec![78 BenchmarkResult {39 unmodified lines118 /// This test demonstrates that the given unit (s) is used to set119 /// the units for all entries.120 #[test]121 fn test_orgmode_format_s() {122+ use super::Exporter;123+ use crate::benchmark::benchmark_result::BenchmarkResult;124+ use crate::util::units::Unit;125 use std::collections::BTreeMap;126+127 let exporter = OrgmodeExporter::default();128 129 let results = vec![130 BenchmarkResult {39 unmodified lines