Skip to content
Myr

asciidoc.rs

This file

Path

src/export/asciidoc.rs

76 lines · 1.9 KiB · Rust

Last changed by

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

History of this file

Take it

1use super::markup::Alignment;2use crate::export::markup::MarkupExporter;34#[derive(Default)]5pub struct AsciidocExporter {}67impl MarkupExporter for AsciidocExporter {8    fn table_header(&self, cell_aligmnents: &[Alignment]) -> String {9        format!(10            "[cols=\"{}\"]\n|===",11            cell_aligmnents12                .iter()13                .map(|a| match a {14                    Alignment::Left => "<",15                    Alignment::Right => ">",16                })17                .collect::<Vec<&str>>()18                .join(",")19        )20    }2122    fn table_footer(&self, _cell_aligmnents: &[Alignment]) -> String {23        "|===\n".to_string()24    }2526    fn table_row(&self, cells: &[&str]) -> String {27        let mut row = String::from("\n");28        for cell in cells {29            row.push('|');30            if !cell.is_empty() {31                row.push(' ');32                row.push_str(cell);33            }34            row.push('\n');35        }36        row37    }3839    fn table_divider(&self, _cell_aligmnents: &[Alignment]) -> String {40        "".to_string()41    }4243    fn command(&self, cmd: &str) -> String {44        format!("`{cmd}`")45    }46}4748/// Check Asciidoc-based data row formatting49#[test]50fn test_asciidoc_exporter_table_data() {51    let exporter = AsciidocExporter::default();52    let data = vec!["a", "b", "c"];5354    let actual = exporter.table_row(&data);55    let expect = "\n| a\n| b\n| c\n";5657    assert_eq!(expect, actual);58}5960/// Check Asciidoc-based table header formatting61#[test]62fn test_asciidoc_exporter_table_header() {63    let exporter = AsciidocExporter::default();64    let cells_alignment = [65        Alignment::Left,66        Alignment::Right,67        Alignment::Right,68        Alignment::Right,69        Alignment::Right,70    ];7172    let actual = exporter.table_header(&cells_alignment);73    let expect = "[cols=\"<,>,>,>,>\"]\n|===";7475    assert_eq!(expect, actual);76}