first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / tests_textual / test_splitter.cpp
1 /*
2 *  Name   : test_splitter
3 *  Author : Chris Koeritz
4 *  Purpose: Checks out the line splitting support to make sure it is working.
5 **
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                                    *
11 */
12
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>
21
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;
31
32 #define LOG(to_print) EMERGENCY_LOG(program_wide_logger().get(), astring(to_print))
33
34 class test_splitter : public virtual unit_base, virtual public application_shell
35 {
36 public:
37   test_splitter() {}
38   DEFINE_CLASS_NAME("test_splitter");
39   int execute();
40 };
41
42 astring show_limits(int min_col, int max_col)
43 {
44   astring to_return;
45   for (int i = 0; i <= max_col; i++) {
46     if (i < min_col) to_return += " ";
47     else to_return += "+";
48   }
49   return to_return;
50 }
51
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))
58
59 int test_splitter::execute()
60 {
61   FUNCDEF("execute");
62
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.";
64   
65   astring output;
66
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);
73
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.";
75
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);
81
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";
83
84   SHOW_SPLIT(split_3, 0, 5);
85   SHOW_SPLIT(split_3, 10, 30);
86
87   astring split_4 = "This string\n\n\nhas multiple CRs gwan on.\r\n\r\nDoes this cause problems?\n\n\n\n";
88
89   SHOW_SPLIT(split_4, 3, 10);
90   SHOW_SPLIT(split_4, 8, 20);
91
92   return final_report();
93 }
94
95 HOOPLE_MAIN(test_splitter, );
96