1*11be35a1SLionel Sambuc // Copyright 2012 Google Inc.
2*11be35a1SLionel Sambuc // All rights reserved.
3*11be35a1SLionel Sambuc //
4*11be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
5*11be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
6*11be35a1SLionel Sambuc // met:
7*11be35a1SLionel Sambuc //
8*11be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
9*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer.
10*11be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
11*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer in the
12*11be35a1SLionel Sambuc // documentation and/or other materials provided with the distribution.
13*11be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
14*11be35a1SLionel Sambuc // may be used to endorse or promote products derived from this software
15*11be35a1SLionel Sambuc // without specific prior written permission.
16*11be35a1SLionel Sambuc //
17*11be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*11be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*11be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*11be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*11be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*11be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*11be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*11be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*11be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*11be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*11be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc
29*11be35a1SLionel Sambuc #include "utils/text/table.hpp"
30*11be35a1SLionel Sambuc
31*11be35a1SLionel Sambuc #include <algorithm>
32*11be35a1SLionel Sambuc
33*11be35a1SLionel Sambuc #include <atf-c++.hpp>
34*11be35a1SLionel Sambuc
35*11be35a1SLionel Sambuc #include "utils/text/operations.ipp"
36*11be35a1SLionel Sambuc
37*11be35a1SLionel Sambuc namespace text = utils::text;
38*11be35a1SLionel Sambuc
39*11be35a1SLionel Sambuc
40*11be35a1SLionel Sambuc /// Performs a check on text::table_formatter.
41*11be35a1SLionel Sambuc ///
42*11be35a1SLionel Sambuc /// This is provided for test simplicity's sake. Having to match the result of
43*11be35a1SLionel Sambuc /// the formatting on a line by line basis would result in too verbose tests
44*11be35a1SLionel Sambuc /// (maybe not with C++11, but not using this yet).
45*11be35a1SLionel Sambuc ///
46*11be35a1SLionel Sambuc /// Because of the flattening of the formatted table into a string, we risk
47*11be35a1SLionel Sambuc /// misdetecting problems when the algorithm bundles newlines into the lines of
48*11be35a1SLionel Sambuc /// a table. This should not happen, and not accounting for this little detail
49*11be35a1SLionel Sambuc /// makes testing so much easier.
50*11be35a1SLionel Sambuc ///
51*11be35a1SLionel Sambuc /// \param expected Textual representation of the table, as a collection of
52*11be35a1SLionel Sambuc /// lines separated by newline characters.
53*11be35a1SLionel Sambuc /// \param formatter The formatter to use.
54*11be35a1SLionel Sambuc /// \param table The table to format.
55*11be35a1SLionel Sambuc static void
table_formatter_check(const std::string & expected,const text::table_formatter & formatter,const text::table & table)56*11be35a1SLionel Sambuc table_formatter_check(const std::string& expected,
57*11be35a1SLionel Sambuc const text::table_formatter& formatter,
58*11be35a1SLionel Sambuc const text::table& table)
59*11be35a1SLionel Sambuc {
60*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(expected, text::join(formatter.format(table), "\n") + "\n");
61*11be35a1SLionel Sambuc }
62*11be35a1SLionel Sambuc
63*11be35a1SLionel Sambuc
64*11be35a1SLionel Sambuc
65*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table__ncolumns);
ATF_TEST_CASE_BODY(table__ncolumns)66*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table__ncolumns)
67*11be35a1SLionel Sambuc {
68*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(5, text::table(5).ncolumns());
69*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(10, text::table(10).ncolumns());
70*11be35a1SLionel Sambuc }
71*11be35a1SLionel Sambuc
72*11be35a1SLionel Sambuc
73*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table__column_width);
ATF_TEST_CASE_BODY(table__column_width)74*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table__column_width)
75*11be35a1SLionel Sambuc {
76*11be35a1SLionel Sambuc text::table_row row1;
77*11be35a1SLionel Sambuc row1.push_back("1234");
78*11be35a1SLionel Sambuc row1.push_back("123456");
79*11be35a1SLionel Sambuc text::table_row row2;
80*11be35a1SLionel Sambuc row2.push_back("12");
81*11be35a1SLionel Sambuc row2.push_back("12345678");
82*11be35a1SLionel Sambuc
83*11be35a1SLionel Sambuc text::table table(2);
84*11be35a1SLionel Sambuc table.add_row(row1);
85*11be35a1SLionel Sambuc table.add_row(row2);
86*11be35a1SLionel Sambuc
87*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(4, table.column_width(0));
88*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(8, table.column_width(1));
89*11be35a1SLionel Sambuc }
90*11be35a1SLionel Sambuc
91*11be35a1SLionel Sambuc
92*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table__column_widths);
ATF_TEST_CASE_BODY(table__column_widths)93*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table__column_widths)
94*11be35a1SLionel Sambuc {
95*11be35a1SLionel Sambuc text::table_row row1;
96*11be35a1SLionel Sambuc row1.push_back("1234");
97*11be35a1SLionel Sambuc row1.push_back("123456");
98*11be35a1SLionel Sambuc text::table_row row2;
99*11be35a1SLionel Sambuc row2.push_back("12");
100*11be35a1SLionel Sambuc row2.push_back("12345678");
101*11be35a1SLionel Sambuc
102*11be35a1SLionel Sambuc text::table table(2);
103*11be35a1SLionel Sambuc table.add_row(row1);
104*11be35a1SLionel Sambuc table.add_row(row2);
105*11be35a1SLionel Sambuc
106*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(4, table.column_widths()[0]);
107*11be35a1SLionel Sambuc ATF_REQUIRE_EQ(8, table.column_widths()[1]);
108*11be35a1SLionel Sambuc }
109*11be35a1SLionel Sambuc
110*11be35a1SLionel Sambuc
111*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table__empty);
ATF_TEST_CASE_BODY(table__empty)112*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table__empty)
113*11be35a1SLionel Sambuc {
114*11be35a1SLionel Sambuc text::table table(2);
115*11be35a1SLionel Sambuc ATF_REQUIRE(table.empty());
116*11be35a1SLionel Sambuc table.add_row(text::table_row(2));
117*11be35a1SLionel Sambuc ATF_REQUIRE(!table.empty());
118*11be35a1SLionel Sambuc }
119*11be35a1SLionel Sambuc
120*11be35a1SLionel Sambuc
121*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table__iterate);
ATF_TEST_CASE_BODY(table__iterate)122*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table__iterate)
123*11be35a1SLionel Sambuc {
124*11be35a1SLionel Sambuc text::table_row row1;
125*11be35a1SLionel Sambuc row1.push_back("foo");
126*11be35a1SLionel Sambuc text::table_row row2;
127*11be35a1SLionel Sambuc row2.push_back("bar");
128*11be35a1SLionel Sambuc
129*11be35a1SLionel Sambuc text::table table(1);
130*11be35a1SLionel Sambuc table.add_row(row1);
131*11be35a1SLionel Sambuc table.add_row(row2);
132*11be35a1SLionel Sambuc
133*11be35a1SLionel Sambuc text::table::const_iterator iter = table.begin();
134*11be35a1SLionel Sambuc ATF_REQUIRE(iter != table.end());
135*11be35a1SLionel Sambuc ATF_REQUIRE(row1 == *iter);
136*11be35a1SLionel Sambuc ++iter;
137*11be35a1SLionel Sambuc ATF_REQUIRE(iter != table.end());
138*11be35a1SLionel Sambuc ATF_REQUIRE(row2 == *iter);
139*11be35a1SLionel Sambuc ++iter;
140*11be35a1SLionel Sambuc ATF_REQUIRE(iter == table.end());
141*11be35a1SLionel Sambuc }
142*11be35a1SLionel Sambuc
143*11be35a1SLionel Sambuc
144*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__empty);
ATF_TEST_CASE_BODY(table_formatter__empty)145*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__empty)
146*11be35a1SLionel Sambuc {
147*11be35a1SLionel Sambuc ATF_REQUIRE(text::table_formatter().set_separator(" ")
148*11be35a1SLionel Sambuc .format(text::table(1)).empty());
149*11be35a1SLionel Sambuc ATF_REQUIRE(text::table_formatter().set_separator(" ")
150*11be35a1SLionel Sambuc .format(text::table(10)).empty());
151*11be35a1SLionel Sambuc }
152*11be35a1SLionel Sambuc
153*11be35a1SLionel Sambuc
154*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__defaults);
ATF_TEST_CASE_BODY(table_formatter__defaults)155*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__defaults)
156*11be35a1SLionel Sambuc {
157*11be35a1SLionel Sambuc text::table table(3);
158*11be35a1SLionel Sambuc {
159*11be35a1SLionel Sambuc text::table_row row;
160*11be35a1SLionel Sambuc row.push_back("First");
161*11be35a1SLionel Sambuc row.push_back("Second");
162*11be35a1SLionel Sambuc row.push_back("Third");
163*11be35a1SLionel Sambuc table.add_row(row);
164*11be35a1SLionel Sambuc }
165*11be35a1SLionel Sambuc {
166*11be35a1SLionel Sambuc text::table_row row;
167*11be35a1SLionel Sambuc row.push_back("Fourth with some text");
168*11be35a1SLionel Sambuc row.push_back("Fifth with some more text");
169*11be35a1SLionel Sambuc row.push_back("Sixth foo");
170*11be35a1SLionel Sambuc table.add_row(row);
171*11be35a1SLionel Sambuc }
172*11be35a1SLionel Sambuc
173*11be35a1SLionel Sambuc table_formatter_check(
174*11be35a1SLionel Sambuc "First Second Third\n"
175*11be35a1SLionel Sambuc "Fourth with some textFifth with some more textSixth foo\n",
176*11be35a1SLionel Sambuc text::table_formatter(), table);
177*11be35a1SLionel Sambuc }
178*11be35a1SLionel Sambuc
179*11be35a1SLionel Sambuc
180*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__one_column__no_max_width);
ATF_TEST_CASE_BODY(table_formatter__one_column__no_max_width)181*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__one_column__no_max_width)
182*11be35a1SLionel Sambuc {
183*11be35a1SLionel Sambuc text::table table(1);
184*11be35a1SLionel Sambuc {
185*11be35a1SLionel Sambuc text::table_row row;
186*11be35a1SLionel Sambuc row.push_back("First row with some words");
187*11be35a1SLionel Sambuc table.add_row(row);
188*11be35a1SLionel Sambuc }
189*11be35a1SLionel Sambuc {
190*11be35a1SLionel Sambuc text::table_row row;
191*11be35a1SLionel Sambuc row.push_back("Second row with some words");
192*11be35a1SLionel Sambuc table.add_row(row);
193*11be35a1SLionel Sambuc }
194*11be35a1SLionel Sambuc
195*11be35a1SLionel Sambuc table_formatter_check(
196*11be35a1SLionel Sambuc "First row with some words\n"
197*11be35a1SLionel Sambuc "Second row with some words\n",
198*11be35a1SLionel Sambuc text::table_formatter().set_separator(" | "), table);
199*11be35a1SLionel Sambuc }
200*11be35a1SLionel Sambuc
201*11be35a1SLionel Sambuc
202*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__one_column__explicit_width);
ATF_TEST_CASE_BODY(table_formatter__one_column__explicit_width)203*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__one_column__explicit_width)
204*11be35a1SLionel Sambuc {
205*11be35a1SLionel Sambuc text::table table(1);
206*11be35a1SLionel Sambuc {
207*11be35a1SLionel Sambuc text::table_row row;
208*11be35a1SLionel Sambuc row.push_back("First row with some words");
209*11be35a1SLionel Sambuc table.add_row(row);
210*11be35a1SLionel Sambuc }
211*11be35a1SLionel Sambuc {
212*11be35a1SLionel Sambuc text::table_row row;
213*11be35a1SLionel Sambuc row.push_back("Second row with some words");
214*11be35a1SLionel Sambuc table.add_row(row);
215*11be35a1SLionel Sambuc }
216*11be35a1SLionel Sambuc
217*11be35a1SLionel Sambuc table_formatter_check(
218*11be35a1SLionel Sambuc "First row with some words\n"
219*11be35a1SLionel Sambuc "Second row with some words\n",
220*11be35a1SLionel Sambuc text::table_formatter().set_separator(" | ").set_column_width(0, 1024),
221*11be35a1SLionel Sambuc table);
222*11be35a1SLionel Sambuc }
223*11be35a1SLionel Sambuc
224*11be35a1SLionel Sambuc
225*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__one_column__max_width);
ATF_TEST_CASE_BODY(table_formatter__one_column__max_width)226*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__one_column__max_width)
227*11be35a1SLionel Sambuc {
228*11be35a1SLionel Sambuc text::table table(1);
229*11be35a1SLionel Sambuc {
230*11be35a1SLionel Sambuc text::table_row row;
231*11be35a1SLionel Sambuc row.push_back("First row with some words");
232*11be35a1SLionel Sambuc table.add_row(row);
233*11be35a1SLionel Sambuc }
234*11be35a1SLionel Sambuc {
235*11be35a1SLionel Sambuc text::table_row row;
236*11be35a1SLionel Sambuc row.push_back("Second row with some words");
237*11be35a1SLionel Sambuc table.add_row(row);
238*11be35a1SLionel Sambuc }
239*11be35a1SLionel Sambuc
240*11be35a1SLionel Sambuc table_formatter_check(
241*11be35a1SLionel Sambuc "First row\nwith some\nwords\n"
242*11be35a1SLionel Sambuc "Second row\nwith some\nwords\n",
243*11be35a1SLionel Sambuc text::table_formatter().set_separator(" | ").set_table_width(11),
244*11be35a1SLionel Sambuc table);
245*11be35a1SLionel Sambuc }
246*11be35a1SLionel Sambuc
247*11be35a1SLionel Sambuc
248*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__many_columns__no_max_width);
ATF_TEST_CASE_BODY(table_formatter__many_columns__no_max_width)249*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__many_columns__no_max_width)
250*11be35a1SLionel Sambuc {
251*11be35a1SLionel Sambuc text::table table(3);
252*11be35a1SLionel Sambuc {
253*11be35a1SLionel Sambuc text::table_row row;
254*11be35a1SLionel Sambuc row.push_back("First");
255*11be35a1SLionel Sambuc row.push_back("Second");
256*11be35a1SLionel Sambuc row.push_back("Third");
257*11be35a1SLionel Sambuc table.add_row(row);
258*11be35a1SLionel Sambuc }
259*11be35a1SLionel Sambuc {
260*11be35a1SLionel Sambuc text::table_row row;
261*11be35a1SLionel Sambuc row.push_back("Fourth with some text");
262*11be35a1SLionel Sambuc row.push_back("Fifth with some more text");
263*11be35a1SLionel Sambuc row.push_back("Sixth foo");
264*11be35a1SLionel Sambuc table.add_row(row);
265*11be35a1SLionel Sambuc }
266*11be35a1SLionel Sambuc
267*11be35a1SLionel Sambuc table_formatter_check(
268*11be35a1SLionel Sambuc "First | Second | Third\n"
269*11be35a1SLionel Sambuc "Fourth with some text | Fifth with some more text | Sixth foo\n",
270*11be35a1SLionel Sambuc text::table_formatter().set_separator(" | "), table);
271*11be35a1SLionel Sambuc }
272*11be35a1SLionel Sambuc
273*11be35a1SLionel Sambuc
274*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__many_columns__explicit_width);
ATF_TEST_CASE_BODY(table_formatter__many_columns__explicit_width)275*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__many_columns__explicit_width)
276*11be35a1SLionel Sambuc {
277*11be35a1SLionel Sambuc text::table table(3);
278*11be35a1SLionel Sambuc {
279*11be35a1SLionel Sambuc text::table_row row;
280*11be35a1SLionel Sambuc row.push_back("First");
281*11be35a1SLionel Sambuc row.push_back("Second");
282*11be35a1SLionel Sambuc row.push_back("Third");
283*11be35a1SLionel Sambuc table.add_row(row);
284*11be35a1SLionel Sambuc }
285*11be35a1SLionel Sambuc {
286*11be35a1SLionel Sambuc text::table_row row;
287*11be35a1SLionel Sambuc row.push_back("Fourth with some text");
288*11be35a1SLionel Sambuc row.push_back("Fifth with some more text");
289*11be35a1SLionel Sambuc row.push_back("Sixth foo");
290*11be35a1SLionel Sambuc table.add_row(row);
291*11be35a1SLionel Sambuc }
292*11be35a1SLionel Sambuc
293*11be35a1SLionel Sambuc table_formatter_check(
294*11be35a1SLionel Sambuc "First | Second | Third\n"
295*11be35a1SLionel Sambuc "Fourth with some text | Fifth with some more text | Sixth foo\n",
296*11be35a1SLionel Sambuc text::table_formatter().set_separator(" | ").set_column_width(0, 23)
297*11be35a1SLionel Sambuc .set_column_width(1, 28), table);
298*11be35a1SLionel Sambuc }
299*11be35a1SLionel Sambuc
300*11be35a1SLionel Sambuc
301*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__many_columns__max_width);
ATF_TEST_CASE_BODY(table_formatter__many_columns__max_width)302*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__many_columns__max_width)
303*11be35a1SLionel Sambuc {
304*11be35a1SLionel Sambuc text::table table(3);
305*11be35a1SLionel Sambuc {
306*11be35a1SLionel Sambuc text::table_row row;
307*11be35a1SLionel Sambuc row.push_back("First");
308*11be35a1SLionel Sambuc row.push_back("Second");
309*11be35a1SLionel Sambuc row.push_back("Third");
310*11be35a1SLionel Sambuc table.add_row(row);
311*11be35a1SLionel Sambuc }
312*11be35a1SLionel Sambuc {
313*11be35a1SLionel Sambuc text::table_row row;
314*11be35a1SLionel Sambuc row.push_back("Fourth with some text");
315*11be35a1SLionel Sambuc row.push_back("Fifth with some more text");
316*11be35a1SLionel Sambuc row.push_back("Sixth foo");
317*11be35a1SLionel Sambuc table.add_row(row);
318*11be35a1SLionel Sambuc }
319*11be35a1SLionel Sambuc
320*11be35a1SLionel Sambuc table_formatter_check(
321*11be35a1SLionel Sambuc "First | Second | Third\n"
322*11be35a1SLionel Sambuc "Fourth with some text | Fifth with | Sixth foo\n"
323*11be35a1SLionel Sambuc " | some more | \n"
324*11be35a1SLionel Sambuc " | text | \n",
325*11be35a1SLionel Sambuc text::table_formatter().set_separator(" | ").set_table_width(46)
326*11be35a1SLionel Sambuc .set_column_width(1, text::table_formatter::width_refill)
327*11be35a1SLionel Sambuc .set_column_width(0, text::table_formatter::width_auto), table);
328*11be35a1SLionel Sambuc
329*11be35a1SLionel Sambuc table_formatter_check(
330*11be35a1SLionel Sambuc "First | Second | Third\n"
331*11be35a1SLionel Sambuc "Fourth with some text | Fifth with | Sixth foo\n"
332*11be35a1SLionel Sambuc " | some more | \n"
333*11be35a1SLionel Sambuc " | text | \n",
334*11be35a1SLionel Sambuc text::table_formatter().set_separator(" | ").set_table_width(48)
335*11be35a1SLionel Sambuc .set_column_width(1, text::table_formatter::width_refill)
336*11be35a1SLionel Sambuc .set_column_width(0, 23), table);
337*11be35a1SLionel Sambuc }
338*11be35a1SLionel Sambuc
339*11be35a1SLionel Sambuc
340*11be35a1SLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(table_formatter__use_case__cli_help);
ATF_TEST_CASE_BODY(table_formatter__use_case__cli_help)341*11be35a1SLionel Sambuc ATF_TEST_CASE_BODY(table_formatter__use_case__cli_help)
342*11be35a1SLionel Sambuc {
343*11be35a1SLionel Sambuc text::table options_table(2);
344*11be35a1SLionel Sambuc {
345*11be35a1SLionel Sambuc text::table_row row;
346*11be35a1SLionel Sambuc row.push_back("-a a_value");
347*11be35a1SLionel Sambuc row.push_back("This is the description of the first flag");
348*11be35a1SLionel Sambuc options_table.add_row(row);
349*11be35a1SLionel Sambuc }
350*11be35a1SLionel Sambuc {
351*11be35a1SLionel Sambuc text::table_row row;
352*11be35a1SLionel Sambuc row.push_back("-b");
353*11be35a1SLionel Sambuc row.push_back("And this is the text for the second flag");
354*11be35a1SLionel Sambuc options_table.add_row(row);
355*11be35a1SLionel Sambuc }
356*11be35a1SLionel Sambuc
357*11be35a1SLionel Sambuc text::table commands_table(2);
358*11be35a1SLionel Sambuc {
359*11be35a1SLionel Sambuc text::table_row row;
360*11be35a1SLionel Sambuc row.push_back("first");
361*11be35a1SLionel Sambuc row.push_back("This is the first command");
362*11be35a1SLionel Sambuc commands_table.add_row(row);
363*11be35a1SLionel Sambuc }
364*11be35a1SLionel Sambuc {
365*11be35a1SLionel Sambuc text::table_row row;
366*11be35a1SLionel Sambuc row.push_back("second");
367*11be35a1SLionel Sambuc row.push_back("And this is the second command");
368*11be35a1SLionel Sambuc commands_table.add_row(row);
369*11be35a1SLionel Sambuc }
370*11be35a1SLionel Sambuc
371*11be35a1SLionel Sambuc const text::widths_vector::value_type first_width =
372*11be35a1SLionel Sambuc std::max(options_table.column_width(0), commands_table.column_width(0));
373*11be35a1SLionel Sambuc
374*11be35a1SLionel Sambuc table_formatter_check(
375*11be35a1SLionel Sambuc "-a a_value This is the description\n"
376*11be35a1SLionel Sambuc " of the first flag\n"
377*11be35a1SLionel Sambuc "-b And this is the text for\n"
378*11be35a1SLionel Sambuc " the second flag\n",
379*11be35a1SLionel Sambuc text::table_formatter().set_separator(" ").set_table_width(36)
380*11be35a1SLionel Sambuc .set_column_width(0, first_width)
381*11be35a1SLionel Sambuc .set_column_width(1, text::table_formatter::width_refill),
382*11be35a1SLionel Sambuc options_table);
383*11be35a1SLionel Sambuc
384*11be35a1SLionel Sambuc table_formatter_check(
385*11be35a1SLionel Sambuc "first This is the first\n"
386*11be35a1SLionel Sambuc " command\n"
387*11be35a1SLionel Sambuc "second And this is the second\n"
388*11be35a1SLionel Sambuc " command\n",
389*11be35a1SLionel Sambuc text::table_formatter().set_separator(" ").set_table_width(36)
390*11be35a1SLionel Sambuc .set_column_width(0, first_width)
391*11be35a1SLionel Sambuc .set_column_width(1, text::table_formatter::width_refill),
392*11be35a1SLionel Sambuc commands_table);
393*11be35a1SLionel Sambuc }
394*11be35a1SLionel Sambuc
395*11be35a1SLionel Sambuc
ATF_INIT_TEST_CASES(tcs)396*11be35a1SLionel Sambuc ATF_INIT_TEST_CASES(tcs)
397*11be35a1SLionel Sambuc {
398*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table__ncolumns);
399*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table__column_width);
400*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table__column_widths);
401*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table__empty);
402*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table__iterate);
403*11be35a1SLionel Sambuc
404*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__empty);
405*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__defaults);
406*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__one_column__no_max_width);
407*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__one_column__explicit_width);
408*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__one_column__max_width);
409*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__many_columns__no_max_width);
410*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__many_columns__explicit_width);
411*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__many_columns__max_width);
412*11be35a1SLionel Sambuc ATF_ADD_TEST_CASE(tcs, table_formatter__use_case__cli_help);
413*11be35a1SLionel Sambuc }
414