1 #include <cxxtest/TestSuite.h>
2 #include "engines/ultima/shared/core/str.h"
3 
4 /**
5  * Test suite for the functions in engines/ultima/shared/core/str.h
6  */
7 
8 class UltimaStrSuite : public CxxTest::TestSuite {
9 
10 	public:
UltimaStrSuite()11 	UltimaStrSuite () {
12 	}
13 
test_index_of()14 	void test_index_of() {
15 		Ultima::Shared::String s = "  a  ";
16 		TS_ASSERT_EQUALS(s.indexOf(' '), 0);
17 		TS_ASSERT_EQUALS(s.indexOf('a'), 2);
18 		TS_ASSERT_EQUALS(s.indexOf('z'), -1);
19 
20 		s = " alksjdf ][";
21 		TS_ASSERT_EQUALS(s.indexOf("3245j9083f45"), 5);
22 		TS_ASSERT_EQUALS(s.indexOf("0123456789"), -1);
23 	}
24 
test_split()25 	void test_split() {
26 		Ultima::Shared::String s = "abc,def,,aaa,";
27 		Ultima::Shared::StringArray a = s.split(',');
28 		// Note: final empty string is trimmed
29 		TS_ASSERT_EQUALS(a.size(), 4);
30 		TS_ASSERT_EQUALS(a[1], "def");
31 		TS_ASSERT_EQUALS(a[2], "");
32 
33 		Ultima::Shared::String s2 = "e,";
34 		a = s.split(s2);
35 		TS_ASSERT_EQUALS(a.size(), 5);
36 		TS_ASSERT_EQUALS(a[1], "d");
37 		TS_ASSERT_EQUALS(a[2], "f");
38 	}
39 };
40