1 #include <libgeodecomp/misc/stringops.h>
2 
3 #include <cxxtest/TestSuite.h>
4 
5 using namespace LibGeoDecomp;
6 
7 namespace LibGeoDecomp {
8 
9 class StringOpsTest : public CxxTest::TestSuite
10 {
11 public:
12 
testItoa()13     void testItoa()
14     {
15         TS_ASSERT_EQUALS("0",   StringOps::itoa(0));
16         TS_ASSERT_EQUALS("-1",  StringOps::itoa(-1));
17         TS_ASSERT_EQUALS("123", StringOps::itoa(123));
18     }
19 
testAtoi()20     void testAtoi()
21     {
22         TS_ASSERT_EQUALS(0,   StringOps::atoi("0"  ));
23         TS_ASSERT_EQUALS(-1,  StringOps::atoi("-1" ));
24         TS_ASSERT_EQUALS(123, StringOps::atoi("123"));
25     }
26 
testAtof()27     void testAtof()
28     {
29         TS_ASSERT_EQUALS(0,   StringOps::atof("0"  ));
30         TS_ASSERT_EQUALS(-1,  StringOps::atof("-1" ));
31         TS_ASSERT_EQUALS(123, StringOps::atof("123"));
32 
33         TS_ASSERT_EQUALS(0.25, StringOps::atof("0.25"));
34         TS_ASSERT_EQUALS(-0.5, StringOps::atof("-0.5"));
35     }
36 
testTokenize()37     void testTokenize()
38     {
39         std::string message = "abc_123_andi ist so toll";
40 
41         StringVec expected1;
42         StringVec expected2;
43         StringVec expected3;
44 
45         expected1 << "abc"
46                   << "123"
47                   << "andi ist so toll";
48 
49         expected2 << "abc"
50                   << "123"
51                   << "andi"
52                   << "ist"
53                   << "so"
54                   << "toll";
55 
56         TS_ASSERT_EQUALS(expected1, StringOps::tokenize(message, "_"));
57         TS_ASSERT_EQUALS(expected2, StringOps::tokenize(message, "_ "));
58         StringVec tokens = StringOps::tokenize("\n", " \n");
59         TS_ASSERT_EQUALS(expected3, StringOps::tokenize("\n", " \n"));
60     }
61 
testTokenize2()62     void testTokenize2()
63     {
64         std::string message = " x y ";
65         StringVec tokens = StringOps::tokenize(message, " ");
66 
67         StringVec expectedTokens;
68         expectedTokens << "x"
69                        << "y";
70 
71         TS_ASSERT_EQUALS(tokens, expectedTokens);
72     }
73 
testJoin()74     void testJoin()
75     {
76         StringVec tokens;
77         tokens << "a"
78                << "bb"
79                << "ccc";
80         TS_ASSERT_EQUALS("a--bb--ccc", StringOps::join(tokens, "--"));
81         TS_ASSERT_EQUALS("a bb ccc", StringOps::join(tokens, " "));
82         TS_ASSERT_EQUALS("abbccc", StringOps::join(tokens, ""));
83     }
84 };
85 
86 }
87