| 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 | fn get_tablerust-analyzer cargo comfy-table 7.2.2 all/hidden_test/get_table().() -> Tablerust-analyzer cargo comfy-table 7.2.2 table/Table# { |
| 5 | 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().(); |
| 6 | table |
| 7 | .load_presetrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]load_preset().(presetsrust-analyzer cargo comfy-table 7.2.2 style/presets/::UTF8_FULLrust-analyzer cargo comfy-table 7.2.2 style/presets/UTF8_FULL.) |
| 8 | .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!![ |
| 9 | "hidden_header", |
| 10 | "smol", |
| 11 | "hidden_header", |
| 12 | "Two_hidden_headers_in_a_row", |
| 13 | "Header2", |
| 14 | "Header3", |
| 15 | "hidden_header", |
| 16 | ]) |
| 17 | .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!![ |
| 18 | "start_hidden", |
| 19 | "smol", |
| 20 | "middle_hidden", |
| 21 | "two_hidden_headers_in_a_row", |
| 22 | "This is another text", |
| 23 | "This is the third text", |
| 24 | "end_hidden", |
| 25 | ]) |
| 26 | .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!![ |
| 27 | "asdf", |
| 28 | "smol", |
| 29 | "asdf", |
| 30 | "asdf", |
| 31 | "Now\nadd some\nmulti line stuff", |
| 32 | "This is awesome", |
| 33 | "asdf", |
| 34 | ]); |
| 35 | |
| 36 | // Hide the first, third and 6th column |
| 37 | table |
| 38 | .column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(0) |
| 39 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 40 | .set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#); |
| 41 | table |
| 42 | .column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(2) |
| 43 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 44 | .set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#); |
| 45 | table |
| 46 | .column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(3) |
| 47 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 48 | .set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#); |
| 49 | |
| 50 | table |
| 51 | .column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(6) |
| 52 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 53 | .set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#); |
| 54 | |
| 55 | table |
| 56 | } |
| 57 | |
| 58 | /// Make sure hidden columns won't be displayed |
| 59 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 60 | fn hidden_columnsrust-analyzer cargo comfy-table 7.2.2 all/hidden_test/hidden_columns().() { |
| 61 | let table = get_tablerust-analyzer cargo comfy-table 7.2.2 all/hidden_test/get_table().(); |
| 62 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 63 | let expected = " |
| 64 | ┌──────┬──────────────────────┬────────────────────────┐ |
| 65 | │ smol ┆ Header2 ┆ Header3 │ |
| 66 | ╞══════╪══════════════════════╪════════════════════════╡ |
| 67 | │ smol ┆ This is another text ┆ This is the third text │ |
| 68 | ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ |
| 69 | │ smol ┆ Now ┆ This is awesome │ |
| 70 | │ ┆ add some ┆ │ |
| 71 | │ ┆ multi line stuff ┆ │ |
| 72 | └──────┴──────────────────────┴────────────────────────┘"; |
| 73 | 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().()); |
| 74 | } |
| 75 | |
| 76 | /// Make sure dynamic adjustment still works with hidden columns |
| 77 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 78 | fn hidden_columns_with_dynamic_adjustmentrust-analyzer cargo comfy-table 7.2.2 all/hidden_test/hidden_columns_with_dynamic_adjustment().() { |
| 79 | let mut table = get_tablerust-analyzer cargo comfy-table 7.2.2 all/hidden_test/get_table().(); |
| 80 | table.set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(25); |
| 81 | table.set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#); |
| 82 | |
| 83 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 84 | let expected = " |
| 85 | ┌──────┬────────┬───────┐ |
| 86 | │ smol ┆ Header ┆ Heade │ |
| 87 | │ ┆ 2 ┆ r3 │ |
| 88 | ╞══════╪════════╪═══════╡ |
| 89 | │ smol ┆ This ┆ This │ |
| 90 | │ ┆ is ano ┆ is │ |
| 91 | │ ┆ ther ┆ the │ |
| 92 | │ ┆ text ┆ third │ |
| 93 | │ ┆ ┆ text │ |
| 94 | ├╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ |
| 95 | │ smol ┆ Now ┆ This │ |
| 96 | │ ┆ add ┆ is │ |
| 97 | │ ┆ some ┆ aweso │ |
| 98 | │ ┆ multi ┆ me │ |
| 99 | │ ┆ line ┆ │ |
| 100 | │ ┆ stuff ┆ │ |
| 101 | └──────┴────────┴───────┘"; |
| 102 | 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().()); |
| 103 | } |
| 104 | |
| 105 | /// Nothing breaks, if all columns are hidden |
| 106 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 107 | fn only_hidden_columnsrust-analyzer cargo comfy-table 7.2.2 all/hidden_test/only_hidden_columns().() { |
| 108 | let mut table = get_tablerust-analyzer cargo comfy-table 7.2.2 all/hidden_test/get_table().(); |
| 109 | table.set_constraintsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_constraints().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 110 | ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#, |
| 111 | ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#, |
| 112 | ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#, |
| 113 | ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#, |
| 114 | ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#, |
| 115 | ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#, |
| 116 | ]); |
| 117 | |
| 118 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 119 | let expected = " |
| 120 | ┌┐ |
| 121 | ╞╡ |
| 122 | ├┤ |
| 123 | └┘"; |
| 124 | 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().()); |
| 125 | } |