feisty meow concerns codebase  2.140
test_splitter.cpp
Go to the documentation of this file.
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 
14 #include <basis/astring.h>
15 #include <basis/functions.h>
16 #include <basis/guards.h>
17 #include <mathematics/chaos.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 
The application_shell is a base object for console programs.
Provides a dynamically resizable ASCII character string.
Definition: astring.h:35
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
Provides macros that implement the 'main' program of an application.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition: averager.h:21
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
#include <time.h>
Definition: earth_time.cpp:37
Useful support functions for unit testing, especially within hoople.
Definition: unit_base.cpp:35
HOOPLE_MAIN(test_splitter,)
astring show_limits(int min_col, int max_col)
#define SHOW_SPLIT(str, low, high)