diff options
author | rathnor <rathnor> | 2002-12-01 13:42:15 (GMT) |
---|---|---|
committer | rathnor <rathnor> | 2002-12-01 13:42:15 (GMT) |
commit | 28b5c604490094e187494dcc566bd3d7a05a2c25 (patch) | |
tree | 8f78f5714a5cd055c10b067a2656fe7b2338e71a /src/tests/StringUtiltest.cc | |
parent | b9134162f9633784d9097df18769a699a62650fe (diff) | |
download | fluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.zip fluxbox-28b5c604490094e187494dcc566bd3d7a05a2c25.tar.bz2 |
Indenting from tabs to emacs 4-space
Diffstat (limited to 'src/tests/StringUtiltest.cc')
-rw-r--r-- | src/tests/StringUtiltest.cc | 164 |
1 files changed, 82 insertions, 82 deletions
diff --git a/src/tests/StringUtiltest.cc b/src/tests/StringUtiltest.cc index ecad2df..8d8f206 100644 --- a/src/tests/StringUtiltest.cc +++ b/src/tests/StringUtiltest.cc | |||
@@ -38,106 +38,106 @@ uds::uds_flags_t uds::flags = uds::leak_check|uds::log_allocs; | |||
38 | using namespace std; | 38 | using namespace std; |
39 | 39 | ||
40 | void testStringtok() { | 40 | void testStringtok() { |
41 | vector<string> ls; | 41 | vector<string> ls; |
42 | StringUtil::stringtok(ls, " arg1 arg2 \targ3\n arg4 arg5\t\t\t\targ6\n\n \n\n \t\t\narg7"); | 42 | StringUtil::stringtok(ls, " arg1 arg2 \targ3\n arg4 arg5\t\t\t\targ6\n\n \n\n \t\t\narg7"); |
43 | cerr<<"Size: "<<ls.size()<<". Should be: 7."<<endl; | 43 | cerr<<"Size: "<<ls.size()<<". Should be: 7."<<endl; |
44 | for (vector<string>::const_iterator i = ls.begin(); | 44 | for (vector<string>::const_iterator i = ls.begin(); |
45 | i != ls.end(); ++i) { | 45 | i != ls.end(); ++i) { |
46 | cerr << ':' << (*i) << ":\n"; | 46 | cerr << ':' << (*i) << ":\n"; |
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | void testExpandFilename() { | 50 | void testExpandFilename() { |
51 | string filename(StringUtil::expandFilename("~/filename/~filename2/file3~/file4")); | 51 | string filename(StringUtil::expandFilename("~/filename/~filename2/file3~/file4")); |
52 | cerr<<"test "; | 52 | cerr<<"test "; |
53 | string test = string(getenv("HOME"))+"/filename/~filename2/file3~/file4"; | 53 | string test = string(getenv("HOME"))+"/filename/~filename2/file3~/file4"; |
54 | if (test == filename) | 54 | if (test == filename) |
55 | cerr<<"ok."; | 55 | cerr<<"ok."; |
56 | else | 56 | else |
57 | cerr<<"faild"; | 57 | cerr<<"faild"; |
58 | cerr<<endl; | 58 | cerr<<endl; |
59 | } | 59 | } |
60 | 60 | ||
61 | void testStrcasestr() { | 61 | void testStrcasestr() { |
62 | cerr<<"test1 "; | 62 | cerr<<"test1 "; |
63 | if (StringUtil::strcasestr("Test", "TEST") == strcasestr("Test", "TEST")) | 63 | if (StringUtil::strcasestr("Test", "TEST") == strcasestr("Test", "TEST")) |
64 | cerr<<"ok."<<endl; | 64 | cerr<<"ok."<<endl; |
65 | else | 65 | else |
66 | cerr<<"faild."<<endl; | 66 | cerr<<"faild."<<endl; |
67 | 67 | ||
68 | cerr<<"test2 "; | 68 | cerr<<"test2 "; |
69 | if (StringUtil::strcasestr("Test", "ESTabc") == strcasestr("Test", "ESTabc")) | 69 | if (StringUtil::strcasestr("Test", "ESTabc") == strcasestr("Test", "ESTabc")) |
70 | cerr<<"ok."<<endl; | 70 | cerr<<"ok."<<endl; |
71 | else | 71 | else |
72 | cerr<<"faild."<<endl; | 72 | cerr<<"faild."<<endl; |
73 | 73 | ||
74 | cerr<<"test3 "; | 74 | cerr<<"test3 "; |
75 | if (StringUtil::strcasestr("TeSt", "abcTEStabc") == strcasestr("TeSt", "abcTEStabc")) | 75 | if (StringUtil::strcasestr("TeSt", "abcTEStabc") == strcasestr("TeSt", "abcTEStabc")) |
76 | cerr<<"ok."<<endl; | 76 | cerr<<"ok."<<endl; |
77 | else | 77 | else |
78 | cerr<<"faild."<<endl; | 78 | cerr<<"faild."<<endl; |
79 | 79 | ||
80 | cerr<<"test4 "; | 80 | cerr<<"test4 "; |
81 | if (StringUtil::strcasestr("TEST", "_TEST;_") == strcasestr("TEST", "_TEST;_")) | 81 | if (StringUtil::strcasestr("TEST", "_TEST;_") == strcasestr("TEST", "_TEST;_")) |
82 | cerr<<"ok."<<endl; | 82 | cerr<<"ok."<<endl; |
83 | else | 83 | else |
84 | cerr<<"faild."<<endl; | 84 | cerr<<"faild."<<endl; |
85 | 85 | ||
86 | } | 86 | } |
87 | 87 | ||
88 | void showError(int line, int pos, string& instr) { | 88 | void showError(int line, int pos, string& instr) { |
89 | 89 | ||
90 | cerr<<"Error on line: "<<line<<endl; | 90 | cerr<<"Error on line: "<<line<<endl; |
91 | cerr<<instr<<endl; | 91 | cerr<<instr<<endl; |
92 | for (int c=0; c<pos; c++) { | 92 | for (int c=0; c<pos; c++) { |
93 | if (instr[c]=='\t') | 93 | if (instr[c]=='\t') |
94 | cerr<<'\t'; | 94 | cerr<<'\t'; |
95 | else | 95 | else |
96 | cerr<<" "; | 96 | cerr<<" "; |
97 | } | 97 | } |
98 | cerr<<"^ here"<<endl; | 98 | cerr<<"^ here"<<endl; |
99 | 99 | ||
100 | } | 100 | } |
101 | 101 | ||
102 | void testGetStringBetween() { | 102 | void testGetStringBetween() { |
103 | string out; | 103 | string out; |
104 | vector<string> stringlist; | 104 | vector<string> stringlist; |
105 | stringlist.push_back(" \t\t\t \t[(in \\)\t haha )] \t\t "); | 105 | stringlist.push_back(" \t\t\t \t[(in \\)\t haha )] \t\t "); |
106 | stringlist.push_back("(in\\)) {_ _ my_ _}"); | 106 | stringlist.push_back("(in\\)) {_ _ my_ _}"); |
107 | stringlist.push_back("(in) {_ _ my_ _}"); | 107 | stringlist.push_back("(in) {_ _ my_ _}"); |
108 | stringlist.push_back("(in){_ _ my_ _}"); | 108 | stringlist.push_back("(in){_ _ my_ _}"); |
109 | stringlist.push_back("\t \t \t ( in ) {haha}"); | 109 | stringlist.push_back("\t \t \t ( in ) {haha}"); |
110 | stringlist.push_back("\t \t \t (( in \\) ) {haha}"); | 110 | stringlist.push_back("\t \t \t (( in \\) ) {haha}"); |
111 | stringlist.push_back("\t \t \t (( in \\) ){hihi}"); | 111 | stringlist.push_back("\t \t \t (( in \\) ){hihi}"); |
112 | stringlist.push_back("\t \t \t (( in \\) )|{hihi}"); | 112 | stringlist.push_back("\t \t \t (( in \\) )|{hihi}"); |
113 | for (unsigned int i=0; i<stringlist.size(); i++) { | 113 | for (unsigned int i=0; i<stringlist.size(); i++) { |
114 | int pos = StringUtil::getStringBetween(out, stringlist[i].c_str(), '(', ')'); | 114 | int pos = StringUtil::getStringBetween(out, stringlist[i].c_str(), '(', ')'); |
115 | int total_pos = 0; | 115 | int total_pos = 0; |
116 | if (pos<0) { | 116 | if (pos<0) { |
117 | showError(i+1, -pos, stringlist[i]); | 117 | showError(i+1, -pos, stringlist[i]); |
118 | continue; | 118 | continue; |
119 | } | 119 | } |
120 | cerr<<"string="<<stringlist[i]<<endl; | 120 | cerr<<"string="<<stringlist[i]<<endl; |
121 | cerr<<"pos="<<pos<<" ::"<<out; | 121 | cerr<<"pos="<<pos<<" ::"<<out; |
122 | total_pos += pos; | 122 | total_pos += pos; |
123 | pos = StringUtil::getStringBetween(out, stringlist[i].c_str()+total_pos, '{', '}'); | 123 | pos = StringUtil::getStringBetween(out, stringlist[i].c_str()+total_pos, '{', '}'); |
124 | if (pos<=0) { | 124 | if (pos<=0) { |
125 | pos=-pos; | 125 | pos=-pos; |
126 | showError(i+1, total_pos+pos, stringlist[i]); | 126 | showError(i+1, total_pos+pos, stringlist[i]); |
127 | continue; | 127 | continue; |
128 | } | 128 | } |
129 | cerr<<"::"<<out<<"::"<<endl; | 129 | cerr<<"::"<<out<<"::"<<endl; |
130 | total_pos += pos; | 130 | total_pos += pos; |
131 | } | 131 | } |
132 | } | 132 | } |
133 | int main() { | 133 | int main() { |
134 | #ifdef UDS | 134 | #ifdef UDS |
135 | uds::Init uds_init; | 135 | uds::Init uds_init; |
136 | #endif | 136 | #endif |
137 | cerr<<"Testing stringtok."<<endl; | 137 | cerr<<"Testing stringtok."<<endl; |
138 | testStringtok(); | 138 | testStringtok(); |
139 | cerr<<"Testing expandFilename."<<endl; | 139 | cerr<<"Testing expandFilename."<<endl; |
140 | testExpandFilename(); | 140 | testExpandFilename(); |
141 | cerr<<"Testing strcasestr."<<endl; | 141 | cerr<<"Testing strcasestr."<<endl; |
142 | testStrcasestr(); | 142 | testStrcasestr(); |
143 | } | 143 | } |