/ thirdparty / hyperfine / src / export / asciidoc.rs
asciidoc.rs
 1  use super::markup::Alignment;
 2  use crate::export::markup::MarkupExporter;
 3  
 4  #[derive(Default)]
 5  pub struct AsciidocExporter {}
 6  
 7  impl MarkupExporter for AsciidocExporter {
 8      fn table_header(&self, cell_aligmnents: &[Alignment]) -> String {
 9          format!(
10              "[cols=\"{}\"]\n|===",
11              cell_aligmnents
12                  .iter()
13                  .map(|a| match a {
14                      Alignment::Left => "<",
15                      Alignment::Right => ">",
16                  })
17                  .collect::<Vec<&str>>()
18                  .join(",")
19          )
20      }
21  
22      fn table_footer(&self, _cell_aligmnents: &[Alignment]) -> String {
23          "|===\n".to_string()
24      }
25  
26      fn table_row(&self, cells: &[&str]) -> String {
27          format!("\n| {} \n", cells.join(" \n| "))
28      }
29  
30      fn table_divider(&self, _cell_aligmnents: &[Alignment]) -> String {
31          "".to_string()
32      }
33  
34      fn command(&self, cmd: &str) -> String {
35          format!("`{cmd}`")
36      }
37  }
38  
39  /// Check Asciidoc-based data row formatting
40  #[test]
41  fn test_asciidoc_exporter_table_data() {
42      let exporter = AsciidocExporter::default();
43      let data = vec!["a", "b", "c"];
44  
45      let actual = exporter.table_row(&data);
46      let expect = "\n| a \n| b \n| c \n";
47  
48      assert_eq!(expect, actual);
49  }
50  
51  /// Check Asciidoc-based table header formatting
52  #[test]
53  fn test_asciidoc_exporter_table_header() {
54      let exporter = AsciidocExporter::default();
55      let cells_alignment = [
56          Alignment::Left,
57          Alignment::Right,
58          Alignment::Right,
59          Alignment::Right,
60          Alignment::Right,
61      ];
62  
63      let actual = exporter.table_header(&cells_alignment);
64      let expect = "[cols=\"<,>,>,>,>\"]\n|===";
65  
66      assert_eq!(expect, actual);
67  }