summaryrefslogtreecommitdiffstats
path: root/vendor/tabled/tests/settings/padding_test.rs
blob: 9a3edb4aa9916286cfba23b3c3dc1283cf8ae018 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#![cfg(feature = "std")]

use tabled::settings::{
    object::{Rows, Segment},
    Alignment, Modify, Padding, Style,
};

use crate::matrix::Matrix;
use testing_table::test_table;

#[cfg(feature = "color")]
use ::{owo_colors::OwoColorize, std::convert::TryFrom, tabled::settings::Color};

test_table!(
    padding,
    Matrix::new(3, 3)
        .with(Style::psql())
        .with(Modify::new(Segment::all()).with(Alignment::left()))
        .with(Modify::new(Rows::new(1..)).with(Padding::new(1, 1, 0, 2))),
    " N | column 0 | column 1 | column 2 "
    "---+----------+----------+----------"
    " 0 | 0-0      | 0-1      | 0-2      "
    "   |          |          |          "
    "   |          |          |          "
    " 1 | 1-0      | 1-1      | 1-2      "
    "   |          |          |          "
    "   |          |          |          "
    " 2 | 2-0      | 2-1      | 2-2      "
    "   |          |          |          "
    "   |          |          |          "
);

test_table!(
    padding_with_set_characters,
    Matrix::new(3, 3)
        .with(Style::psql())
        .with(Modify::new(Segment::all()).with(Padding::new(1, 2, 1, 1).fill('>', '<', 'V', '^'))),
    "VVVV|VVVVVVVVVVV|VVVVVVVVVVV|VVVVVVVVVVV"
    ">N<<|>column 0<<|>column 1<<|>column 2<<"
    "^^^^|^^^^^^^^^^^|^^^^^^^^^^^|^^^^^^^^^^^"
    "----+-----------+-----------+-----------"
    "VVVV|VVVVVVVVVVV|VVVVVVVVVVV|VVVVVVVVVVV"
    ">0<<|>  0-0   <<|>  0-1   <<|>  0-2   <<"
    "^^^^|^^^^^^^^^^^|^^^^^^^^^^^|^^^^^^^^^^^"
    "VVVV|VVVVVVVVVVV|VVVVVVVVVVV|VVVVVVVVVVV"
    ">1<<|>  1-0   <<|>  1-1   <<|>  1-2   <<"
    "^^^^|^^^^^^^^^^^|^^^^^^^^^^^|^^^^^^^^^^^"
    "VVVV|VVVVVVVVVVV|VVVVVVVVVVV|VVVVVVVVVVV"
    ">2<<|>  2-0   <<|>  2-1   <<|>  2-2   <<"
    "^^^^|^^^^^^^^^^^|^^^^^^^^^^^|^^^^^^^^^^^"
);

test_table!(
    padding_with_set_characters_and_zero_ident,
    Matrix::new(3, 3)
        .with(Style::psql())
        .with(Modify::new(Segment::all()).with(Padding::zero().fill('>', '<', '^', 'V'))),
    "N|column 0|column 1|column 2"
    "-+--------+--------+--------"
    "0|  0-0   |  0-1   |  0-2   "
    "1|  1-0   |  1-1   |  1-2   "
    "2|  2-0   |  2-1   |  2-2   "
);

test_table!(
    padding_multiline,
    Matrix::new(3, 3)
        .with(Style::psql())
        .with(Modify::new(Rows::new(1..)).with(Padding::new(1, 1, 1, 1))),
    " N | column 0 | column 1 | column 2 "
    "---+----------+----------+----------"
    "   |          |          |          "
    " 0 |   0-0    |   0-1    |   0-2    "
    "   |          |          |          "
    "   |          |          |          "
    " 1 |   1-0    |   1-1    |   1-2    "
    "   |          |          |          "
    "   |          |          |          "
    " 2 |   2-0    |   2-1    |   2-2    "
    "   |          |          |          "
);

test_table!(
    padding_multiline_with_vertical_alignment,
    Matrix::new(3, 3)
        .with(Style::psql())
        .with(Modify::new(Segment::all()).with(Alignment::center()).with(Alignment::center_vertical()))
        .with(Modify::new(Rows::new(1..)).with(Padding::new(1, 1, 1, 1))),
    " N | column 0 | column 1 | column 2 "
    "---+----------+----------+----------"
    "   |          |          |          "
    " 0 |   0-0    |   0-1    |   0-2    "
    "   |          |          |          "
    "   |          |          |          "
    " 1 |   1-0    |   1-1    |   1-2    "
    "   |          |          |          "
    "   |          |          |          "
    " 2 |   2-0    |   2-1    |   2-2    "
    "   |          |          |          "
);

#[cfg(feature = "color")]
test_table!(
    padding_color,
    {
        let padding = Padding::new(2, 2, 2, 2).colorize(
            Color::try_from(' '.on_yellow().to_string()).unwrap(),
            Color::try_from(' '.on_blue().to_string()).unwrap(),
            Color::try_from(' '.on_red().to_string()).unwrap(),
            Color::try_from(' '.on_green().to_string()).unwrap(),
        );

        Matrix::new(3, 3)
            .with(Style::psql())
            .with(Modify::new(Rows::new(1..)).with(padding))
    },
    "  N  | column 0 | column 1 | column 2 \n-----+----------+----------+----------\n\u{1b}[41m     \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m\n\u{1b}[41m     \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m\n\u{1b}[43m  \u{1b}[49m0\u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 0-0  \u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 0-1  \u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 0-2  \u{1b}[44m  \u{1b}[49m\n\u{1b}[42m     \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m\n\u{1b}[42m     \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m\n\u{1b}[41m     \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m\n\u{1b}[41m     \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m\n\u{1b}[43m  \u{1b}[49m1\u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 1-0  \u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 1-1  \u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 1-2  \u{1b}[44m  \u{1b}[49m\n\u{1b}[42m     \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m\n\u{1b}[42m     \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m\n\u{1b}[41m     \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m\n\u{1b}[41m     \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m|\u{1b}[41m          \u{1b}[49m\n\u{1b}[43m  \u{1b}[49m2\u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 2-0  \u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 2-1  \u{1b}[44m  \u{1b}[49m|\u{1b}[43m  \u{1b}[49m 2-2  \u{1b}[44m  \u{1b}[49m\n\u{1b}[42m     \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m\n\u{1b}[42m     \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m|\u{1b}[42m          \u{1b}[49m"
);

test_table!(
    padding_table,
    Matrix::new(3, 3)
        .with(Style::psql())
        .with(Padding::new(1, 1, 0, 2)),
    " N | column 0 | column 1 | column 2 "
    "   |          |          |          "
    "   |          |          |          "
    "---+----------+----------+----------"
    " 0 |   0-0    |   0-1    |   0-2    "
    "   |          |          |          "
    "   |          |          |          "
    " 1 |   1-0    |   1-1    |   1-2    "
    "   |          |          |          "
    "   |          |          |          "
    " 2 |   2-0    |   2-1    |   2-2    "
    "   |          |          |          "
    "   |          |          |          "
);