orgmode.rs
This file
Path
src/export/orgmode.rs
169 lines · 4.8 KiB · Rust
Last changed by
Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
History of this fileTake it
Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
lines 1–2why, one step back1use super::markup::Alignment;2use crate::export::markup::MarkupExporter;Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 3–4why, one step back34#[derive(Default)]Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
line 5why, one step back5pub struct OrgmodeExporter {}Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 6why, one step back6Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
lines 7–8why, one step back7impl MarkupExporter for OrgmodeExporter {8 fn table_row(&self, cells: &[&str]) -> String {Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 9–10why, one step back9 format!(10 "| {} | {} |\n",Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
lines 11–12why, one step back11 cells.first().unwrap(),12 &cells[1..].join(" | ")Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 13–15why, one step back13 )14 }15Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
lines 16–17why, one step back16 fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {17 format!("|{}--|\n", "--+".repeat(cell_aligmnents.len() - 1))Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 18–27why, one step back18 }1920 fn command(&self, cmd: &str) -> String {21 format!("={}=", cmd)22 }23}2425/// Check Emacs org-mode data row formatting26#[test]27fn test_orgmode_formatter_table_data() {Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
line 28why, one step back28 let exporter = OrgmodeExporter::default();Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 29why, one step back29Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
line 30why, one step back30 let actual = exporter.table_row(&["a", "b", "c"]);Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 31–38why, one step back31 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() {Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
line 39why, one step back39 let exporter = OrgmodeExporter::default();Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 40why, one step back40Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
lines 41–47why, one step back41 let actual = exporter.table_divider(&[42 Alignment::Left,43 Alignment::Left,44 Alignment::Left,45 Alignment::Left,46 Alignment::Left,47 ]);Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 48–70why, one step back48 let expect = "|--+--+--+--+--|\n";4950 assert_eq!(expect, actual);51}5253/// Test helper function to create unit-based header and horizontal line54/// independently from the markup functionality for Emacs org-mode.55#[cfg(test)]56fn cfg_test_table_header(unit_short_name: String) -> String {57 format!(58 "| Command | Mean [{unit}] | Min [{unit}] | Max [{unit}] | Relative |\n|--+--+--+--+--|\n",59 unit = unit_short_name60 )61}6263/// Ensure the Emacs org-mode output includes the table header and the multiple64/// benchmark results as a table. The list of actual times is not included65/// in the output.66///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() {Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
lines 71–72why, one step back71 use super::Exporter;72 use crate::benchmark::benchmark_result::BenchmarkResult;Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 73why, one step back73 use std::collections::BTreeMap;Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
line 74why, one step back74Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 75–121why, one step back75 let exporter = OrgmodeExporter::default();7677 let results = vec![78 BenchmarkResult {79 command: String::from("sleep 0.1"),80 mean: 0.1057,81 stddev: Some(0.0016),82 median: 0.1057,83 user: 0.0009,84 system: 0.0011,85 min: 0.1023,86 max: 0.1080,87 times: Some(vec![0.1, 0.1, 0.1]),88 exit_codes: vec![Some(0), Some(0), Some(0)],89 parameters: BTreeMap::new(),90 },91 BenchmarkResult {92 command: String::from("sleep 2"),93 mean: 2.0050,94 stddev: Some(0.0020),95 median: 2.0050,96 user: 0.0009,97 system: 0.0012,98 min: 2.0020,99 max: 2.0080,100 times: Some(vec![2.0, 2.0, 2.0]),101 exit_codes: vec![Some(0), Some(0), Some(0)],102 parameters: BTreeMap::new(),103 },104 ];105106 let actual = String::from_utf8(exporter.serialize(&results, None).unwrap()).unwrap();107 let expect = format!(108 "{}\109| =sleep 0.1= | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |110| =sleep 2= | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |111",112 cfg_test_table_header("ms".to_string())113 );114115 assert_eq!(expect, actual);116}117118/// This test demonstrates that the given unit (s) is used to set119/// the units for all entries.120#[test]121fn test_orgmode_format_s() {Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
lines 122–124why, one step back122 use super::Exporter;123 use crate::benchmark::benchmark_result::BenchmarkResult;124 use crate::util::units::Unit;Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
line 125why, one step back125 use std::collections::BTreeMap;Adapt to new markup exporter changesDavid Peterbefore adoptioneb0ccc8
line 126why, one step back126Export of Emacs org-mode table supportPhilipp Paulweberbefore adoption2443383
lines 127–169why, one step back127 let exporter = OrgmodeExporter::default();128129 let results = vec![130 BenchmarkResult {131 command: String::from("sleep 2"),132 mean: 2.0050,133 stddev: Some(0.0020),134 median: 2.0050,135 user: 0.0009,136 system: 0.0012,137 min: 2.0020,138 max: 2.0080,139 times: Some(vec![2.0, 2.0, 2.0]),140 exit_codes: vec![Some(0), Some(0), Some(0)],141 parameters: BTreeMap::new(),142 },143 BenchmarkResult {144 command: String::from("sleep 0.1"),145 mean: 0.1057,146 stddev: Some(0.0016),147 median: 0.1057,148 user: 0.0009,149 system: 0.0011,150 min: 0.1023,151 max: 0.1080,152 times: Some(vec![0.1, 0.1, 0.1]),153 exit_codes: vec![Some(0), Some(0), Some(0)],154 parameters: BTreeMap::new(),155 },156 ];157158 let actual =159 String::from_utf8(exporter.serialize(&results, Some(Unit::Second)).unwrap()).unwrap();160 let expect = format!(161 "{}\162| =sleep 2= | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |163| =sleep 0.1= | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |164",165 cfg_test_table_header("s".to_string())166 );167168 assert_eq!(expect, actual);169}