diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-01-07 15:59:57 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-01-07 15:59:57 +0000 |
commit | 45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (patch) | |
tree | a9e8279fe00b9b01dc2393f59dc7f41b5e416b2a /src/unit/fstring.cpp | |
parent | d96fe229e79f9b1947cbd24ff52d6bf7bb9bf80d (diff) | |
download | libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.gz libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.bz2 libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.xz libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.zip |
Only two real changes. First, Bu::FString and Bu::FBasicString are in different
files. This won't affect any programs at all anywhere. This will just make it
easier to maintain and extend later. You still want to include "bu/fstring.h"
and use Bu::FString in code.
The other is kinda fun. I created a special format for unit tests, they use the
extension .unit now and use the mkunit.sh script to convert them to c++ code.
There are some nice features here too, maintaining unit tests is much, much
easier, and we can have more features without making the code any harder to use.
Also, it will be easier to have the unit tests generate reports and be run from
a master program and the like.
Diffstat (limited to '')
-rw-r--r-- | src/unit/fstring.cpp | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp deleted file mode 100644 index 9430a83..0000000 --- a/src/unit/fstring.cpp +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/fstring.h" | ||
9 | #include "bu/unitsuite.h" | ||
10 | |||
11 | #include <dirent.h> | ||
12 | |||
13 | class Unit : public Bu::UnitSuite | ||
14 | { | ||
15 | public: | ||
16 | Unit() | ||
17 | { | ||
18 | setName("FString"); | ||
19 | addTest( Unit::compare1 ); | ||
20 | addTest( Unit::compare2 ); | ||
21 | addTest( Unit::appendSingle ); | ||
22 | addTest( Unit::shared1 ); | ||
23 | addTest( Unit::insert ); | ||
24 | addTest( Unit::remove ); | ||
25 | addTest( Unit::add1 ); | ||
26 | addTest( Unit::add2 ); | ||
27 | addTest( Unit::add3 ); | ||
28 | addTest( Unit::add4 ); | ||
29 | addTest( Unit::add5 ); | ||
30 | addTest( Unit::add6 ); | ||
31 | addTest( Unit::subStr1 ); | ||
32 | } | ||
33 | |||
34 | virtual ~Unit() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | void compare1() | ||
39 | { | ||
40 | Bu::FString b("Bob"); | ||
41 | unitTest( !(b == "Bobo") ); | ||
42 | unitTest( b == "Bob" ); | ||
43 | } | ||
44 | |||
45 | void compare2() | ||
46 | { | ||
47 | Bu::FString b("Bobo"); | ||
48 | unitTest( !(b == "Bob") ); | ||
49 | unitTest( b == "Bobo" ); | ||
50 | } | ||
51 | |||
52 | void appendSingle() | ||
53 | { | ||
54 | Bu::FString b; | ||
55 | for( char l = 'a'; l < 'g'; l++ ) | ||
56 | b += l; | ||
57 | unitTest( b == "abcdef" ); | ||
58 | unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); | ||
59 | } | ||
60 | |||
61 | void shared1() | ||
62 | { | ||
63 | Bu::FString a("Hey there"); | ||
64 | Bu::FString b( a ); | ||
65 | unitTest( a.getStr() == b.getStr() ); | ||
66 | b += " guy"; | ||
67 | unitTest( a.getStr() != b.getStr() ); | ||
68 | a = b; | ||
69 | unitTest( a.getStr() == b.getStr() ); | ||
70 | } | ||
71 | |||
72 | void insert() | ||
73 | { | ||
74 | Bu::FString a("abcd"); | ||
75 | a.insert( 2, "-!-", 3 ); | ||
76 | unitTest( a == "ab-!-cd" ); | ||
77 | |||
78 | a.insert( 0, "!!", 2 ); | ||
79 | unitTest( a == "!!ab-!-cd" ); | ||
80 | |||
81 | a.insert( -10, "789", 3 ); | ||
82 | unitTest( a == "789!!ab-!-cd" ); | ||
83 | |||
84 | a.insert( 12, "89", 2 ); | ||
85 | unitTest( a == "789!!ab-!-cd89" ); | ||
86 | |||
87 | a.insert( 1203, "12", 2 ); | ||
88 | unitTest( a == "789!!ab-!-cd8912" ); | ||
89 | } | ||
90 | |||
91 | void remove() | ||
92 | { | ||
93 | Bu::FString a("abHEYcd"); | ||
94 | a.remove( 2, 3 ); | ||
95 | unitTest( a == "abcd" ); | ||
96 | a.remove( 2, 5 ); | ||
97 | unitTest( a == "ab" ); | ||
98 | a += "cdefghijklmnop"; | ||
99 | a.remove( 5, 1 ); | ||
100 | unitTest( a = "abcdeghijklmnop" ); | ||
101 | } | ||
102 | |||
103 | void add1() | ||
104 | { | ||
105 | Bu::FString a("hi there"); | ||
106 | Bu::FString b(", yeah!"); | ||
107 | Bu::FString c = a + b; | ||
108 | |||
109 | unitTest( c == "hi there, yeah!" ); | ||
110 | } | ||
111 | |||
112 | void add2() | ||
113 | { | ||
114 | Bu::FString a("hi there"); | ||
115 | Bu::FString c = a + ", yeah!"; | ||
116 | |||
117 | unitTest( c == "hi there, yeah!" ); | ||
118 | } | ||
119 | |||
120 | void add3() | ||
121 | { | ||
122 | Bu::FString a("hi there"); | ||
123 | Bu::FString b(", yeah!"); | ||
124 | Bu::FString c = a + ", Mr. Man" + b; | ||
125 | |||
126 | unitTest( c == "hi there, Mr. Man, yeah!" ); | ||
127 | } | ||
128 | |||
129 | void add4() | ||
130 | { | ||
131 | Bu::FString b(", yeah!"); | ||
132 | Bu::FString c = "hi there" + b; | ||
133 | |||
134 | unitTest( c == "hi there, yeah!" ); | ||
135 | } | ||
136 | |||
137 | void add5() | ||
138 | { | ||
139 | Bu::FString b; | ||
140 | Bu::FString c = "sup?"; | ||
141 | b += "hey, " + c; | ||
142 | |||
143 | unitTest( b == "hey, sup?" ); | ||
144 | } | ||
145 | |||
146 | void add6() | ||
147 | { | ||
148 | Bu::FString a("Hello"); | ||
149 | char b[256] = {"Dude"}; | ||
150 | Bu::FString c = a + "/" + b; | ||
151 | |||
152 | unitTest( c == "Hello/Dude" ); | ||
153 | } | ||
154 | |||
155 | void subStr1() | ||
156 | { | ||
157 | Bu::FString a("abcdefghijklmnop"); | ||
158 | unitTest( a.getSubStr( 5, 3 ) == "fgh" ); | ||
159 | unitTest( a.getSubStr( 10 ) == "klmnop" ); | ||
160 | unitTest( a.getSubStr( 40 ) == "" ); | ||
161 | unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" ); | ||
162 | unitTest( a.getSubStr( -15, 4 ) == "abcd" ); | ||
163 | } | ||
164 | }; | ||
165 | |||
166 | int main( int argc, char *argv[] ) | ||
167 | { | ||
168 | return Unit().run( argc, argv ); | ||
169 | } | ||
170 | |||