Skip to content
Myr

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

1 file+26 added−39 removed

modified:src/export/orgmode.rs+26 added-39 removed
1use super::Exporter;2use crate::benchmark::benchmark_result::BenchmarkResult;3use crate::benchmark::relative_speed;4use crate::export::markup::MarkupFormatter;5use crate::util::units::Unit;1use super::markup::Alignment;2use crate::export::markup::MarkupExporter;37use anyhow::{anyhow, Result};84#[derive(Default)]10pub struct OrgmodeFormatter;5pub struct OrgmodeExporter {}612impl MarkupFormatter for OrgmodeFormatter {13 fn table_data(&self, data: &[&str]) -> String {7impl 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 }1521 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 }1920 fn command(&self, cmd: &str) -> String {21 format!("={}=", cmd)22 }23}2430#[derive(Default)]31pub struct OrgmodeExporter {}3233impl 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 }4243 let formatter = OrgmodeFormatter::default();44 let table = formatter.table_results(&entries.unwrap(), unit);45 Ok(table.as_bytes().to_vec())46 }47}4825/// Check Emacs org-mode data row formatting26#[test]27fn test_orgmode_formatter_table_data() {52 let formatter = OrgmodeFormatter::default();53 let data = vec!["a", "b", "c"];28 let exporter = OrgmodeExporter::default();2955 let actual = formatter.table_data(&data);30 let actual = exporter.table_row(&["a", "b", "c"]);31 let expect = "| a | b | c |\n";3233 assert_eq!(expect, actual);34}3536/// Check Emacs org-mode horizontal line formatting37#[test]38fn test_orgmode_formatter_table_line() {64 let formatter = OrgmodeFormatter::default();65 let size = 5;39 let exporter = OrgmodeExporter::default();4067 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";4950 assert_eq!(expect, actual);51}
15 unmodified lines
67/// 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]70fn test_orgmode_format_ms() {71 use super::Exporter;72 use crate::benchmark::benchmark_result::BenchmarkResult;73 use std::collections::BTreeMap;7475 let exporter = OrgmodeExporter::default();7677 let results = vec![78 BenchmarkResult {
39 unmodified lines
118/// This test demonstrates that the given unit (s) is used to set119/// the units for all entries.120#[test]121fn 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;126127 let exporter = OrgmodeExporter::default();128129 let results = vec![130 BenchmarkResult {
39 unmodified lines