#include "io.hh"
int main()
{
cout << "**** BEGIN t-string.exe\n";
{
cout << "*** BEGIN test 1\n";
string s = " bogie";
string t = string();
t += ' ';
t += "bogie";
ASSERT(strings_equal(s,t));
cout << "*** END test 1\n";
}
{
cout << "*** BEGIN test 2\n";
string a = "antelope";
ASSERT(strings_equal(a, string() + "ante" + "lope"));
cout << "*** END test 2\n";
}
{
cout << "*** BEGIN test 3\n";
string a = "apple";
ASSERT(strings_equal(a,"apple"));
string b = "banana";
ASSERT(strings_equal(b,"banana"));
string c = "carrot" + a;
ASSERT(strings_equal(c,"carrotapple"));
string r = c + "123" + "456" + 78;
ASSERT(strings_equal(r,"carrotapple12345678"));
{
string_buffer sb;
sb << c;
sb << "123";
sb << "456";
sb << 78;
ASSERT(sb.equals("carrotapple12345678"));
}
ASSERT(strings_equal(a + 22, "apple22"));
ASSERT(strings_equal(22 + a,"22apple"));
string_buffer temp;
temp << 'h';
temp << b;
temp << " bogie-dog";
ASSERT(strings_equal(temp,"hbanana bogie-dog"));
cout << "*** END test 3\n";
}
{
cout << "*** BEGIN test 4\n";
string s = "cat";
string t = s;
t = s;
ASSERT(s.equals(t));
ASSERT(s.equals("cat"));
t += string("bat");
ASSERT(s.equals("cat"));
ASSERT(t.equals("catbat"));
ASSERT(!s.equals(t));
string u;
u = s;
u += "bat";
ASSERT(t.equals(u));
cout << "*** END test 4\n";
}
{
cout << "*** BEGIN test 5\n";
string a = "apple";
string b = "banana";
ASSERT(!a.equals(b));
cout << "*** END test 5\n";
}
{
cout << "*** BEGIN test 6\n";
string a = "apple";
string b = "apple";
ASSERT(a.equals(b));
ASSERT(strings_equal(a,b));
cout << "*** END test 6\n";
}
{
cout << "*** BEGIN test 7\n";
string a = "apple";
string b = "appl";
b += "e";
ASSERT(a.equals(b));
cout << "*** END test 7\n";
}
{
cout << "*** BEGIN test 8\n";
string s1;
s1 += "hello";
s1 += ", ";
s1 += "world";
ASSERT(s1.equals("hello, world"));
string_buffer s2;
s2 << "hello" << ", " << "world";
ASSERT(s2.equals("hello, world"));
cout << "*** END test 8\n";
}
{
cout << "*** BEGIN test 9\n";
string s;
const char* a1 = "zip";
s += a1;
ASSERT(s.equals("zip"));
cout << "*** END test 9\n";
}
{
cout << "*** BEGIN test 10\n";
string_buffer b;
b << "zip";
string c = "nip" + b + "dog";
ASSERT(b.equals("zip"));
ASSERT(c.equals("nipzipdog"));
cout << "*** END test 10\n";
}
{
cout << "*** BEGIN test 11\n";
string_buffer b;
b << "zip";
string c = b + "dog";
ASSERT(b.equals("zip"));
cout << "*** END test 11\n";
}
{
cout << "*** BEGIN test 12\n";
string_buffer pb;
string s = "moose ";
pb << s;
string t = pb;
pb << "that got loose";
ASSERT(s.equals("moose "));
ASSERT(t.equals("moose "));
ASSERT(pb.equals("moose that got loose"));
cout << "*** END test 12\n";
}
{
cout << "*** BEGIN test 13\n";
string a = "cat";
const char* s = a.const_char_star();
ASSERT(strings_equal(s, a));
ASSERT(strings_equal(s, "cat"));
cout << "*** END test 13\n";
}
{
cout << "*** BEGIN test 14\n";
string_buffer silly;
silly << "abcdefghijklmnopqrstuvwxyz";
silly << silly;
ASSERT(silly.equals("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
string_buffer silly2;
silly2 << "cat";
silly2 << silly2;
string me = silly2;
string me2 = (me + ' ' + 'i' + 's' + ' ' + 'a' + " do"+ 'g');
ASSERT(me2.equals("catcat is a dog"));
ASSERT(strings_equal(me2,"catcat is a dog"));
cout << "*** END test 14\n";
}
{
cout << "*** BEGIN test 15\n";
string_buffer b;
b << "jack";
string s = b + ' ' + "and jill";
ASSERT(b.equals("jack"));
ASSERT(strings_equal(b,"jack"));
ASSERT(s.equals("jack and jill"));
cout << "*** END test 15\n";
}
{
cout << "*** BEGIN test 16\n";
string s = ("hello" + 2);
ASSERT(s.equals("llo"));
cout << "*** END test 16\n";
}
{
cout << "*** BEGIN test 17\n";
char* s = "123456789012345678901234567890123456789012345678901234567890";
string s2 = s + '1';
ASSERT(s2.equals("01234567890"));
cout << "*** END test 17\n";
}
{
cout << "*** BEGIN test 18\n";
string_buffer b;
b << "hello";
string s = b;
b << ", there";
ASSERT(s.equals("hello"));
cout << "*** END test 18\n";
}
{
cout << "*** BEGIN test 19\n";
const string s = "I am a const string\n";
ASSERT(s.get_char_at(0) == 'I');
ASSERT(s.equals("I am a const string\n"));
cout << "*** END test 19\n";
}
{
cout << "*** BEGIN test 20\n";
const string s = "a cat had a \"dog\"";
ASSERT(s.equals("a cat had a \"dog\""));
string quoted_s = quoted(s);
ASSERT(strings_equal(quoted_s,"\"a cat had a \\\"dog\\\"\""));
cout << "*** END test 20\n";
}
{
cout << "*** BEGIN test 21\n";
string s = "cat";
s = s;
ASSERT(s.equals("cat"));
cout << "*** END test 21\n";
}
{
cout << "*** BEGIN test 22\n";
string_buffer silly;
silly << "zap";
silly << silly;
ASSERT(silly.equals("zapzap"));
cout << "*** END test 22\n";
}
{
cout << "*** BEGIN test 23\n";
string a = "apple";
string b = a;
a = "apple2";
ASSERT(a.equals("apple2"));
ASSERT(b.equals("apple"));
a += "apple3";
ASSERT(a.equals("apple2apple3"));
ASSERT(b.equals("apple"));
cout << "*** END test 23\n";
}
{
cout << "*** BEGIN test 24\n";
string a = "the cat sat on the mat";
string b = substring(a,4,4+3);
string c = substring(a,0,a.get_length());
string d = substring(a,4,-4);
string e = reversed(a);
string f = capitalised(a);
ASSERT(a.equals("the cat sat on the mat"));
ASSERT(b.equals("cat"));
ASSERT(c.equals("the cat sat on the mat"));
ASSERT(d.equals("cat sat on the"));
ASSERT(e.equals("tam eht no tas tac eht"));
ASSERT(f.equals("The Cat Sat On The Mat"));
cout << "*** END test 24\n";
}
{
cout << "*** BEGIN test 25\n";
string s1 = "apple";
s1 += "banana";
ASSERT(s1.equals("applebanana"));
string s2 = "apple";
string s3 = "banana";
s2 += s3;
ASSERT(s2.equals("applebanana"));
ASSERT(s3.equals("banana"));
cout << "*** END test 25\n";
}
{
cout << "*** BEGIN test 26\n";
string s = "ignoreme";
s = (string() + "0x" +
'f' +
'f');
ASSERT(s.equals("0xff"));
cout << "*** END test 26\n";
}
{
cout << "*** BEGIN test 27\n";
string s = "apple";
string t = s;
t = "banana";
ASSERT(strings_equal(s, "apple"));
ASSERT(strings_equal(t, "banana"));
cout << "*** END test 27\n";
}
cout << "**** All tests succeeded!\n";
cout << "**** END t-string.exe\n";
return EXIT_SUCCESS;
}
END_OF_MAIN();