forked from Poordeveloper/ini-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
112 lines (91 loc) · 1.49 KB
/
test.cpp
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
#include "ini.hpp"
#include <sstream>
void test1();
void test2();
void test3();
void test4();
void test5();
int main()
{
test1();
test2();
test3();
test4();
test5();
return 0;
}
void test1()
{
std::stringstream ss;
ss <<
"a=1\n"
"b=1\n\n"
"[e]\n"
"ea=1\n"
"eb=1\n\n"
"[c]\n"
"ca=2\n"
"cb=2\n\n"
"[[d]]\n"
"da=3\n"
"db=3\n\n"
"[A]\n"
"Aa=4\n"
"Ab=4\n";
INI::Parser p(ss);
std::stringstream out;
p.dump(out);
assert(out.str() == ss.str());
assert(p.top()["a"]=="1");
assert(p.top()("e")["ea"]=="1");
}
void test2()
{
std::stringstream ss;
ss <<
"a=1\n"
"a=1\n\n";
try {
INI::Parser p(ss);
} catch (std::runtime_error& e) {
assert(std::string(e.what()) == "duplicated key found on line #2");
}
}
void test3()
{
std::stringstream ss;
ss <<
"a=1\n"
"b\n";
try {
INI::Parser p(ss);
} catch (std::runtime_error& e) {
assert(std::string(e.what()) == "no '=' found on line #2");
}
}
void test4()
{
std::stringstream ss;
ss <<
"a=1\n"
"[b]\n"
"[[[a]]]\n";
try {
INI::Parser p(ss);
} catch (std::runtime_error& e) {
assert(std::string(e.what()) == "section with wrong depth on line #3");
}
}
void test5()
{
std::stringstream ss;
ss <<
"a=1\n"
"[b]\n"
"[b]\n";
try {
INI::Parser p(ss);
} catch (std::runtime_error& e) {
assert(std::string(e.what()) == "duplicate section name on the same level on line #3");
}
}