summaryrefslogtreecommitdiffstats
path: root/vendor/tabled/tests/settings/height_test.rs
blob: 48d6a6364beb093ddaad1c3d263fb8858d3e6136 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#![cfg(feature = "std")]

use tabled::settings::{
    object::{Columns, Segment},
    Alignment, Format, Height, Modify, Style,
};

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

#[cfg(feature = "color")]
use owo_colors::OwoColorize;

test_table!(
    cell_height_increase,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(
            Modify::new(Columns::first())
                .with(Height::increase(3))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "| 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!(
    table_height_increase,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::increase(10)),
    "|   | column 0 | column 1 | column 2 |"
    "| N |          |          |          |"
    "|   |          |          |          |"
    "|---|----------|----------|----------|"
    "| 0 |   0-0    |   0-1    |   0-2    |"
    "|   |          |          |          |"
    "| 1 |   1-0    |   1-1    |   1-2    |"
    "|   |          |          |          |"
    "| 2 |   2-0    |   2-1    |   2-2    |"
    "|   |          |          |          |"
);

test_table!(
    cell_height_increase_zero,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(
            Modify::new(Columns::first())
                .with(Height::increase(0))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "| 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!(
    table_height_increase_zero,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::increase(0)),
    "| 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!(
    cell_height_limit,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n"))))
        .with(
            Modify::new(Columns::first())
                .with(Height::limit(1))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "| xxxx | column 0 | column 1 | column 2 |"
    "|------|----------|----------|----------|"
    "| xxxx |   0-0    |   0-1    |   0-2    |"
    "| xxxx |   1-0    |   1-1    |   1-2    |"
    "| xxxx |   2-0    |   2-1    |   2-2    |"
);

test_table!(
    table_height_limit,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n"))))
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::limit(10)),
    "| xxxx  | column 0 | column 1 | column 2 |"
    "| Nxxxx |          |          |          |"
    "|-------|----------|----------|----------|"
    "| xxxx  |   0-0    |   0-1    |   0-2    |"
    "| 0xxxx |          |          |          |"
    "| xxxx  |   1-0    |   1-1    |   1-2    |"
    "| 1xxxx |          |          |          |"
    "| xxxx  |   2-0    |   2-1    |   2-2    |"
    "| 2xxxx |          |          |          |"
    "| xxxx  |          |          |          |"
);

test_table!(
    table_height_limit_style_change_after,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n"))))
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::limit(7)),
    "| xxxx  | column 0 | column 1 | column 2 |"
    "|-------|----------|----------|----------|"
    "| xxxx  |   0-0    |   0-1    |   0-2    |"
    "| xxxx  |   1-0    |   1-1    |   1-2    |"
    "| 1xxxx |          |          |          |"
    "| xxxx  |   2-0    |   2-1    |   2-2    |"
    "| 2xxxx |          |          |          |"
);

test_table!(
    cell_height_limit_zero,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n"))))
        .with(
            Modify::new(Columns::first())
                .with(Height::limit(0))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
    "|  | column 0 | column 1 | column 2 |"
    "|--|----------|----------|----------|"
    "|  |   0-0    |   0-1    |   0-2    |"
    "|  |   1-0    |   1-1    |   1-2    |"
    "|  |   2-0    |   2-1    |   2-2    |"
);

test_table!(
    table_height_limit_zero,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(
            Modify::new(Columns::new(..))
                .with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n")))
        )
        .with(Height::limit(0)),
    "|--|--|--|--|"
);

test_table!(
    table_height_limit_zero_1,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Height::limit(0))
        .with(
            Modify::new(Columns::new(..)).with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n")))
        ),
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "|      |      |      |      |"
        "|------|------|------|------|"
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "|      |      |      |      |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "|      |      |      |      |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "| xxxx | xxxx | xxxx | xxxx |"
        "|      |      |      |      |"
);

#[cfg(feature = "color")]
test_table!(
    cell_height_limit_colored,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n").red().to_string())))
        .with(
            Modify::new(Columns::first())
                .with(Height::limit(1))
        )
        .with(Modify::new(Segment::all()).with(
            Alignment::center_vertical()
        )),
        "| \u{1b}[31mxxxx\u{1b}[39m | column 0 | column 1 | column 2 |"
        "|------|----------|----------|----------|"
        "| \u{1b}[31mxxxx\u{1b}[39m |   0-0    |   0-1    |   0-2    |"
        "| \u{1b}[31mxxxx\u{1b}[39m |   1-0    |   1-1    |   1-2    |"
        "| \u{1b}[31mxxxx\u{1b}[39m |   2-0    |   2-1    |   2-2    |"
);

#[cfg(feature = "color")]
test_table!(
    table_height_limit_colored,
    Matrix::new(3, 3)
        .with(Style::markdown())
        .with(Modify::new(Columns::first()).with(Format::content(|s| format!("xxxx\n{s}xxxx\nxxxx\n").blue().on_green().to_string())))
        .with(Modify::new(Columns::first()).with(Alignment::center_vertical()))
        .with(Height::limit(10)),
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  | column 0 | column 1 | column 2 |"
        "| \u{1b}[34m\u{1b}[42mNxxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "|-------|----------|----------|----------|"
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  |   0-0    |   0-1    |   0-2    |"
        "| \u{1b}[34m\u{1b}[42m0xxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  |   1-0    |   1-1    |   1-2    |"
        "| \u{1b}[34m\u{1b}[42m1xxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "| \u{1b}[34;42mxxxx\u{1b}[39m\u{1b}[49m  |   2-0    |   2-1    |   2-2    |"
        "| \u{1b}[34m\u{1b}[42m2xxxx\u{1b}[39m\u{1b}[49m |          |          |          |"
        "| \u{1b}[34m\u{1b}[42mxxxx\u{1b}[39m\u{1b}[49m  |          |          |          |"
);

#[cfg(feature = "macros")]
test_table!(
    cell_height_1x1,
    tabled::row![tabled::col!["SGML"].with(Height::increase(4))],
    "+----------+"
    "| +------+ |"
    "| | SGML | |"
    "| |      | |"
    "| +------+ |"
    "+----------+"
);

#[cfg(feature = "macros")]
test_table!(
    cell_height_1x1_no_top_border,
    tabled::row![tabled::col!["SGML"].with(Style::ascii().remove_top()).with(Height::increase(4))],
    "+----------+"
    "| | SGML | |"
    "| |      | |"
    "| |      | |"
    "| +------+ |"
    "+----------+"
);