mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-03 01:21:25 +00:00
Adapt to new markup exporter changes
This commit is contained in:
1 parent
7b28528a74
commit
e25673e81f
1 file changed
+26
-39
+26
-39
@@ -1,25 +1,20 @@
|
|||||||
use super::Exporter;
|
use super::markup::Alignment;
|
||||||
use crate::benchmark::benchmark_result::BenchmarkResult;
|
use crate::export::markup::MarkupExporter;
|
||||||
use crate::benchmark::relative_speed;
|
|
||||||
use crate::export::markup::MarkupFormatter;
|
|
||||||
use crate::util::units::Unit;
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct OrgmodeFormatter;
|
pub struct OrgmodeExporter {}
|
||||||
|
|
||||||
impl MarkupFormatter for OrgmodeFormatter {
|
impl MarkupExporter for OrgmodeExporter {
|
||||||
fn table_data(&self, data: &[&str]) -> String {
|
fn table_row(&self, cells: &[&str]) -> String {
|
||||||
format!(
|
format!(
|
||||||
"| {} | {} |\n",
|
"| {} | {} |\n",
|
||||||
data.first().unwrap(),
|
cells.first().unwrap(),
|
||||||
&data[1..].join(" | ")
|
&cells[1..].join(" | ")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn table_line(&self, size: usize) -> String {
|
fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {
|
||||||
format!("|{}--|\n", "--+".repeat(size - 1))
|
format!("|{}--|\n", "--+".repeat(cell_aligmnents.len() - 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn command(&self, cmd: &str) -> String {
|
fn command(&self, cmd: &str) -> String {
|
||||||
@@ -27,32 +22,12 @@ impl MarkupFormatter for OrgmodeFormatter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct OrgmodeExporter {}
|
|
||||||
|
|
||||||
impl Exporter for OrgmodeExporter {
|
|
||||||
fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {
|
|
||||||
let unit = self.unit(results, unit);
|
|
||||||
let entries = relative_speed::compute(results);
|
|
||||||
if entries.is_none() {
|
|
||||||
return Err(anyhow!(
|
|
||||||
"Relative speed comparison is not available for Emacs org-mode export."
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let formatter = OrgmodeFormatter::default();
|
|
||||||
let table = formatter.table_results(&entries.unwrap(), unit);
|
|
||||||
Ok(table.as_bytes().to_vec())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check Emacs org-mode data row formatting
|
/// Check Emacs org-mode data row formatting
|
||||||
#[test]
|
#[test]
|
||||||
fn test_orgmode_formatter_table_data() {
|
fn test_orgmode_formatter_table_data() {
|
||||||
let formatter = OrgmodeFormatter::default();
|
let exporter = OrgmodeExporter::default();
|
||||||
let data = vec!["a", "b", "c"];
|
|
||||||
|
|
||||||
let actual = formatter.table_data(&data);
|
let actual = exporter.table_row(&["a", "b", "c"]);
|
||||||
let expect = "| a | b | c |\n";
|
let expect = "| a | b | c |\n";
|
||||||
|
|
||||||
assert_eq!(expect, actual);
|
assert_eq!(expect, actual);
|
||||||
@@ -61,10 +36,15 @@ fn test_orgmode_formatter_table_data() {
|
|||||||
/// Check Emacs org-mode horizontal line formatting
|
/// Check Emacs org-mode horizontal line formatting
|
||||||
#[test]
|
#[test]
|
||||||
fn test_orgmode_formatter_table_line() {
|
fn test_orgmode_formatter_table_line() {
|
||||||
let formatter = OrgmodeFormatter::default();
|
let exporter = OrgmodeExporter::default();
|
||||||
let size = 5;
|
|
||||||
|
|
||||||
let actual = formatter.table_line(size);
|
let actual = exporter.table_divider(&[
|
||||||
|
Alignment::Left,
|
||||||
|
Alignment::Left,
|
||||||
|
Alignment::Left,
|
||||||
|
Alignment::Left,
|
||||||
|
Alignment::Left,
|
||||||
|
]);
|
||||||
let expect = "|--+--+--+--+--|\n";
|
let expect = "|--+--+--+--+--|\n";
|
||||||
|
|
||||||
assert_eq!(expect, actual);
|
assert_eq!(expect, actual);
|
||||||
@@ -88,7 +68,10 @@ fn cfg_test_table_header(unit_short_name: String) -> String {
|
|||||||
/// the units for all entries when the time unit is not given.
|
/// the units for all entries when the time unit is not given.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_orgmode_format_ms() {
|
fn test_orgmode_format_ms() {
|
||||||
|
use super::Exporter;
|
||||||
|
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
let exporter = OrgmodeExporter::default();
|
let exporter = OrgmodeExporter::default();
|
||||||
|
|
||||||
let results = vec![
|
let results = vec![
|
||||||
@@ -136,7 +119,11 @@ fn test_orgmode_format_ms() {
|
|||||||
/// the units for all entries.
|
/// the units for all entries.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_orgmode_format_s() {
|
fn test_orgmode_format_s() {
|
||||||
|
use super::Exporter;
|
||||||
|
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||||
|
use crate::util::units::Unit;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
let exporter = OrgmodeExporter::default();
|
let exporter = OrgmodeExporter::default();
|
||||||
|
|
||||||
let results = vec![
|
let results = vec![
|
||||||
|
|||||||
Reference in new issue
Block a user