Skip to content
Myr

markdown.rs

This file

Path

src/export/markdown.rs

271 lines · 8.0 KiB · Rust

Last changed by

Simplify testDavid Peterbefore adoptione3bc5b8

History of this file

Take it

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

line 1why, one step back
1use crate::export::markup::MarkupExporter;

Flat directory/module structureDavid Peterbefore adoption30c381f

line 2why, one step back
2

table_line => table_dividerDavid Peterbefore adoption8c05fd0

lines 3–4why, one step back
3use super::markup::Alignment;
4

Flat directory/module structureDavid Peterbefore adoption30c381f

line 5why, one step back
5#[derive(Default)]

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

line 6why, one step back
6pub struct MarkdownExporter {}

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 7why, one step back
7

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

line 8why, one step back
8impl MarkupExporter for MarkdownExporter {

table_line => table_dividerDavid Peterbefore adoption8c05fd0

lines 9–10why, one step back
9 fn table_row(&self, cells: &[&str]) -> String {
10 format!("| {} |\n", cells.join(" | "))

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

lines 11–12why, one step back
11 }
12

table_line => table_dividerDavid Peterbefore adoption8c05fd0

lines 13–23why, one step back
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 )

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

lines 24–33why, one step back
24 }
2526 fn command(&self, cmd: &str) -> String {27 format!("`{}`", cmd)28 }29}3031/// Check Markdown-based data row formatting32#[test]33fn test_markdown_formatter_table_data() {

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

line 34why, one step back
34 let formatter = MarkdownExporter::default();

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 35why, one step back
35

table_line => table_dividerDavid Peterbefore adoption8c05fd0

line 36why, one step back
36 assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

lines 37–40why, one step back
37}
3839/// Check Markdown-based horizontal line formatting40#[test]

table_line => table_dividerDavid Peterbefore adoption8c05fd0

line 41why, one step back
41fn test_markdown_formatter_table_divider() {

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

line 42why, one step back
42 let formatter = MarkdownExporter::default();

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 43why, one step back
43

Simplify testDavid Peterbefore adoptione3bc5b8

lines 44–45why, one step back
44 let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);
45 assert_eq!(divider, "|:---|---:|:---|\n");

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

lines 46–47why, one step back
46}
47

Refactor Markdown with Markup by using generic table emitterPhilipp Paulweberbefore adoption23d9fe2

line 48why, one step back
48/// Test helper function to create unit-based header and horizontal line

Refactor Markdown table emitting to generic Markup functionPhilipp Paulweberbefore adoption50cf7de

line 49why, one step back
49/// independently from the markup functionality for Markdown.

Refactor Markdown with Markup by using generic table emitterPhilipp Paulweberbefore adoption23d9fe2

line 50why, one step back
50#[cfg(test)]

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 51why, one step back
51fn cfg_test_table_header(unit_short_name: String) -> String {

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 52–65why, one step back
52 format!(
53 "| Command | Mean [{unit}] | Min [{unit}] | Max [{unit}] | Relative |\n|:---|---:|---:|---:|---:|\n",54 unit = unit_short_name55 )56}5758/// Ensure the markdown output includes the table header and the multiple59/// benchmark results as a table. The list of actual times is not included60/// in the output.61///62/// This also demonstrates that the first entry's units (ms) are used to set63/// the units for all entries when the time unit is not given.64#[test]65fn test_markdown_format_ms() {

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

lines 66–67why, one step back
66 use super::Exporter;
67 use crate::benchmark::benchmark_result::BenchmarkResult;

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 68–70why, one step back
68 use std::collections::BTreeMap;
69 let exporter = MarkdownExporter::default();70

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 71why, one step back
71 let timing_results = vec![

Remove BenchmarkResult::newDavid Peterbefore adoption81b737f

lines 72–97why, one step back
72 BenchmarkResult {
73 command: String::from("sleep 0.1"),74 mean: 0.1057,75 stddev: Some(0.0016),76 median: 0.1057,77 user: 0.0009,78 system: 0.0011,79 min: 0.1023,80 max: 0.1080,81 times: Some(vec![0.1, 0.1, 0.1]),82 exit_codes: vec![Some(0), Some(0), Some(0)],83 parameters: BTreeMap::new(),84 },85 BenchmarkResult {86 command: String::from("sleep 2"),87 mean: 2.0050,88 stddev: Some(0.0020),89 median: 2.0050,90 user: 0.0009,91 system: 0.0012,92 min: 2.0020,93 max: 2.0080,94 times: Some(vec![2.0, 2.0, 2.0]),95 exit_codes: vec![Some(0), Some(0), Some(0)],96 parameters: BTreeMap::new(),97 },

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 98why, one step back
98 ];

Flat directory/module structureDavid Peterbefore adoption30c381f

line 99why, one step back
99

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

lines 100–101why, one step back
100 let actual = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
101 let expect = format!(

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 102–105why, one step back
102 "{}\
103| `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |104| `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |105",

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 106why, one step back
106 cfg_test_table_header("ms".to_string())

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 107–108why, one step back
107 );
108

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 109why, one step back
109 assert_eq!(expect, actual);

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 110–115why, one step back
110}
111112/// This (again) demonstrates that the first entry's units (s) are used to set113/// the units for all entries when the time unit is not given.114#[test]115fn test_markdown_format_s() {

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

lines 116–117why, one step back
116 use super::Exporter;
117 use crate::benchmark::benchmark_result::BenchmarkResult;

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 118–120why, one step back
118 use std::collections::BTreeMap;
119 let exporter = MarkdownExporter::default();120

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 121why, one step back
121 let timing_results = vec![

Remove BenchmarkResult::newDavid Peterbefore adoption81b737f

lines 122–147why, one step back
122 BenchmarkResult {
123 command: String::from("sleep 2"),124 mean: 2.0050,125 stddev: Some(0.0020),126 median: 2.0050,127 user: 0.0009,128 system: 0.0012,129 min: 2.0020,130 max: 2.0080,131 times: Some(vec![2.0, 2.0, 2.0]),132 exit_codes: vec![Some(0), Some(0), Some(0)],133 parameters: BTreeMap::new(),134 },135 BenchmarkResult {136 command: String::from("sleep 0.1"),137 mean: 0.1057,138 stddev: Some(0.0016),139 median: 0.1057,140 user: 0.0009,141 system: 0.0011,142 min: 0.1023,143 max: 0.1080,144 times: Some(vec![0.1, 0.1, 0.1]),145 exit_codes: vec![Some(0), Some(0), Some(0)],146 parameters: BTreeMap::new(),147 },

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 148why, one step back
148 ];

Flat directory/module structureDavid Peterbefore adoption30c381f

line 149why, one step back
149

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

lines 150–151why, one step back
150 let actual = String::from_utf8(exporter.serialize(&timing_results, None).unwrap()).unwrap();
151 let expect = format!(

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 152–155why, one step back
152 "{}\
153| `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |154| `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |155",

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 156why, one step back
156 cfg_test_table_header("s".to_string())

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 157–158why, one step back
157 );
158

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 159why, one step back
159 assert_eq!(expect, actual);

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 160–164why, one step back
160}
161162/// The given time unit (s) is used to set the units for all entries.163#[test]164fn test_markdown_format_time_unit_s() {

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

lines 165–167why, one step back
165 use super::Exporter;
166 use crate::benchmark::benchmark_result::BenchmarkResult;167 use crate::util::units::Unit;

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 168–170why, one step back
168 use std::collections::BTreeMap;
169 let exporter = MarkdownExporter::default();170

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 171why, one step back
171 let timing_results = vec![

Remove BenchmarkResult::newDavid Peterbefore adoption81b737f

lines 172–197why, one step back
172 BenchmarkResult {
173 command: String::from("sleep 0.1"),174 mean: 0.1057,175 stddev: Some(0.0016),176 median: 0.1057,177 user: 0.0009,178 system: 0.0011,179 min: 0.1023,180 max: 0.1080,181 times: Some(vec![0.1, 0.1, 0.1]),182 exit_codes: vec![Some(0), Some(0), Some(0)],183 parameters: BTreeMap::new(),184 },185 BenchmarkResult {186 command: String::from("sleep 2"),187 mean: 2.0050,188 stddev: Some(0.0020),189 median: 2.0050,190 user: 0.0009,191 system: 0.0012,192 min: 2.0020,193 max: 2.0080,194 times: Some(vec![2.0, 2.0, 2.0]),195 exit_codes: vec![Some(0), Some(0), Some(0)],196 parameters: BTreeMap::new(),197 },

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 198why, one step back
198 ];

Flat directory/module structureDavid Peterbefore adoption30c381f

line 199why, one step back
199

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 200why, one step back
200 let actual = String::from_utf8(

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 201–205why, one step back
201 exporter
202 .serialize(&timing_results, Some(Unit::Second))203 .unwrap(),204 )205 .unwrap();

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 206why, one step back
206 let expect = format!(

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 207–210why, one step back
207 "{}\
208| `sleep 0.1` | 0.106 ± 0.002 | 0.102 | 0.108 | 1.00 |209| `sleep 2` | 2.005 ± 0.002 | 2.002 | 2.008 | 18.97 ± 0.29 |210",

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 211why, one step back
211 cfg_test_table_header("s".to_string())

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 212–213why, one step back
212 );
213

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 214why, one step back
214 assert_eq!(expect, actual);

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 215–220why, one step back
215}
216217/// This (again) demonstrates that the given time unit (ms) is used to set218/// the units for all entries.219#[test]220fn test_markdown_format_time_unit_ms() {

Implement Exporter for all MarkupExportersDavid Peterbefore adoption4cdf2d5

lines 221–223why, one step back
221 use super::Exporter;
222 use crate::benchmark::benchmark_result::BenchmarkResult;223 use crate::util::units::Unit;

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 224–226why, one step back
224 use std::collections::BTreeMap;
225 let exporter = MarkdownExporter::default();226

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 227why, one step back
227 let timing_results = vec![

Remove BenchmarkResult::newDavid Peterbefore adoption81b737f

lines 228–253why, one step back
228 BenchmarkResult {
229 command: String::from("sleep 2"),230 mean: 2.0050,231 stddev: Some(0.0020),232 median: 2.0050,233 user: 0.0009,234 system: 0.0012,235 min: 2.0020,236 max: 2.0080,237 times: Some(vec![2.0, 2.0, 2.0]),238 exit_codes: vec![Some(0), Some(0), Some(0)],239 parameters: BTreeMap::new(),240 },241 BenchmarkResult {242 command: String::from("sleep 0.1"),243 mean: 0.1057,244 stddev: Some(0.0016),245 median: 0.1057,246 user: 0.0009,247 system: 0.0011,248 min: 0.1023,249 max: 0.1080,250 times: Some(vec![0.1, 0.1, 0.1]),251 exit_codes: vec![Some(0), Some(0), Some(0)],252 parameters: BTreeMap::new(),253 },

Fix clippy warnings from testsHeikki Hellgrenbefore adoptionf592155

line 254why, one step back
254 ];

Flat directory/module structureDavid Peterbefore adoption30c381f

line 255why, one step back
255

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 256why, one step back
256 let actual = String::from_utf8(

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 257–261why, one step back
257 exporter
258 .serialize(&timing_results, Some(Unit::MilliSecond))259 .unwrap(),260 )261 .unwrap();

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 262why, one step back
262 let expect = format!(

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 263–266why, one step back
263 "{}\
264| `sleep 2` | 2005.0 ± 2.0 | 2002.0 | 2008.0 | 18.97 ± 0.29 |265| `sleep 0.1` | 105.7 ± 1.6 | 102.3 | 108.0 | 1.00 |266",

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 267why, one step back
267 cfg_test_table_header("ms".to_string())

Flat directory/module structureDavid Peterbefore adoption30c381f

lines 268–269why, one step back
268 );
269

Refactor MarkdownExporter emitting using a generic MarkupFormatter traitPhilipp Paulweberbefore adoption9dc87ac

line 270why, one step back
270 assert_eq!(expect, actual);

Flat directory/module structureDavid Peterbefore adoption30c381f

line 271why, one step back
271}