Debian Codegraph @

tests/all/alignment_test.rs

raw symbols SCIP
1 use comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::*;
2 use pretty_assertionsrust-analyzer cargo pretty_assertions 1.4.1 crate/::assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!;
3
4 /// Cell alignment can be specified on Columns and Cells
5 /// Alignment settings on Cells overwrite the settings of Columns
6 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
7 fn cell_alignmentrust-analyzer cargo comfy-table 7.2.2 all/alignment_test/cell_alignment().() {
8 let mut table = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().();
9 table
10 .set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Header1", "Header2", "Header3"])
11 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
12 "Very long line Test",
13 "Very long line Test",
14 "Very long line Test",
15 ])
16 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
17 Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().("Right").set_alignmentrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]set_alignment().(CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Rightrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Right#),
18 Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().("Left").set_alignmentrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]set_alignment().(CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Leftrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Left#),
19 Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().("Center").set_alignmentrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]set_alignment().(CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Centerrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Center#),
20 ])
21 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Left", "Center", "Right"]);
22
23 let alignment = [
24 CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Leftrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Left#,
25 CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Centerrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Center#,
26 CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Rightrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Right#,
27 ];
28
29 // Add the alignment to their respective column
30 for (column_index, column) in table.column_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
31 let alignment = alignment.getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(column_index).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
32 column.set_cell_alignmentrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_cell_alignment().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().alignment);
33 }
34
35 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}");
36 let expected = "
37 +---------------------+---------------------+---------------------+
38 | Header1 | Header2 | Header3 |
39 +=================================================================+
40 | Very long line Test | Very long line Test | Very long line Test |
41 |---------------------+---------------------+---------------------|
42 | Right | Left | Center |
43 |---------------------+---------------------+---------------------|
44 | Left | Center | Right |
45 +---------------------+---------------------+---------------------+";
46 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(expected, "\n".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). &table.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
47 }