3 * Author : Chris Koeritz
4 * Purpose: Checks out the line splitting support to make sure it is working.
6 * Copyright (c) 1992-$now By Author. This program is free software; you can *
7 * redistribute it and/or modify it under the terms of the GNU General Public *
8 * License as published by the Free Software Foundation; either version 2 of *
9 * the License or (at your option) any later version. This is online at: *
10 * http://www.fsf.org/copyleft/gpl.html *
13 #include <application/hoople_main.h>
14 #include <basis/astring.h>
15 #include <basis/functions.h>
16 #include <basis/guards.h>
17 #include <mathematics/chaos.h>
18 #include <structures/static_memory_gremlin.h>
19 #include <textual/string_manipulation.h>
20 #include <unit_test/unit_base.h>
22 using namespace application;
23 using namespace basis;
24 using namespace filesystem;
25 using namespace loggers;
26 using namespace mathematics;
27 using namespace structures;
28 using namespace textual;
29 using namespace timely;
30 using namespace unit_test;
32 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
34 class test_splitter : public virtual unit_base, virtual public application_shell
38 DEFINE_CLASS_NAME("test_splitter");
42 astring show_limits(int min_col, int max_col)
45 for (int i = 0; i <= max_col; i++) {
46 if (i < min_col) to_return += " ";
47 else to_return += "+";
52 #define SHOW_SPLIT(str, low, high) \
53 string_manipulation::split_lines(str, output, low, high); \
54 LOG(""); formal(temp)\
55 LOG(show_limits(low, high)); \
56 LOG(output + "<<<<"); \
57 LOG(show_limits(low, high))
59 int test_splitter::execute()
63 astring split_1 = "This is a fairly long paragraph that will be split a few different ways to check the splitting logic. It will be interesting to see how things like spaces, and punctuation, are handled.";
67 SHOW_SPLIT(split_1, 0, 1);
68 SHOW_SPLIT(split_1, 0, 10);
69 SHOW_SPLIT(split_1, 10, 30);
70 SHOW_SPLIT(split_1, 20, 35);
71 SHOW_SPLIT(split_1, 4, 50);
72 SHOW_SPLIT(split_1, 8, 12);
74 astring split_2 = "Here's another string.\r\nThere are embedded carriage returns after every sentence.\r\nSo, this should be a good test of how those things are handled when they're seen in the body of the text.\r\nThe next one is, hey, guess what?\r\nIt's a simple LF instead of CRLF; here it comes:\nHow did that look compared the others?\nThe previous was another bare one.\r\nWhen can I stop writing this stupid paragraph?\r\nSoon hopefully.";
76 SHOW_SPLIT(split_2, 5, 20);
77 SHOW_SPLIT(split_2, 0, 30);
78 SHOW_SPLIT(split_2, 8, 11);
79 SHOW_SPLIT(split_2, 28, 41);
80 SHOW_SPLIT(split_2, 58, 79);
82 astring split_3 = "This string exists for just one purpose; it will be showing how the thing handles a really long word at the end. And that word is... califragilisticexpialadociuosberriesinatreearerottingnowsomamacasscanyoupleasehelpme";
84 SHOW_SPLIT(split_3, 0, 5);
85 SHOW_SPLIT(split_3, 10, 30);
87 astring split_4 = "This string\n\n\nhas multiple CRs gwan on.\r\n\r\nDoes this cause problems?\n\n\n\n";
89 SHOW_SPLIT(split_4, 3, 10);
90 SHOW_SPLIT(split_4, 8, 20);
92 return final_report();
95 HOOPLE_MAIN(test_splitter, );