2 // Automated Testing Framework (atf)
4 // Copyright (c) 2009 The NetBSD Foundation, Inc.
5 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "../macros.hpp"
38 // ------------------------------------------------------------------------
39 // Test cases for the free functions.
40 // ------------------------------------------------------------------------
108 // TODO(jmmv): Fix the code to pass this test...
114 // " 2345678901234567",
115 // "\n2345678901234567",
123 "12345 789012345 78",
124 "12345 789012345\n78",
304 "1234 6789 123456\n2 4 6",
305 "1234 6789\n123456\n\n2 4 6"
313 "56789 123456\n2 4 6",
314 "12: 56789\n 123456\n\n 2 4 6"
322 "56789 123456\n2 4 6",
323 "12: 56789\n12: 123456\n12: \n12: 2 4 6"
331 "56789 123456\n2 4 6",
332 "12: 56789\n 123456\n\n 2 4 6"
340 "56789 123456\n2 4 6",
341 "12: 56789\n12: 123456\n12:\n12: 2 4 6"
360 run_tests(const char *tc
)
364 std::cout
<< "Running tests for " << tc
<< "\n";
366 atf::env::set("COLUMNS", "15");
368 for (t
= &tests
[0]; t
->tc
!= NULL
; t
++) {
369 if (std::strcmp(t
->tc
, tc
) == 0) {
371 std::cout
<< "Testing with tag '" << t
->tag
<< "', '"
372 << (t
->repeat
? "repeat" : "no repeat") << "', col "
374 std::cout
<< "Input: >>>" << t
->fmt
<< "<<<\n";
375 std::cout
<< "Expected output: >>>" << t
->result
<< "<<<\n";
377 std::string result
= atf::ui::format_text_with_tag(t
->fmt
, t
->tag
,
379 std::cout
<< "Output : >>>" << result
<< "<<<\n";
380 ATF_REQUIRE_EQ(t
->result
, result
);
385 ATF_TEST_CASE(wo_tag
);
386 ATF_TEST_CASE_HEAD(wo_tag
)
388 set_md_var("descr", "Checks formatting without tags");
390 ATF_TEST_CASE_BODY(wo_tag
)
395 ATF_TEST_CASE(wo_tag_col
);
396 ATF_TEST_CASE_HEAD(wo_tag_col
)
398 set_md_var("descr", "Checks formatting without tags and with a non-zero "
401 ATF_TEST_CASE_BODY(wo_tag_col
)
403 run_tests("wo_tag_col");
406 ATF_TEST_CASE(w_tag_no_repeat
);
407 ATF_TEST_CASE_HEAD(w_tag_no_repeat
)
409 set_md_var("descr", "Checks formatting with a tag");
411 ATF_TEST_CASE_BODY(w_tag_no_repeat
)
413 run_tests("w_tag_no_repeat");
416 ATF_TEST_CASE(w_tag_repeat
);
417 ATF_TEST_CASE_HEAD(w_tag_repeat
)
419 set_md_var("descr", "Checks formatting with a tag and repeating it on "
422 ATF_TEST_CASE_BODY(w_tag_repeat
)
424 run_tests("w_tag_repeat");
427 ATF_TEST_CASE(w_tag_col
);
428 ATF_TEST_CASE_HEAD(w_tag_col
)
430 set_md_var("descr", "Checks formatting with a tag and starting at a "
431 "column greater than its length");
433 ATF_TEST_CASE_BODY(w_tag_col
)
435 run_tests("w_tag_col");
438 ATF_TEST_CASE(paragraphs
);
439 ATF_TEST_CASE_HEAD(paragraphs
)
441 set_md_var("descr", "Checks formatting a string that contains multiple "
444 ATF_TEST_CASE_BODY(paragraphs
)
446 run_tests("paragraphs");
449 // ------------------------------------------------------------------------
451 // ------------------------------------------------------------------------
453 ATF_INIT_TEST_CASES(tcs
)
455 // Add the test cases for the free functions.
456 ATF_ADD_TEST_CASE(tcs
, wo_tag
);
457 ATF_ADD_TEST_CASE(tcs
, wo_tag_col
);
458 ATF_ADD_TEST_CASE(tcs
, w_tag_no_repeat
);
459 ATF_ADD_TEST_CASE(tcs
, w_tag_repeat
);
460 ATF_ADD_TEST_CASE(tcs
, w_tag_col
);
461 ATF_ADD_TEST_CASE(tcs
, paragraphs
);