Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ts-bugfix.cpp « tests - github.com/windirstat/simpleini.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1234b8fb81eb64c58b0e6483f11010f2e76d0b92 (plain)
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
#include "pch.h"
#include "../SimpleIni.h"

TEST(TestBugFix, TestEmptySection) {
	CSimpleIniA ini;
	ini.SetValue("foo", "skey", "sval");
	ini.SetValue("", "rkey", "rval");
	ini.SetValue("bar", "skey", "sval");

	std::string output;
	ini.Save(output);

	std::string expected =
		"rkey = rval\n"
		"\n"
		"\n"
		"[foo]\n"
		"skey = sval\n"
		"\n"
		"\n"
		"[bar]\n"
		"skey = sval\n";

	output.erase(std::remove(output.begin(), output.end(), '\r'), output.end());
	ASSERT_STREQ(expected.c_str(), output.c_str());
}

TEST(TestBugFix, TestMultiLineIgnoreTrailSpace0) {
	std::string input =
		"; multiline values\n"
		"key = <<<EOS\n"
		"This is a\n"
		"multiline value\n"
		"and it ends.\n"
		"EOS\n"
		"\n"
		"[section]\n";

	bool multiline = true;
	CSimpleIniA ini(true, false, multiline);

	SI_Error rc = ini.LoadData(input);
	ASSERT_EQ(rc, SI_OK);

	std::string output;
	ini.Save(output);

	std::string expected =
		"; multiline values\n"
		"\n"
		"\n"
		"key = <<<END_OF_TEXT\n"
		"This is a\n"
		"multiline value\n"
		"and it ends.\n"
		"END_OF_TEXT\n"
		"\n"
		"\n"
		"[section]\n";

	output.erase(std::remove(output.begin(), output.end(), '\r'), output.end());
	ASSERT_STREQ(expected.c_str(), output.c_str());
}

TEST(TestBugFix, TestMultiLineIgnoreTrailSpace1) {
	std::string input =
		"; multiline values\n"
		"key = <<<EOS\n"
		"This is a\n"
		"multiline value\n"
		"and it ends.\n"
		"EOS \n"
		"\n"
		"[section]\n";

	bool multiline = true;
	CSimpleIniA ini(true, false, multiline);

	SI_Error rc = ini.LoadData(input);
	ASSERT_EQ(rc, SI_OK);

	std::string output;
	ini.Save(output);

	std::string expected =
		"; multiline values\n"
		"\n"
		"\n"
		"key = <<<END_OF_TEXT\n"
		"This is a\n"
		"multiline value\n"
		"and it ends.\n"
		"END_OF_TEXT\n"
		"\n"
		"\n"
		"[section]\n";

	output.erase(std::remove(output.begin(), output.end(), '\r'), output.end());
	ASSERT_STREQ(expected.c_str(), output.c_str());
}

TEST(TestBugFix, TestMultiLineIgnoreTrailSpace2) {
	std::string input =
		"; multiline values\n"
		"key = <<<EOS\n"
		"This is a\n"
		"multiline value\n"
		"and it ends.\n"
		"EOS  \n"
		"\n"
		"[section]\n";

	bool multiline = true;
	CSimpleIniA ini(true, false, multiline);

	SI_Error rc = ini.LoadData(input);
	ASSERT_EQ(rc, SI_OK);

	std::string output;
	ini.Save(output);

	std::string expected =
		"; multiline values\n"
		"\n"
		"\n"
		"key = <<<END_OF_TEXT\n"
		"This is a\n"
		"multiline value\n"
		"and it ends.\n"
		"END_OF_TEXT\n"
		"\n"
		"\n"
		"[section]\n";

	output.erase(std::remove(output.begin(), output.end(), '\r'), output.end());
	ASSERT_STREQ(expected.c_str(), output.c_str());
}