Skip to content

Commit 6b35796

Browse files
committed
Formatting properties by default
1 parent 513f474 commit 6b35796

File tree

3 files changed

+61
-24
lines changed

3 files changed

+61
-24
lines changed

Entitas.Utils/Entitas.Utils/Utils/Configuration/Properties.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public string this[string key] {
2828
}
2929
set {
3030
_dict[key.Trim()] = value
31-
.TrimStart()
31+
.Trim()
3232
.Replace("\\n", "\n")
3333
.Replace("\\t", "\t");
3434
}
@@ -115,10 +115,25 @@ static string[] mergeMultilineValues(string[] lines) {
115115
}
116116

117117
public override string ToString() {
118+
return _dict.Aggregate(string.Empty, (properties, kv) => {
119+
var contentValues = kv.Value
120+
.Replace("\n", "\\n")
121+
.Replace("\t", "\\t")
122+
.ArrayFromCSV()
123+
.Select(value => value.PadLeft(kv.Key.Length + 3 + value.Length))
124+
.ToArray();
125+
126+
var content = string.Join(", \\\n", contentValues).TrimStart();
127+
128+
return properties + kv.Key + " = " + content + (contentValues.Length > 1 ? "\n\n" : "\n");
129+
});
130+
}
131+
132+
public string ToMinifiedString() {
118133
return _dict.Aggregate(string.Empty, (properties, kv) => {
119134
var content = kv.Value
120-
.Replace("\n", "\\n")
121-
.Replace("\t", "\\t");
135+
.Replace("\n", "\\n")
136+
.Replace("\t", "\\t");
122137

123138
return properties + kv.Key + " = " + content + "\n";
124139
});

Tests/Tests/Tests/Entitas.CodeGeneration/describe_CodeGeneratorConfig.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,20 @@ void when_creating_config() {
5757

5858
it["gets string"] = () => {
5959
config.ToString().should_be(
60-
"Entitas.CodeGeneration.CodeGenerator.SearchPaths = newS1, newS2\n" +
61-
"Entitas.CodeGeneration.CodeGenerator.Plugins = newP1, newP2\n" +
60+
"Entitas.CodeGeneration.CodeGenerator.SearchPaths = newS1, \\\n" +
61+
" newS2\n\n" +
6262

63-
"Entitas.CodeGeneration.CodeGenerator.DataProviders = newDp1, newDp2\n" +
64-
"Entitas.CodeGeneration.CodeGenerator.CodeGenerators = newCg1, newCg2\n" +
65-
"Entitas.CodeGeneration.CodeGenerator.PostProcessors = newPp1, newPp2\n"
63+
"Entitas.CodeGeneration.CodeGenerator.Plugins = newP1, \\\n" +
64+
" newP2\n\n" +
65+
66+
"Entitas.CodeGeneration.CodeGenerator.DataProviders = newDp1, \\\n" +
67+
" newDp2\n\n" +
68+
69+
"Entitas.CodeGeneration.CodeGenerator.CodeGenerators = newCg1, \\\n" +
70+
" newCg2\n\n" +
71+
72+
"Entitas.CodeGeneration.CodeGenerator.PostProcessors = newPp1, \\\n" +
73+
" newPp2\n\n"
6674
);
6775
};
6876
};

Tests/Tests/Tests/Entitas.Utils/Configuration/describe_Properties.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ void when_creating_properties() {
9494
assertProperties(input, expectedOutput, expectedProperties);
9595
};
9696

97-
it["keeps whitespace after value"] = () => {
97+
it["removes whitespace after value"] = () => {
9898
const string input = "some.key = some value ";
9999

100-
const string expectedOutput = "some.key = some value \n";
100+
const string expectedOutput = "some.key = some value\n";
101101
var expectedProperties = new Dictionary<string, string> {
102-
{ "some.key", "some value " }
102+
{ "some.key", "some value" }
103103
};
104104

105105
assertProperties(input, expectedOutput, expectedProperties);
@@ -111,17 +111,17 @@ void when_creating_properties() {
111111
it["creates Properties from multiline input string"] = () => {
112112
var input =
113113
"some.key.1=some value 1" + "\n" +
114-
" some.key.2 = some value 2 " + "\n" +
114+
" some.key.2 = some value 2" + "\n" +
115115
"some.key.3=some value 3" + "\n";
116116

117117
const string expectedOutput =
118118
"some.key.1 = some value 1\n" +
119-
"some.key.2 = some value 2 \n" +
119+
"some.key.2 = some value 2\n" +
120120
"some.key.3 = some value 3\n";
121121

122122
var expectedProperties = new Dictionary<string, string> {
123123
{ "some.key.1", "some value 1" },
124-
{ "some.key.2", "some value 2 " },
124+
{ "some.key.2", "some value 2" },
125125
{ "some.key.3", "some value 3" }
126126
};
127127

@@ -131,17 +131,17 @@ void when_creating_properties() {
131131
it["creates Properties from multiline input string where values contain ="] = () => {
132132
var input =
133133
"some.key.1=some=value 1" + "\n" +
134-
"some.key.2 ==some value 2 " + "\n" +
134+
"some.key.2 ==some value 2" + "\n" +
135135
"some.key.3=some value=" + "\n";
136136

137137
const string expectedOutput =
138138
"some.key.1 = some=value 1\n" +
139-
"some.key.2 = =some value 2 \n" +
139+
"some.key.2 = =some value 2\n" +
140140
"some.key.3 = some value=\n";
141141

142142
var expectedProperties = new Dictionary<string, string> {
143143
{ "some.key.1", "some=value 1" },
144-
{ "some.key.2", "=some value 2 " },
144+
{ "some.key.2", "=some value 2" },
145145
{ "some.key.3", "some value=" }
146146
};
147147

@@ -153,18 +153,18 @@ void when_creating_properties() {
153153
"\n" +
154154
"some.key.1=some value 1" + "\n" +
155155
"\n" +
156-
" some.key.2 = some value 2 " + "\n" +
156+
" some.key.2 = some value 2" + "\n" +
157157
"\n" +
158158
"some.key.3=some value 3" + "\n";
159159

160160
const string expectedOutput =
161161
"some.key.1 = some value 1\n" +
162-
"some.key.2 = some value 2 \n" +
162+
"some.key.2 = some value 2\n" +
163163
"some.key.3 = some value 3\n";
164164

165165
var expectedProperties = new Dictionary<string, string> {
166166
{ "some.key.1", "some value 1" },
167-
{ "some.key.2", "some value 2 " },
167+
{ "some.key.2", "some value 2" },
168168
{ "some.key.3", "some value 3" }
169169
};
170170

@@ -243,7 +243,7 @@ void when_creating_properties() {
243243
var values = new Properties(input).values;
244244
values.Length.should_be(3);
245245
values.should_contain("some value 1");
246-
values.should_contain("some value 2 ");
246+
values.should_contain("some value 2");
247247
values.should_contain("some value 3");
248248
};
249249

@@ -331,9 +331,9 @@ void when_creating_properties() {
331331
p["key"].should_be("value");
332332
};
333333

334-
it["keeps trailing whitespace of value"] = () => {
335-
p["key"] = "value ";
336-
p["key"].should_be("value ");
334+
it["removes trailing whitespace of value"] = () => {
335+
p["key"] = "value";
336+
p["key"].should_be("value");
337337
};
338338

339339
it["adds properties from dictionary"] = () => {
@@ -480,6 +480,20 @@ void when_creating_properties() {
480480
assertProperties(input, expectedOutput, expectedProperties);
481481
};
482482
};
483+
484+
context["minified string"] = () => {
485+
486+
it["puts values in one line"] = () => {
487+
var properties = new Properties(
488+
@"key = value1, value2, value3
489+
key2 = value4");
490+
491+
properties.ToMinifiedString().should_be(
492+
@"key = value1, value2, value3
493+
key2 = value4
494+
");
495+
};
496+
};
483497
}
484498

485499
void when_creating_properties_from_dictionary() {

0 commit comments

Comments
 (0)