summaryrefslogtreecommitdiff
path: root/src/unit/fstring.unit
diff options
context:
space:
mode:
Diffstat (limited to 'src/unit/fstring.unit')
-rw-r--r--src/unit/fstring.unit140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit
new file mode 100644
index 0000000..93065fe
--- /dev/null
+++ b/src/unit/fstring.unit
@@ -0,0 +1,140 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
4 *
5 * This file is part of the libbu++ library and is released under the
6 * terms of the license contained in the file LICENSE.
7 */
8
9#include "bu/fstring.h"
10
11#include <dirent.h>
12
13{=Init}
14
15{%compare1}
16{
17 Bu::FString b("Bob");
18 unitTest( !(b == "Bobo") );
19 unitTest( b == "Bob" );
20}
21
22{%compare2}
23{
24 Bu::FString b("Bobo");
25 unitTest( !(b == "Bob") );
26 unitTest( b == "Bobo" );
27}
28
29{%appendSingle}
30{
31 Bu::FString b;
32 for( char l = 'a'; l < 'g'; l++ )
33 b += l;
34 unitTest( b == "abcdef" );
35 unitTest( strcmp( b.getStr(), "abcdef" ) == 0 );
36}
37
38{%shared1}
39{
40 Bu::FString a("Hey there");
41 Bu::FString b( a );
42 unitTest( a.getStr() == b.getStr() );
43 b += " guy";
44 unitTest( a.getStr() != b.getStr() );
45 a = b;
46 unitTest( a.getStr() == b.getStr() );
47}
48
49{%insert}
50{
51 Bu::FString a("abcd");
52 a.insert( 2, "-!-", 3 );
53 unitTest( a == "ab-!-cd" );
54
55 a.insert( 0, "!!", 2 );
56 unitTest( a == "!!ab-!-cd" );
57
58 a.insert( -10, "789", 3 );
59 unitTest( a == "789!!ab-!-cd" );
60
61 a.insert( 12, "89", 2 );
62 unitTest( a == "789!!ab-!-cd89" );
63
64 a.insert( 1203, "12", 2 );
65 unitTest( a == "789!!ab-!-cd8912" );
66}
67
68{%remove}
69{
70 Bu::FString a("abHEYcd");
71 a.remove( 2, 3 );
72 unitTest( a == "abcd" );
73 a.remove( 2, 5 );
74 unitTest( a == "ab" );
75 a += "cdefghijklmnop";
76 a.remove( 5, 1 );
77 unitTest( a = "abcdeghijklmnop" );
78}
79
80{%add1}
81{
82 Bu::FString a("hi there");
83 Bu::FString b(", yeah!");
84 Bu::FString c = a + b;
85
86 unitTest( c == "hi there, yeah!" );
87}
88
89{%add2}
90{
91 Bu::FString a("hi there");
92 Bu::FString c = a + ", yeah!";
93
94 unitTest( c == "hi there, yeah!" );
95}
96
97{%add3}
98{
99 Bu::FString a("hi there");
100 Bu::FString b(", yeah!");
101 Bu::FString c = a + ", Mr. Man" + b;
102
103 unitTest( c == "hi there, Mr. Man, yeah!" );
104}
105
106{%add4}
107{
108 Bu::FString b(", yeah!");
109 Bu::FString c = "hi there" + b;
110
111 unitTest( c == "hi there, yeah!" );
112}
113
114{%add5}
115{
116 Bu::FString b;
117 Bu::FString c = "sup?";
118 b += "hey, " + c;
119
120 unitTest( b == "hey, sup?" );
121}
122
123{%add6}
124{
125 Bu::FString a("Hello");
126 char b[256] = {"Dude"};
127 Bu::FString c = a + "/" + b;
128
129 unitTest( c == "Hello/Dude" );
130}
131
132{%subStr1}
133{
134 Bu::FString a("abcdefghijklmnop");
135 unitTest( a.getSubStr( 5, 3 ) == "fgh" );
136 unitTest( a.getSubStr( 10 ) == "klmnop" );
137 unitTest( a.getSubStr( 40 ) == "" );
138 unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" );
139 unitTest( a.getSubStr( -15, 4 ) == "abcd" );
140}