[350120]: contrib / mul / mbl / tests / test_read_props.cxx  Maximize  Restore  History

Download this file

206 lines (170 with data), 6.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// This is mul/mbl/tests/test_read_props.cxx
#include <vcl_iostream.h>
#include <vcl_sstream.h>
#include <mbl/mbl_read_props.h>
#include <testlib/testlib_test.h>
vcl_string strip_ws(vcl_string &s)
{
vcl_string out;
vcl_string::size_type i=0;
while (i < s.length())
{
if (s[i] != ' ' && s[i] != '\n')
out += s[i];
i++;
}
return out;
}
void test_read_props()
{
vcl_cout << "\n************************\n"
<< " Testing mbl_read_props\n"
<< "************************\n";
{
vcl_cout << "\nCase 1\n";
vcl_istringstream ss("{}");
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 1: props[ \"a\" ] == \"\"",
props[ "a" ] == "" && !ss.fail(), true);
}
#if 0 // This one won't work because the { } should be on their own lines
{
vcl_cout << "\nCase 2\n";
vcl_istringstream ss("{ a: a }");
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 2: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
}
#endif // 0
{
vcl_cout << "\nCase 3\n";
vcl_istringstream ss("{\n a: a\n }");
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 3: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
}
{
vcl_cout << "\nCase 4\n";
vcl_istringstream ss("{\n // comment\n a: a\n }");
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 4: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
}
{
vcl_cout << "\nCase 5\n";
vcl_istringstream ss("{\n // comment\n a: a\n b: b\n }");
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 5a: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
TEST("Case 5b: props[ \"b\" ] == \"b\"",
props[ "b" ] == "b" && !ss.fail(), true);
}
{
vcl_cout << "\nCase 6\n";
vcl_istringstream ss("{\n // comment\n a: a\n a: b\n }");
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 6: props[ \"a\" ] == \"b\"",
props[ "a" ] == "b" && !ss.fail(), true);
}
{
vcl_cout << "\nCase 7\n";
vcl_istringstream ss("{\n // comment\n a: a\n // comment\n b: b\n }");
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 7a: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
TEST("Case 7b: props[ \"b\" ] == \"b\"",
props[ "b" ] == "b" && !ss.fail(), true);
}
{
vcl_cout << "\nCase 8\n";
vcl_istringstream ss("{\n a: a\n b: b\n {\n ba: ba\n }\n}");
vcl_string b_ans( "b\n{\n ba: ba\n }" );
// vcl_cout << ss.str() << vcl_endl;
// vcl_cout << b_ans << vcl_endl;
mbl_read_props_type props = mbl_read_props( ss );
// vcl_cout << props[ "b" ] << vcl_endl;
mbl_read_props_print(vcl_cout, props);
TEST("Case 8a: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
vcl_istringstream ssb(props[ "b" ]);
vcl_string sb;
ssb >> sb;
TEST("Case 8b: props[ \"b\" ] == b.*", sb == "b" && !ss.fail(), true);
mbl_read_props_type propsb = mbl_read_props( ssb );
mbl_read_props_print(vcl_cout, propsb);
TEST("Case 8c: propsb[ \"ba\" ] == \"ba\"",
propsb[ "ba" ] == "ba" && !ssb.fail(), true);
}
{
vcl_cout << "\nCase 8.5\n";
vcl_istringstream ss("{\n a: a\n b: b\n {\n ba: ba\n bb: bb\n }\n}");
vcl_string b_ans( "b\n{\n ba: ba\n bb: bb\n }" );
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 8.5a: props[ \"a\" ] == \"a\"", props[ "a" ] == "a" && !ss.fail(), true);
TEST("Case 8.5b: props[ \"b\" ] == b_ans",
strip_ws(props[ "b" ]) == strip_ws(b_ans) && !ss.fail(), true);
}
{
vcl_cout << "\nCase 9\n";
vcl_istringstream ss("{\n a: a\n b: b\n {\n ba: ba\n }\n c: c\n}");
vcl_string b_ans( "b\n{\n ba: ba\n }" );
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 9a: props[ \"a\" ] == \"a\"", props[ "a" ] == "a" && !ss.fail(), true);
TEST("Case 9b: props[ \"b\" ] == b_ans",
strip_ws(props[ "b" ]) == strip_ws(b_ans) && !ss.fail(), true);
TEST("Case 9c: props[ \"c\" ] == \"c\"", props[ "c" ] == "c", true);
}
{
vcl_cout << "\nCase 10\n";
vcl_istringstream ss("{\n a: a\n b: b\n {\n ba: ba\n }\n c: c\n d: d\n {\n da: da\n }\n}");
vcl_string b_ans( "b\n{\n ba: ba\n }" );
vcl_string d_ans( "d\n{\n da: da\n }" );
mbl_read_props_type props = mbl_read_props( ss );
mbl_read_props_print(vcl_cout, props);
TEST("Case 10a: props[ \"a\" ] == \"a\"", props[ "a" ] == "a" && !ss.fail(), true);
TEST("Case 10b: props[ \"b\" ] == b_ans",
strip_ws(props[ "b" ]) == strip_ws(b_ans) && !ss.fail(), true);
TEST("Case 10c: props[ \"c\" ] == \"c\"", props[ "c" ] == "c", true);
TEST("Case 10d: props[ \"d\" ] == d_ans",
strip_ws(props[ "d" ]) == strip_ws(d_ans) && !ss.fail(), true);
}
{
vcl_cout << "\nCase 11\n";
vcl_istringstream ss("{\n a: a\n b: b\n {\n ba: ba\n bb: bb\n {\n bba: bba\n }\n }\n}");
vcl_string b_ans( "b\n{\n ba: ba\n bb: bb\n {\n bba: bba\n }\n }" );
// vcl_cout << ss.str() << vcl_endl;
// vcl_cout << b_ans << vcl_endl;
mbl_read_props_type props = mbl_read_props( ss );
// vcl_cout << props[ "b" ] << vcl_endl;
mbl_read_props_print(vcl_cout, props);
TEST("Case 11a: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
TEST("Case 11b: props[ \"b\" ] == b_ans",
strip_ws(props[ "b" ]) == strip_ws(b_ans) && !ss.fail(), true);
}
{
vcl_cout << "\nCase 12\n";
vcl_istringstream ss("{\n a: a\n b: \n {\n ba: ba\n bb: bb\n {\n bba: bba\n }\n }\n}");
vcl_string b_ans( "{\n ba: ba\n bb: bb\n {\n bba: bba\n }\n }" );
// vcl_cout << ss.str() << vcl_endl;
// vcl_cout << b_ans << vcl_endl;
mbl_read_props_type props = mbl_read_props( ss );
// vcl_cout << props[ "b" ] << vcl_endl;
mbl_read_props_print(vcl_cout, props);
TEST("Case 12a: props[ \"a\" ] == \"a\"",
props[ "a" ] == "a" && !ss.fail(), true);
TEST("Case 12b: props[ \"b\" ] == b_ans",
strip_ws(props[ "b" ]) == strip_ws(b_ans) && !ss.fail(), true);
}
vcl_cout << "\n\n";
}
TESTMAIN(test_read_props);

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks