| 1 | use comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::{ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::*, 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 superrust-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 | fn get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().() -> Tablerust-analyzer cargo comfy-table 7.2.2 table/Table# { |
| 7 | 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().(); |
| 8 | table |
| 9 | .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!!["smol", "Header2", "Header3"]) |
| 10 | .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!![ |
| 11 | "smol", |
| 12 | "This is another text", |
| 13 | "This is the third text", |
| 14 | ]) |
| 15 | .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!![ |
| 16 | "smol", |
| 17 | "Now\nadd some\nmulti line stuff", |
| 18 | "This is awesome", |
| 19 | ]); |
| 20 | |
| 21 | table |
| 22 | } |
| 23 | |
| 24 | /// Ensure max-, min- and fixed-width constraints are respected |
| 25 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 26 | fn fixed_max_min_constraintsrust-analyzer cargo comfy-table 7.2.2 all/constraints_test/fixed_max_min_constraints().() { |
| 27 | let mut table = get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().(); |
| 28 | |
| 29 | 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!![ |
| 30 | LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(10)), |
| 31 | UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(8)), |
| 32 | Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(10)), |
| 33 | ]); |
| 34 | |
| 35 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 36 | let expected = " |
| 37 | +----------+--------+----------+ |
| 38 | | smol | Header | Header3 | |
| 39 | | | 2 | | |
| 40 | +==============================+ |
| 41 | | smol | This | This is | |
| 42 | | | is ano | the | |
| 43 | | | ther | third | |
| 44 | | | text | text | |
| 45 | |----------+--------+----------| |
| 46 | | smol | Now | This is | |
| 47 | | | add | awesome | |
| 48 | | | some | | |
| 49 | | | multi | | |
| 50 | | | line | | |
| 51 | | | stuff | | |
| 52 | +----------+--------+----------+"; |
| 53 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 54 | 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().()); |
| 55 | |
| 56 | // Now try this again when using dynamic content arrangement |
| 57 | // The table tries to arrange to 28 characters, |
| 58 | // but constraints enforce a width of at least 10+10+2+1+4 = 27 |
| 59 | // min_width + max_width + middle_padding + middle_min_width + borders |
| 60 | // Since the left and right column are fixed, the middle column should only get a width of 2 |
| 61 | table |
| 62 | .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#) |
| 63 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(28); |
| 64 | |
| 65 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 66 | let expected = " |
| 67 | +----------+----+----------+ |
| 68 | | smol | He | Header3 | |
| 69 | | | ad | | |
| 70 | | | er | | |
| 71 | | | 2 | | |
| 72 | +==========================+ |
| 73 | | smol | Th | This is | |
| 74 | | | is | the | |
| 75 | | | is | third | |
| 76 | | | an | text | |
| 77 | | | ot | | |
| 78 | | | he | | |
| 79 | | | r | | |
| 80 | | | te | | |
| 81 | | | xt | | |
| 82 | |----------+----+----------| |
| 83 | | smol | No | This is | |
| 84 | | | w | awesome | |
| 85 | | | ad | | |
| 86 | | | d | | |
| 87 | | | so | | |
| 88 | | | me | | |
| 89 | | | mu | | |
| 90 | | | lt | | |
| 91 | | | i | | |
| 92 | | | li | | |
| 93 | | | ne | | |
| 94 | | | st | | |
| 95 | | | uf | | |
| 96 | | | f | | |
| 97 | +----------+----+----------+"; |
| 98 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 99 | 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().()); |
| 100 | } |
| 101 | |
| 102 | /// Max and Min constraints won't be considered, if they are unnecessary. |
| 103 | /// This is true for normal and dynamic arrangement tables. |
| 104 | #[rstestrust-analyzer cargo rstest 0.26.1 crate/::rstestrust-analyzer cargo rstest_macros 0.26.1 rstest:] |
| 105 | #[case(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#)] |
| 106 | #[case(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Disabledrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Disabled#)] |
| 107 | fn unnecessary_max_min_constraintsrust-analyzer cargo comfy-table 7.2.2 all/constraints_test/unnecessary_max_min_constraints().(#[case] arrangement: ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#) { |
| 108 | let mut table = get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().(); |
| 109 | |
| 110 | table |
| 111 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(80) |
| 112 | .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!![LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(1)), UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(30))]) |
| 113 | .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(arrangement); |
| 114 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 115 | let expected = " |
| 116 | +------+----------------------+------------------------+ |
| 117 | | smol | Header2 | Header3 | |
| 118 | +======================================================+ |
| 119 | | smol | This is another text | This is the third text | |
| 120 | |------+----------------------+------------------------| |
| 121 | | smol | Now | This is awesome | |
| 122 | | | add some | | |
| 123 | | | multi line stuff | | |
| 124 | +------+----------------------+------------------------+"; |
| 125 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 126 | 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().()); |
| 127 | } |
| 128 | |
| 129 | /// The user can specify constraints that result in bigger width than actually provided |
| 130 | /// This is allowed, but results in a wider table than actually aimed for. |
| 131 | /// Anyway we still try to fit everything as good as possible, which of course breaks stuff. |
| 132 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 133 | fn constraints_bigger_than_table_widthrust-analyzer cargo comfy-table 7.2.2 all/constraints_test/constraints_bigger_than_table_width().() { |
| 134 | let mut table = get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().(); |
| 135 | |
| 136 | table |
| 137 | .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#) |
| 138 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(28) |
| 139 | .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!![ |
| 140 | UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(50)), |
| 141 | LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(30)), |
| 142 | ContentWidthrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#ContentWidth#, |
| 143 | ]); |
| 144 | |
| 145 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 146 | let expected = " |
| 147 | +---+------------------------------+------------------------+ |
| 148 | | s | Header2 | Header3 | |
| 149 | | m | | | |
| 150 | | o | | | |
| 151 | | l | | | |
| 152 | +===========================================================+ |
| 153 | | s | This is another text | This is the third text | |
| 154 | | m | | | |
| 155 | | o | | | |
| 156 | | l | | | |
| 157 | |---+------------------------------+------------------------| |
| 158 | | s | Now | This is awesome | |
| 159 | | m | add some | | |
| 160 | | o | multi line stuff | | |
| 161 | | l | | | |
| 162 | +---+------------------------------+------------------------+"; |
| 163 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 164 | 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().()); |
| 165 | } |
| 166 | |
| 167 | /// Test correct usage of the Percentage constraint. |
| 168 | /// Percentage allows to set a fixed width. |
| 169 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 170 | fn percentagerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/percentage().() { |
| 171 | let mut table = get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().(); |
| 172 | |
| 173 | // Set a percentage of 20% for the first column. |
| 174 | // The the rest should arrange accordingly. |
| 175 | table |
| 176 | .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#) |
| 177 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(40) |
| 178 | .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!![Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(20))]); |
| 179 | |
| 180 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 181 | let expected = " |
| 182 | +-------+---------------+--------------+ |
| 183 | | smol | Header2 | Header3 | |
| 184 | +======================================+ |
| 185 | | smol | This is | This is the | |
| 186 | | | another text | third text | |
| 187 | |-------+---------------+--------------| |
| 188 | | smol | Now | This is | |
| 189 | | | add some | awesome | |
| 190 | | | multi line | | |
| 191 | | | stuff | | |
| 192 | +-------+---------------+--------------+"; |
| 193 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 194 | 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().()); |
| 195 | } |
| 196 | |
| 197 | /// A single percentage constraint should be 100% at most. |
| 198 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 199 | fn max_100_percentagerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/max_100_percentage().() { |
| 200 | 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().(); |
| 201 | table |
| 202 | .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!!["smol"]) |
| 203 | .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!!["smol"]) |
| 204 | .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#) |
| 205 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(40) |
| 206 | .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!![Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(200))]); |
| 207 | |
| 208 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 209 | let expected = " |
| 210 | +--------------------------------------+ |
| 211 | | smol | |
| 212 | +======================================+ |
| 213 | | smol | |
| 214 | +--------------------------------------+"; |
| 215 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 216 | assert_table_line_widthrust-analyzer cargo comfy-table 7.2.2 all/assert_table_line_width().(&table, 40); |
| 217 | 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().()); |
| 218 | } |
| 219 | |
| 220 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 221 | fn percentage_secondrust-analyzer cargo comfy-table 7.2.2 all/constraints_test/percentage_second().() { |
| 222 | let mut table = get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().(); |
| 223 | |
| 224 | table |
| 225 | .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#) |
| 226 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(40) |
| 227 | .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!![ |
| 228 | LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(40)), |
| 229 | UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(30)), |
| 230 | Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(30)), |
| 231 | ]); |
| 232 | |
| 233 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 234 | let expected = " |
| 235 | +--------------+----------+----------+ |
| 236 | | smol | Header2 | Header3 | |
| 237 | +====================================+ |
| 238 | | smol | This is | This is | |
| 239 | | | another | the | |
| 240 | | | text | third | |
| 241 | | | | text | |
| 242 | |--------------+----------+----------| |
| 243 | | smol | Now | This is | |
| 244 | | | add some | awesome | |
| 245 | | | multi | | |
| 246 | | | line | | |
| 247 | | | stuff | | |
| 248 | +--------------+----------+----------+"; |
| 249 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 250 | 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().()); |
| 251 | } |
| 252 | |
| 253 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 254 | fn max_percentagerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/max_percentage().() { |
| 255 | let mut table = get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().(); |
| 256 | |
| 257 | table |
| 258 | .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#) |
| 259 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(40) |
| 260 | .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!![ |
| 261 | ContentWidthrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#ContentWidth#, |
| 262 | UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(30)), |
| 263 | Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(30)), |
| 264 | ]); |
| 265 | |
| 266 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 267 | let expected = " |
| 268 | +------+----------+----------+ |
| 269 | | smol | Header2 | Header3 | |
| 270 | +============================+ |
| 271 | | smol | This is | This is | |
| 272 | | | another | the | |
| 273 | | | text | third | |
| 274 | | | | text | |
| 275 | |------+----------+----------| |
| 276 | | smol | Now | This is | |
| 277 | | | add some | awesome | |
| 278 | | | multi | | |
| 279 | | | line | | |
| 280 | | | stuff | | |
| 281 | +------+----------+----------+"; |
| 282 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 283 | 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().()); |
| 284 | } |
| 285 | |
| 286 | /// Ensure that both min and max in [Boundaries] is respected |
| 287 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 288 | fn min_max_boundaryrust-analyzer cargo comfy-table 7.2.2 all/constraints_test/min_max_boundary().() { |
| 289 | let mut table = get_constraint_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/get_constraint_table().(); |
| 290 | |
| 291 | table |
| 292 | .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#) |
| 293 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(40) |
| 294 | .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!![ |
| 295 | Boundariesrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries# { |
| 296 | lowerrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries#lower.: Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(50), |
| 297 | upperrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries#upper.: Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(2), |
| 298 | }, |
| 299 | Boundariesrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries# { |
| 300 | lowerrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries#lower.: Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(15), |
| 301 | upperrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries#upper.: Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(50), |
| 302 | }, |
| 303 | Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(30)), |
| 304 | ]); |
| 305 | |
| 306 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 307 | let expected = " |
| 308 | +------------------+---------------+----------+ |
| 309 | | smol | Header2 | Header3 | |
| 310 | +=============================================+ |
| 311 | | smol | This is | This is | |
| 312 | | | another text | the | |
| 313 | | | | third | |
| 314 | | | | text | |
| 315 | |------------------+---------------+----------| |
| 316 | | smol | Now | This is | |
| 317 | | | add some | awesome | |
| 318 | | | multi line | | |
| 319 | | | stuff | | |
| 320 | +------------------+---------------+----------+"; |
| 321 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 322 | 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().()); |
| 323 | } |
| 324 | |
| 325 | /// Empty table with zero width constraint. |
| 326 | #[rstestrust-analyzer cargo rstest 0.26.1 crate/::rstestrust-analyzer cargo rstest_macros 0.26.1 rstest:] |
| 327 | #[case(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#)] |
| 328 | #[case(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Disabledrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Disabled#)] |
| 329 | fn empty_tablerust-analyzer cargo comfy-table 7.2.2 all/constraints_test/empty_table().(#[case] arrangement: ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#) { |
| 330 | 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().(); |
| 331 | table |
| 332 | .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!![""]) |
| 333 | .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(arrangement) |
| 334 | .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!![Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(0))]); |
| 335 | |
| 336 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 337 | let expected = " |
| 338 | +---+ |
| 339 | | | |
| 340 | +---+"; |
| 341 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 342 | 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().()); |
| 343 | } |
| 344 | |
| 345 | /// Test that successive `Fixed` `LowerBoundary` constraints are respected. |
| 346 | /// |
| 347 | /// This covers the edge-case that a later column enforces a lower-boundary |
| 348 | /// constraint, resulting in the average space for the remaining columns to shrink significantly. |
| 349 | /// This should then result in the other columns to be fixed as well. |
| 350 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 351 | fn lower_fixed_boundaryrust-analyzer cargo comfy-table 7.2.2 all/constraints_test/lower_fixed_boundary().() { |
| 352 | 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().(); |
| 353 | table |
| 354 | .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!!["123", "123", "1234", "1234567891234"]) |
| 355 | .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#) |
| 356 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(33); |
| 357 | |
| 358 | table |
| 359 | .column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(2) |
| 360 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 361 | .set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(5))); |
| 362 | |
| 363 | table |
| 364 | .column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(3) |
| 365 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 366 | .set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(14))); |
| 367 | |
| 368 | let expected = " |
| 369 | +-----+----+-----+--------------+ |
| 370 | | 123 | 12 | 123 | 123456789123 | |
| 371 | | | 3 | 4 | 4 | |
| 372 | +-----+----+-----+--------------+"; |
| 373 | |
| 374 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 375 | 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().()); |
| 376 | } |
| 377 | |
| 378 | /// Test that `LowerBoundary` constraints are respected, even if a split would result in |
| 379 | /// a smaller size. |
| 380 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 381 | fn lower_fixed_boundary_with_splitrust-analyzer cargo comfy-table 7.2.2 all/constraints_test/lower_fixed_boundary_with_split().() { |
| 382 | 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().(); |
| 383 | table |
| 384 | .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!!["123", "123", "123 343"]) |
| 385 | .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#) |
| 386 | .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(5); |
| 387 | |
| 388 | table |
| 389 | .column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(2) |
| 390 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() |
| 391 | .set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(6))); |
| 392 | |
| 393 | let expected = " |
| 394 | +---+---+------+ |
| 395 | | 1 | 1 | 123 | |
| 396 | | 2 | 2 | 343 | |
| 397 | | 3 | 3 | | |
| 398 | +---+---+------+"; |
| 399 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}"); |
| 400 | 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().()); |
| 401 | } |