Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:43

0001 
0002 // Copyright 2022, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #include <catch.hpp>
0006 #include <JANA/Utils/JTablePrinter.h>
0007 
0008 TEST_CASE("Short noop") {
0009     auto result = JTablePrinter::SplitContents("record_call_stack", 50);
0010     REQUIRE(result.size() == 1);
0011     REQUIRE(result[0] == "record_call_stack");
0012 }
0013 
0014 TEST_CASE("Cell split by newlines") {
0015     auto result = JTablePrinter::SplitContents("This\nis a\ntest", 10);
0016     REQUIRE(result.size() == 3);
0017     REQUIRE(result[0] == "This");
0018     REQUIRE(result[1] == "is a");
0019     REQUIRE(result[2] == "test");
0020 }
0021 
0022 TEST_CASE("Cell split by spaces trivial") {
0023     auto result = JTablePrinter::SplitContents("This is a test", 20);
0024     REQUIRE(result[0] == "This is a test");
0025     REQUIRE(result.size() == 1);
0026 }
0027 
0028 TEST_CASE("Cell split by newlines and spaces trivial") {
0029     auto result = JTablePrinter::SplitContents("This is a \ntest", 20);
0030     REQUIRE(result[0] == "This is a ");
0031     REQUIRE(result[1] == "test");
0032     REQUIRE(result.size() == 2);
0033 }
0034 
0035 TEST_CASE("Cell split by spaces") {
0036     auto result = JTablePrinter::SplitContents("This is a test", 6);
0037     for (auto& s: result) {
0038         std::cout << ">> " << s << std::endl;
0039     }
0040     REQUIRE(result.size() == 3);
0041     REQUIRE(result[0] == "This");
0042     REQUIRE(result[1] == "is a");
0043     REQUIRE(result[2] == "test");
0044 }
0045 
0046 TEST_CASE("Cell split by multiple spaces and newline") {
0047     auto result = JTablePrinter::SplitContents("This is  \n        a test", 10);
0048     for (auto& s: result) {
0049         std::cout << ">> " << s << std::endl;
0050     }
0051     REQUIRE(result.size() == 3);
0052     REQUIRE(result[0] == "This is  ");
0053     REQUIRE(result[1] == "        a");
0054     REQUIRE(result[2] == "test");
0055 }
0056 
0057 TEST_CASE("Nothing splittable") {
0058     auto result = JTablePrinter::SplitContents("This_is_a_test", 5);
0059     for (auto& s: result) {
0060         std::cout << ">> " << s << std::endl;
0061     }
0062     REQUIRE(result.size() == 3);
0063     REQUIRE(result[0] == "This_");
0064     REQUIRE(result[1] == "is_a_");
0065     REQUIRE(result[2] == "test");
0066 
0067 }
0068 
0069 TEST_CASE("Evenly divides") {
0070     auto result = JTablePrinter::SplitContents("aaa bbb ccc", 3);
0071     for (auto& s: result) {
0072         std::cout << ">> " << s << std::endl;
0073     }
0074     REQUIRE(result.size() == 3);
0075     REQUIRE(result[0] == "aaa");
0076     REQUIRE(result[1] == "bbb");
0077     REQUIRE(result[2] == "ccc");
0078 
0079 }
0080 
0081 TEST_CASE("Weird one") {
0082     std::string s = "Max time (in seconds) JANA will wait for a thread to update its heartbeat before hard-exiting. 0 to disable timeout completely.";
0083     auto result = JTablePrinter::SplitContents(s, 30);
0084     for (auto& s: result) {
0085         std::cout << ">> " << s << std::endl;
0086     }
0087     REQUIRE(result.size() == 5);
0088     REQUIRE(result[4] == "timeout completely.");
0089 }