Debian Codegraph @

tests/all/property_test.rs

raw symbols SCIP
1 use ::proptestrust-analyzer cargo proptest 1.9.0 crate/::preluderust-analyzer cargo proptest 1.9.0 prelude/::*;
2 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#::*, *};
3
4 /// Pick any of the three existing ContentArrangement types for the table.
5 fn content_arrangementrust-analyzer cargo comfy-table 7.2.2 all/property_test/content_arrangement().() -> impl Strategyrust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#Value# = ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#> {
6 prop_oneofrust-analyzer cargo proptest 1.9.0 sugar/prop_oneof!![
7 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Disabledrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Disabled#),
8 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#),
9 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::DynamicFullWidthrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#DynamicFullWidth#),
10 ]
11 }
12
13 /// Each cell can have any alignment.
14 fn cell_alignmentrust-analyzer cargo comfy-table 7.2.2 all/property_test/cell_alignment().() -> impl Strategyrust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#Value# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#>> {
15 prop_oneofrust-analyzer cargo proptest 1.9.0 sugar/prop_oneof!![
16 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
17 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Leftrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Left#)),
18 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#::Rightrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#Right#)),
19 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(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 }
22
23 /// Any Column can have any constellation of ColumnConstraints
24 fn column_constraintrust-analyzer cargo comfy-table 7.2.2 all/property_test/column_constraint().() -> impl Strategyrust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#Value# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#>> {
25 prop_oneofrust-analyzer cargo proptest 1.9.0 sugar/prop_oneof!![
26 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
27 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::ContentWidthrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#ContentWidth#)),
28 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#)),
29 anyrust-analyzer cargo proptest 1.9.0 arbitrary/traits/any().::<u16>().prop_maprust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#prop_map().(|width| { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(width))) }),
30 anyrust-analyzer cargo proptest 1.9.0 arbitrary/traits/any().::<u16>().prop_maprust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#prop_map().(|width| { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(width))) }),
31 anyrust-analyzer cargo proptest 1.9.0 arbitrary/traits/any().::<u16>().prop_maprust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#prop_map().(|width| { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(Fixedrust-analyzer cargo comfy-table 7.2.2 style/column/Width#Fixed#(width))) }),
32 (0u16..200u16).prop_maprust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#prop_map().(|percentage| { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(percentage))) }),
33 (0u16..200u16).prop_maprust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#prop_map().(|percentage| { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(percentage))) }),
34 (0u16..200u16).prop_maprust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#prop_map().(|percentage| { Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(Percentagerust-analyzer cargo comfy-table 7.2.2 style/column/Width#Percentage#(percentage))) }),
35 ]
36 }
37
38 /// We test the Row::max_height with a few values.
39 fn max_heightrust-analyzer cargo comfy-table 7.2.2 all/property_test/max_height().() -> impl Strategyrust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#Value# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>> {
40 prop_oneofrust-analyzer cargo proptest 1.9.0 sugar/prop_oneof!![
41 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
42 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)),
43 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1)),
44 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(5)),
45 Justrust-analyzer cargo proptest 1.9.0 strategy/just/Just#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(100))
46 ]
47 }
48
49 prop_composerust-analyzer cargo proptest 1.9.0 sugar/prop_compose!! {
50 /// Returns the dimensions of the table, i.e. the amount of rows and columns.
51 fn dimensionsrust-analyzer cargo comfy-table 7.2.2 all/property_test/dimensions().()(columns in 1u16..10u16, rows in 1u16..10u16)
52 -> (u16, u16) {
53 (columns, rows)
54 }
55 }
56
57 /// Returns all data needed to build the final table.
58 /// 1. A matrix of cells Row[Column[Cell]].
59 /// 2. Constraints for all columns.
60 /// 3. The alignment for each cell.
61 /// 3. The alignment for each column.
62 #[allow(clippy::type_complexity)]
63 fn columns_and_rowsrust-analyzer cargo comfy-table 7.2.2 all/property_test/columns_and_rows().() -> impl Strategyrust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#<
64 Valuerust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#Value# = (
65 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>,
66 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#>>,
67 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#>>,
68 Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<CellAlignmentrust-analyzer cargo comfy-table 7.2.2 style/cell/CellAlignment#>>,
69 ),
70 > {
71 dimensionsrust-analyzer cargo comfy-table 7.2.2 all/property_test/dimensions().().prop_flat_maprust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#prop_flat_map().(|(column_count, row_count)| {
72 let mut rows = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
73 let mut cell_alignments = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
74 for _i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#row_count {
75 // Create the max amount of possibly needed cell alignments
76 for _j in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#column_count {
77 cell_alignments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(cell_alignmentrust-analyzer cargo comfy-table 7.2.2 all/property_test/cell_alignment().());
78 }
79 // Add a strategy that creates random cell content with a length of 0 to column_count
80 //
81 // UTF-8 characters completely break table alignment in edge-case situations (e.g. 1
82 // space columns). UTF-8 characters can be multiple characters wide, which
83 // conflicts with the 1 space column fallback, as well as fixed-width-,
84 // percental- and max-column-constraints. As a result, we cannot check this
85 // with proptest, as this is inherently broken.
86 rows.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(::proptestrust-analyzer cargo proptest 1.9.0 crate/::collectionrust-analyzer cargo proptest 1.9.0 collection/::vecrust-analyzer cargo proptest 1.9.0 collection/vec().(
87 "[A-Za-z_]*",
88 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#column_count as usize,
89 ));
90 }
91 let mut constraints = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
92 let mut column_alignments = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
93 for _i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#column_count {
94 constraints.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(column_constraintrust-analyzer cargo comfy-table 7.2.2 all/property_test/column_constraint().());
95 column_alignments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(cell_alignmentrust-analyzer cargo comfy-table 7.2.2 all/property_test/cell_alignment().());
96 }
97
98 (rows, constraints, cell_alignments, column_alignments)
99 })
100 }
101
102 /// We test the Row::max_height with a few values.
103 fn table_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/table_width().() -> impl Strategyrust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#<Valuerust-analyzer cargo proptest 1.9.0 strategy/traits/Strategy#Value# = u16> {
104 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1000u16
105 }
106
107 prop_composerust-analyzer cargo proptest 1.9.0 sugar/prop_compose!! {
108 /// The ultimate test
109 /// This creates a table from a combination of all "random" selectors above.
110 fn tablerust-analyzer cargo comfy-table 7.2.2 all/property_test/table().()
111 (arrangement in content_arrangementrust-analyzer cargo comfy-table 7.2.2 all/property_test/content_arrangement().(),
112 max_height in max_heightrust-analyzer cargo comfy-table 7.2.2 all/property_test/max_height().(),
113 (rows, constraints, cell_alignments, column_alignments) in columns_and_rowsrust-analyzer cargo comfy-table 7.2.2 all/property_test/columns_and_rows().()) -> Tablerust-analyzer cargo comfy-table 7.2.2 table/Table# {
114
115 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().();
116 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(height) = max_height {
117 for row in table.row_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_iter_mut().() {
118 row.max_heightrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_height().(height);
119 }
120 }
121
122 let mut cell_alignments = cell_alignments.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
123 for row in rows.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
124 // Convert a vector of Strings to a vector of Cells and
125 // set the content alignment for each cell
126 let row: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#> = row.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|content| {
127 let mut cell = Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#::newrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]new().(content.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().());
128 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(alignment) = cell_alignments.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() {
129 cell = cell.set_alignmentrust-analyzer cargo comfy-table 7.2.2 cell/impl#[Cell]set_alignment().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().alignment);
130 }
131 cell
132 }).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
133
134 // Add the row to the table
135 table.add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(row);
136 }
137
138 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().() {
139 // Add the alignment for all columns
140 let alignment = column_alignments.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().();
141 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(alignment) = alignment {
142 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);
143 }
144
145 // Set constraints for all columns
146 let constraint = constraints.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().();
147 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(constraint) = constraint {
148 column.set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().constraint);
149 }
150
151 }
152
153 table.set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(arrangement);
154 table
155 }
156 }
157
158 proptestrust-analyzer cargo proptest 1.9.0 sugar/proptest!! {
159 #![proptest_config({
160 let mut config = ProptestConfigrust-analyzer cargo proptest 1.9.0 test_runner/config/Config#::with_casesrust-analyzer cargo proptest 1.9.0 test_runner/config/impl#[Config]with_cases().(512);
161 config.max_shrink_itersrust-analyzer cargo proptest 1.9.0 test_runner/config/Config#max_shrink_iters. = 5000;
162 config
163 })]
164 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
165 fn random_tablesrust-analyzer cargo comfy-table 7.2.2 all/property_test/random_tables().(mut table in tablerust-analyzer cargo comfy-table 7.2.2 all/property_test/table().(), table_width in table_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/table_width().()) {
166 table.set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(table_width);
167
168 // Make sure the table builds without any panics
169 let formatted = table.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
170
171 // We'll take a look at each individual line to ensure they all share some properties.
172 let lines: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = formatted.split_terminatorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_terminator().('\n').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|line| line.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
173 let mut line_iter = lines.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
174
175 // ----- Table width check ------
176
177 // Get the length of the very first line.
178 // We're lateron going to ensure, that all lines have the same length.
179 let line_length = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(line) = line_iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]next().() {
180 line.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()
181 } else {
182 0
183 };
184
185 // Make sure all lines have the same length
186 for line in line_iter {
187 if line.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() != line_length {
188 return build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(&formatted, "Each line of a printed table has to have the same length!");
189 }
190 }
191
192 // Make sure that the table is within its width, if arrangement isn't enabled.
193 // This is a bit tricky.
194 // A table can be larger than the specified width, if the user forces it to be larger.
195 #[cfg(feature = "_integration_test")]
196 {
197 let current_arrangement = table.content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]content_arrangement().();
198 match current_arrangement {
199 ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Disabledrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Disabled# => (),
200 _ => {
201 let expected_max = determine_max_table_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/determine_max_table_width().(&table);
202
203 // A line can be a bit longer than u16::MAX due to formatting and borders.
204 let actual: u16 = line_length.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(u16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]MAX.);
205 if actual >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]gt(). expected_max {
206 return build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(
207 &formatted,
208 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Expected table to be smaller than line length!\n\
209 Actual: {actual}, Expected max: {expected_max}\n\
210 Arrangement: {current_arrangement:?}"
211 ));
212 }
213 }
214 }
215 }
216
217 #[cfg(feature = "_integration_test")]
218 // Only run this test, if the `integration_test` is enabled.
219 // Without this flag, we don't have access to some util functions in comfy_table, that
220 // aren't exposed by default.
221 enforce_constraintsrust-analyzer cargo comfy-table 7.2.2 all/property_test/enforce_constraints().(&table, formatted, lines)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().
222 }
223 }
224
225 fn build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(table: &str, context: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TestCaseErrorrust-analyzer cargo proptest 1.9.0 test_runner/errors/TestCaseError#> {
226 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(TestCaseErrorrust-analyzer cargo proptest 1.9.0 test_runner/errors/TestCaseError#::Failrust-analyzer cargo proptest 1.9.0 test_runner/errors/TestCaseError#Fail#(
227 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("\n{context}:\n{table}\n").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
228 ))
229 }
230
231 /// The user can actually force a table to be longer than the specified `table.width()`
232 /// by specifying [ColumnConstraint]s.
233 #[cfg(feature = "_integration_test")]
234 fn determine_max_table_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/determine_max_table_width().(table: &Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#) -> u16 {
235 use comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::utilsrust-analyzer cargo comfy-table 7.2.2 utils/::arrangementrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/::helperrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/::count_border_columnsrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/count_border_columns().;
236 let table_width = table.widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]width().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
237
238 // The max value that will be enforced by constraints.
239 // We start with `2` for the side borders.
240 let visible_columns = table
241 .column_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter().()
242 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|column| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().column.is_hiddenrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]is_hidden().())
243 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().();
244
245 // Initialize the value for the min width enforced by constraints.
246 // Borders may exist, but they are not included in constraints, which is why we have to
247 // explicitly add them.
248 let mut constraint_min_width: u16 = count_border_columnsrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/helper/count_border_columns().(table, visible_columns)
249 .try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()
250 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(u16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]MAX.);
251
252 // Get the max content widths for each column.
253 // This is necessary for the `ContentWidth` constraint.
254 let max_content_widths = table.column_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_max_content_widths().();
255
256 // Calculate the enforced widths by any constraints.
257 for (index, column) in table.column_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
258 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(constraint) = column.constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]constraint().() {
259 match constraint {
260 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::ContentWidthrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#ContentWidth# => {
261 constraint_min_width = constraint_min_width
262 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(max_content_widths[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().)
263 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(column.padding_widthrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]padding_width().());
264 }
265 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(width) => {
266 constraint_min_width = constraint_min_width
267 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table, width))
268 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(column.padding_widthrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]padding_width().());
269 }
270 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(width)
271 | ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Boundariesrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries# { lowerrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries#lower.: width, .. } => {
272 constraint_min_width = constraint_min_width
273 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table, width))
274 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(column.padding_widthrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]padding_width().());
275 }
276 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden# => {}
277 _ => {
278 // Add the padding and the min-width of `1` for this column
279 constraint_min_width = constraint_min_width
280 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(column.padding_widthrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]padding_width().())
281 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(1);
282 }
283 }
284 } else {
285 // Add the padding + 1 space for all columns without constraints.
286 constraint_min_width = constraint_min_width
287 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(column.padding_widthrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]padding_width().())
288 .saturating_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]saturating_add().(1);
289 }
290 }
291
292 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(table_width, constraint_min_width)
293 }
294
295 /// Enforce that Column constraints are enforced as expected in `Dynamic` mode.
296 #[cfg(feature = "_integration_test")]
297 fn enforce_constraintsrust-analyzer cargo comfy-table 7.2.2 all/property_test/enforce_constraints().(
298 table: &Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#,
299 formatted: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
300 lines: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
301 ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), TestCaseErrorrust-analyzer cargo proptest 1.9.0 test_runner/errors/TestCaseError#> {
302 let content_arrangement = table.content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]content_arrangement().();
303 // Don't run the following for disabled or full-width arrangement.
304 // These constraints kind of mess with all kinds of assertions we can make, which is why we
305 // skip them.
306 match content_arrangement {
307 ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic# => (),
308 _ => return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()),
309 }
310
311 // Extract the constraints for each table
312 // Also remove hidden columns
313 let constraints: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#>> = table
314 .column_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter().()
315 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|col| col.constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]constraint().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().())
316 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|constraint| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(constraint, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden#)))
317 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
318
319 let line_iter = lines.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().();
320
321 for line in line_iter {
322 // Split the line along the column delimiter.
323 // This allows us to ensure that each column is inside its constraints.
324 let line_parts: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = line.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('|').maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|col| col.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
325
326 // Skip the line if there're fewer vertical delimiters than columns + borders.
327 // If that's the case, we're currently looking at a border or a delimiter line.
328 if line_parts.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().(constraints.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().2) {
329 continue;
330 }
331
332 // The left and right borders will produce empty strings, let's filter those out.
333 let line_parts: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> = line_parts
334 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
335 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|part| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().part.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().())
336 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
337
338 for (index, (part, constraint)) in line_parts.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(constraints.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()).enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
339 let constraint = match constraint {
340 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(constraint) => constraint,
341 // No constraint, we're good to go.
342 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => continue,
343 };
344 // Get the actual length of the part.
345 let actual = part.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().();
346
347 match constraint {
348 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Hiddenrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Hidden# => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("This shouldn't happen"),
349 // No need to check, if the column can be as wide as the content.
350 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::ContentWidthrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#ContentWidth# => continue,
351 // Absolute width is defined.
352 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Absoluterust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Absolute#(absolute) => {
353 let mut expected = absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table, absolute);
354 // The minimal amount of chars per column (with default padding)
355 // is 3 chars. 2 padding + 1 char content.
356 if expected rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().3 {
357 expected = 3;
358 }
359 if actual rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().expected.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() {
360 return build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(
361 &formatted,
362 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
363 "Column {index} for should have absolute width of {expected}.\n\
364 Actual width is {actual}.\n\
365 {absolute:?} for line '{line}', part '{part}'"
366 ),
367 );
368 }
369 }
370 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::LowerBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#LowerBoundary#(lower) => {
371 let expected_lower = absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table, lower);
372 if actual rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().expected_lower.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() {
373 return build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(
374 &formatted,
375 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
376 "Column {index} has a lower bound of {expected_lower}.\n\
377 Actual width is {actual}.\n\
378 {lower:?} for line '{line}', part '{part}'"
379 ),
380 );
381 }
382 }
383 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::UpperBoundaryrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#UpperBoundary#(upper) => {
384 let mut expected_upper = absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table, upper);
385 // The minimal amount of chars per column (with default padding)
386 // is 3 chars. 2 padding + 1 char content.
387 if expected_upper rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().3 {
388 expected_upper = 3;
389 }
390
391 if actual rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().expected_upper.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() {
392 return build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(
393 &formatted,
394 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
395 "Column {index} has a upper bound of {expected_upper}.\n\
396 Actual width is {actual}.\n\
397 {upper:?} for line '{line}', part '{part}'"
398 ),
399 );
400 }
401 }
402 ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#::Boundariesrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries# { lowerrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries#lower., upperrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#Boundaries#upper. } => {
403 let expected_lower = absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table, lower);
404 let mut expected_upper = absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table, upper);
405 // The minimal amount of chars per column (with default padding)
406 // is 3 chars. 2 padding + 1 char content.
407 if expected_upper rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().3 {
408 expected_upper = 3;
409 }
410
411 if actual rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().expected_lower.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() {
412 return build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(
413 &formatted,
414 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
415 "Column {index} has a lower bound of {expected_lower}.\n\
416 Actual width is {actual}.\n\
417 {lower:?} for line '{line}', part '{part}'"
418 ),
419 );
420 }
421
422 if actual rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().expected_upper.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() {
423 return build_errorrust-analyzer cargo comfy-table 7.2.2 all/property_test/build_error().(
424 &formatted,
425 &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
426 "Column {index} has a upper bound of {expected_upper}.\n\
427 Actual width is {actual}.\n\
428 {upper:?} for line '{line}', part '{part}'"
429 ),
430 );
431 }
432 }
433 }
434 }
435 }
436
437 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
438 }
439
440 /// Resolve an absolute value from a given boundary
441 #[cfg(feature = "_integration_test")]
442 pub fn absolute_widthrust-analyzer cargo comfy-table 7.2.2 all/property_test/absolute_width().(table: &Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#, width: &Widthrust-analyzer cargo comfy-table 7.2.2 style/column/Width#) -> u16 {
443 use comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::utilsrust-analyzer cargo comfy-table 7.2.2 utils/::arrangementrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/::constraintrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/constraint/::absolute_value_from_widthrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/constraint/absolute_value_from_width().;
444
445 let visible_columns = table
446 .column_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter().()
447 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|column| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().column.is_hiddenrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]is_hidden().())
448 .countrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/filter/impl#[`Filter<I, P>`][Iterator]count().();
449
450 let computed_width = absolute_value_from_widthrust-analyzer cargo comfy-table 7.2.2 utils/arrangement/constraint/absolute_value_from_width().(table, width, visible_columns)
451 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("Expected table to have a width");
452
453 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(1, computed_width)
454 }