| 1 | use comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::{ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::*, ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#, Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#, Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#, Widthrust-analyzer cargo comfy-table 7.2.2 style/column/Width#::*}; |
| 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 | use craterust-analyzer cargo comfy-table 7.2.2 crate/::allrust-analyzer cargo comfy-table 7.2.2 all/::assert_table_line_widthrust-analyzer cargo comfy-table 7.2.2 all/assert_table_line_width().; |
| 5 | |
| 6 | /// Individual rows can be configured to have a max height. |
| 7 | /// Everything beyond that line height should be truncated. |
| 8 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 9 | fn table_with_truncaterust-analyzer cargo comfy-table 7.2.2 all/truncation/table_with_truncate().() { |
| 10 | 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().(); |
| 11 | let mut first_row: Rowrust-analyzer cargo comfy-table 7.2.2 row/Row# = Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#::fromrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row][`From<T>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 12 | "This is a very long line with a lot of text", |
| 13 | "This is anotherverylongtextwithlongwords text", |
| 14 | "smol", |
| 15 | ]); |
| 16 | first_row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(4); |
| 17 | |
| 18 | let mut second_row = Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#::fromrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row][`From<T>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 19 | "Now let's\nadd a really long line in the middle of the cell \n and add more multi line stuff", |
| 20 | "This is another text", |
| 21 | "smol", |
| 22 | ]); |
| 23 | second_row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(4); |
| 24 | |
| 25 | table |
| 26 | .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", "Head"]) |
| 27 | .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#) |
| 28 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(35) |
| 29 | .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(first_row) |
| 30 | .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(second_row); |
| 31 | |
| 32 | // The first column will be wider than 6 chars. |
| 33 | // The second column's content is wider than 6 chars. There should be a '...'. |
| 34 | let second_column = table.column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 35 | second_column.set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(8))); |
| 36 | |
| 37 | // The third column's content is less than 6 chars width. There shouldn't be a '...'. |
| 38 | let third_column = table.column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 39 | third_column.set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(7))); |
| 40 | |
| 41 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 42 | let expected = " |
| 43 | +----------------+--------+-------+ |
| 44 | | Header1 | Header | Head | |
| 45 | | | 2 | | |
| 46 | +=================================+ |
| 47 | | This is a very | This | smol | |
| 48 | | long line with | is ano | | |
| 49 | | a lot of text | therve | | |
| 50 | | | ryl... | | |
| 51 | |----------------+--------+-------| |
| 52 | | Now let's | This | smol | |
| 53 | | add a really | is ano | | |
| 54 | | long line in | ther | | |
| 55 | | the middle ... | text | | |
| 56 | +----------------+--------+-------+"; |
| 57 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 58 | assert_table_line_widthrust-analyzer cargo comfy-table 7.2.2 all/assert_table_line_width().(&table, 35); |
| 59 | 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().()); |
| 60 | } |
| 61 | |
| 62 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 63 | fn table_with_truncate_indicatorrust-analyzer cargo comfy-table 7.2.2 all/truncation/table_with_truncate_indicator().() { |
| 64 | 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().(); |
| 65 | let mut first_row: Rowrust-analyzer cargo comfy-table 7.2.2 row/Row# = Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#::fromrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row][`From<T>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 66 | "This is a very long line with a lot of text", |
| 67 | "This is anotherverylongtextwithlongwords text", |
| 68 | "smol", |
| 69 | ]); |
| 70 | first_row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(4); |
| 71 | |
| 72 | let mut second_row = Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#::fromrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row][`From<T>`]from().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 73 | "Now let's\nadd a really long line in the middle of the cell \n and add more multi line stuff", |
| 74 | "This is another text", |
| 75 | "smol", |
| 76 | ]); |
| 77 | second_row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(4); |
| 78 | |
| 79 | table |
| 80 | .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", "Head"]) |
| 81 | .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 | .set_truncation_indicatorrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_truncation_indicator().("…") |
| 83 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(35) |
| 84 | .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(first_row) |
| 85 | .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(second_row); |
| 86 | |
| 87 | // The first column will be wider than 6 chars. |
| 88 | // The second column's content is wider than 6 chars. There should be a '…'. |
| 89 | let second_column = table.column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 90 | second_column.set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(8))); |
| 91 | |
| 92 | // The third column's content is less than 6 chars width. There shouldn't be a '…'. |
| 93 | let third_column = table.column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 94 | third_column.set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(7))); |
| 95 | |
| 96 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 97 | let expected = " |
| 98 | +----------------+--------+-------+ |
| 99 | | Header1 | Header | Head | |
| 100 | | | 2 | | |
| 101 | +=================================+ |
| 102 | | This is a very | This | smol | |
| 103 | | long line with | is ano | | |
| 104 | | a lot of text | therve | | |
| 105 | | | rylon… | | |
| 106 | |----------------+--------+-------| |
| 107 | | Now let's | This | smol | |
| 108 | | add a really | is ano | | |
| 109 | | long line in | ther | | |
| 110 | | the middle of… | text | | |
| 111 | +----------------+--------+-------+"; |
| 112 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 113 | assert_table_line_widthrust-analyzer cargo comfy-table 7.2.2 all/assert_table_line_width().(&table, 35); |
| 114 | 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().()); |
| 115 | } |
| 116 | |
| 117 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 118 | fn table_with_composite_utf8_stringsrust-analyzer cargo comfy-table 7.2.2 all/truncation/table_with_composite_utf8_strings().() { |
| 119 | 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().(); |
| 120 | |
| 121 | table |
| 122 | .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"]) |
| 123 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(20) |
| 124 | .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!!["あいうえおかきくけこさしすせそたちつてと"]) |
| 125 | .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#); |
| 126 | |
| 127 | for row in table.row_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_iter_mut().() { |
| 128 | row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(1); // 2 -> also panics, 3 -> ok |
| 129 | } |
| 130 | |
| 131 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 132 | let expected = " |
| 133 | +------------------+ |
| 134 | | Header1 | |
| 135 | +==================+ |
| 136 | | あいうえおか... | |
| 137 | +------------------+"; |
| 138 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 139 | assert_table_line_widthrust-analyzer cargo comfy-table 7.2.2 all/assert_table_line_width().(&table, 20); |
| 140 | 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().()); |
| 141 | } |
| 142 | |
| 143 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 144 | fn table_with_composite_utf8_strings_2_linesrust-analyzer cargo comfy-table 7.2.2 all/truncation/table_with_composite_utf8_strings_2_lines().() { |
| 145 | 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().(); |
| 146 | |
| 147 | table |
| 148 | .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"]) |
| 149 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(20) |
| 150 | .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!!["あいうえおかきくけこさしすせそたちつてと"]) |
| 151 | .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#); |
| 152 | |
| 153 | for row in table.row_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_iter_mut().() { |
| 154 | row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(2); |
| 155 | } |
| 156 | |
| 157 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 158 | let expected = " |
| 159 | +------------------+ |
| 160 | | Header1 | |
| 161 | +==================+ |
| 162 | | あいうえおかきく | |
| 163 | | けこさしすせ... | |
| 164 | +------------------+"; |
| 165 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 166 | assert_table_line_widthrust-analyzer cargo comfy-table 7.2.2 all/assert_table_line_width().(&table, 20); |
| 167 | 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().()); |
| 168 | } |
| 169 | |
| 170 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 171 | fn table_with_composite_utf8_emojisrust-analyzer cargo comfy-table 7.2.2 all/truncation/table_with_composite_utf8_emojis().() { |
| 172 | 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().(); |
| 173 | |
| 174 | table |
| 175 | .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"]) |
| 176 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(15) |
| 177 | .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!![ |
| 178 | "🙂↕️🙂↕️🙂↕️🙂↕️🙂↕️🙂↕️last_line.into_bytes().truncate(truncate_at)", |
| 179 | ]) |
| 180 | .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#); |
| 181 | |
| 182 | for row in table.row_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_iter_mut().() { |
| 183 | row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(1); // 2 -> also panics, 3 -> ok |
| 184 | } |
| 185 | |
| 186 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 187 | let expected = " |
| 188 | +-------------+ |
| 189 | | Header1 | |
| 190 | +=============+ |
| 191 | | 🙂↕️🙂↕️🙂↕️🙂↕️... | |
| 192 | +-------------+"; |
| 193 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 194 | assert_table_line_widthrust-analyzer cargo comfy-table 7.2.2 all/assert_table_line_width().(&table, 15); |
| 195 | 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().()); |
| 196 | } |