-
Notifications
You must be signed in to change notification settings - Fork 0
/
ToTestWellFormattedTests.cs
514 lines (471 loc) · 18 KB
/
ToTestWellFormattedTests.cs
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
using System;
using System.Collections.Generic;
using ObjectToTest.UnitTests.Data;
using ObjectToTest.UnitTests.Models;
using Xunit;
using Xunit.Abstractions;
namespace ObjectToTest.UnitTests
{
/*
* @todo #5 60m/DEV Implement proper formatting. Base puzzle with all rules for references.
* The rules are following:
* 0. API should be compatible with old one.
* 1. if there is new operator in arguments, all arguments should be properly formatted.
* 2. spaces between arguments are required: (0, 0, 1) instead of (0,0,1).
* 3. Lambdas are always from new string.
* 4. Indention is 4 spaces.
* 5. Inner properties should be from separate lines.
* 6. Lines bigger than 80 characters should be properly formatted.
* 7. All arrays should be placed with proper formatting.
* 8. Dictionary should be formatted with separate set of rules.
*/
/*
* @todo #80 60m/DEV Describe formatting rules in readme file.
*/
/*
* @todo #5 60m/DEV Implement rule: if there is new operator in arguments, all arguments should be properly formatted.
*/
/*
* @todo #5 60m/DEV Implement rule: spaces between arguments are required: (0, 0, 1) instead of (0,0,1).
*/
/*
* @todo #5 60m/DEV Implement rule: Lambdas are always from new string.
*/
/*
* @todo #5 60m/DEV Implement rule: Indention is 4 spaces.
*/
/*
* @todo #5 60m/DEV Implement rule: Inner properties should be from separate lines.
*/
/*
* @todo #5 60m/DEV Implement rule: Lines bigger than 80 characters should be properly formatted.
*/
/*
* @todo #5 60m/DEV Implement rule: All arrays should be placed with proper formatting.
*/
/*
* @todo #5 60m/DEV Implement rule: Dictionary should be formatted with separate set of rules.
*/
public class ToTestWellFormattedTests
{
private readonly ITestOutputHelper _output;
public ToTestWellFormattedTests(ITestOutputHelper output)
{
_output = output;
}
[Fact]
public void NotImplementedForCurrentFunctionalityRevision()
{
// Remove this test after draft for ToTestWellFormatted
object? obj = null;
Assert.Throws<NotImplementedException>(() => obj.ToTestWellFormatted());
}
#pragma warning disable CS8604
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ThrowArgumentNullException_ShouldBehaveAsNotFormatted()
{
object? obj = null;
Assert.Throws<ArgumentNullException>(() => obj.ToTestWellFormatted());
}
#pragma warning restore CS8604
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void InnerPropertyShouldBeFromSeparateLine_StringPropertyInitializer()
{
Assert.Equal(
"new WithOnePublicProperty()" +
"{" +
" PropertyName = \"Test\"" +
"}",
new WithOnePublicProperty
{
PropertyName = "Test"
}.ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void InnerPropertyShouldBeFromSeparateLine_IntPropertyInitializer()
{
Assert.Equal(
"new WithOnePublicIntProperty()" +
"{" +
" PropertyName = 42" +
"}",
new WithOnePublicIntProperty
{
PropertyName = 42
}.ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void InnerPropertyShouldBeFromSeparateLine_MultipleValueTypesPropertyInitializer()
{
Assert.Equal(
"new WithTwoProperties()" +
"{" +
" IntProperty = 42," +
" StringProperty = \"Test\"" +
"}",
new WithTwoProperties
{
IntProperty = 42,
StringProperty = "Test"
}.ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ShortArgumentsWithoutNewPlacedInline_CtorWithIntArgumentForProperty()
{
Assert.Equal(
"new WithOneParameterContructorAndPublicReadProperty(42)",
new WithOneParameterContructorAndPublicReadProperty(42)
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ShortArgumentsWithoutNewPlacedInline_CtorWithIntArgumentForPrivateField()
{
Assert.Equal(
"new WithOneParamAndPrivateField(42)",
new WithOneParamAndPrivateField(42).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5, rule 2")]
public void ShortArgumentsWithoutNewPlacedInline_CtorWithMultipleValueTypeArguments()
{
Assert.Equal(
"new WithTwoParamOneFieldAndOneProperty(42, \"Test\")",
new WithTwoParamOneFieldAndOneProperty(
42,
"Test"
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5, rule 6")]
public void StringMoreThan80CharsShouldBeFormatted_CtorWithMultipleLongValueTypeArguments()
{
Assert.Equal(
"new WithTwoParamOneFieldAndOneProperty(" +
" 42," +
" \"Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test\"" +
")",
new WithTwoParamOneFieldAndOneProperty(
42,
"Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test"
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_CtorWithReferenceTypeArgument()
{
Assert.Equal(
"new WithClassParam(" +
" new EmptyObject()" +
")",
new WithClassParam(new EmptyObject()).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_CtorWithMultipleComplexTypesArguments()
{
Assert.Equal(
"new WithClassAndIntParams(" +
" 42," +
" new EmptyObject()" +
")",
new WithClassAndIntParams(
42,
new EmptyObject()
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5, rule 2")]
public void ShortArgumentsShouldBeSeparatedBySpace_TimeSpanConstructor()
{
Assert.Equal(
"new TimeSpan(18, 17, 34, 24, 5)",
new TimeSpan(18, 17, 34, 24, 5)
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_CtorWithComplexDependencyArgument()
{
Assert.Equal(
"new WithClassParamThatDependsOnClass(" +
" new WithClassParam(" +
" new EmptyObject()" +
" )" +
")",
new WithClassParamThatDependsOnClass(
new WithClassParam(new EmptyObject())
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_CtorWithComplexDependencySeveralArguments()
{
Assert.Equal(
"new WithTwoClassParamAndIntParam(" +
" new WithClassParam(" +
" new EmptyObject()" +
" )," +
" new WithClassAndIntParams(" +
" 42," +
" new EmptyObject()" +
" )," +
" 42" +
")",
new WithTwoClassParamAndIntParam(
new WithClassParam(new EmptyObject()),
new WithClassAndIntParams(
42,
new EmptyObject()
),
42
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void InnerPropertyShouldBeFromSeparateLine__And_ArgumentWithNewShouldBeFormatted__CtorWithComplexArgumentsAndProperties()
{
Assert.Equal(
"new WithClassParamWithProp(" +
" new WithOnePublicProperty()" +
" {" +
" PropertyName = \"Test\"" +
" }," +
" 42" +
")",
new WithClassParamWithProp(
new WithOnePublicProperty { PropertyName = "Test" },
42
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void GenericArgumentsAreNotFormatted_CtorWithGenericArgument()
{
Assert.Equal(
"new WithGenericArgument<IPrice>()",
new WithGenericArgument<IPrice>().ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void GenericArgumentsAreNotFormatted_With2GenericArguments()
{
Assert.Equal(
"new With2GenericArguments<IPrice,IUser>(" +
" new Price(" +
" 10" +
" )" +
")",
new With2GenericArguments<IPrice, IUser>(new Price(10))
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void GenericArgumentsAreNotFormatted_With3GenericArguments()
{
Assert.Equal(
"new With3GenericArguments<int,decimal,string>()",
new With3GenericArguments<int, decimal, string>()
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5, rule 2")]
public void ShortArgumentsShouldBeSeparatedBySpace_And_ArgumentWithNewShouldBeFormatted_CtorWithStructArgument()
{
Assert.Equal(
"new WithStructArgument(" +
" new Vector3(0, 0, 1)" +
")",
new WithStructArgument(UnityEngine.Vector3.forward)
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ShortArgumentsWithoutNewPlacedInline_CtorWithEnumArgument()
{
Assert.Equal(
"new WithEnumArgument(FlaggedEnum.Advanced)",
new WithEnumArgument(FlaggedEnum.Advanced)
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void LambdasShouldBePlacedOnNewLine_CtorWithFuncArgument()
{
Assert.Equal(
"new WithFuncArgument(" +
" () => 0" +
")",
new WithFuncArgument(() => 0)
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void LambdasShouldBePlacedOnNewLine_CtorWithActionArgument()
{
Assert.Equal(
"new WithActionArgument(" +
" pos => {}" +
")",
new WithActionArgument((pos) => { })
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArraysShouldBeFormatted_CtorWithIEnumerableInt()
{
Assert.Equal(
"new WithIEnumerableInt(" +
" new[] " +
" {" +
" 1," +
" 2," +
" 4," +
" 5" +
" }" +
")",
new WithIEnumerableInt(new[] { 1, 2, 4, 5 })
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArraysShouldBeFormatted_CtorWithListInt()
{
Assert.Equal(
"new WithListArgument(" +
" new List<int> " +
" {" +
" 1," +
" 2," +
" 4," +
" 5" +
" }" +
")",
new WithListArgument(new List<int> { 1, 2, 4, 5 })
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_CtorWithEmptyListInt()
{
Assert.Equal(
"new WithListArgument(" +
" new List<int>()" +
")",
new WithListArgument(new List<int>())
.ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void DictionaryShouldBeFormatted_CtorWithDictionaryIntString()
{
Assert.Equal(
"new WithDictionaryArgument(" +
" new Dictionary<int,string>" +
" {" +
" { 1, \"1\" }," +
" { 2, \"2\" }," +
" { 3, \"3\" }" +
" }" +
")",
new WithDictionaryArgument(
new Dictionary<int,string> { { 1, "1" }, { 2, "2" }, { 3, "3" } }
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_CtorWithEmptyDictionaryIntString()
{
Assert.Equal(
"new WithDictionaryArgument(" +
" new Dictionary<int,string>()" +
")",
new WithDictionaryArgument(
new Dictionary<int, string>()
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_And_ShortArgumentsWithoutNewPlacedInline_CtorWithInterfaceArguments()
{
Assert.Equal(
"new Foo(" +
" new Price(10)," +
" new User(\"User Name\")" +
")",
new Foo(
new Price(10),
new User("User Name")
).ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_And_InnerPropertyShouldBeFromSeparateLine_TheSameObjectDetection()
{
var user = new User("user name");
var withUser = new WithUserArgument(
user,
new WithUserPublicProperty
{
User = user
}
);
Assert.Equal(
"var user = new User(\"user name\");" + Environment.NewLine +
"new WithUserArgument(" +
" user," +
" new WithUserPublicProperty()" +
" {" +
" User = user" +
" }" +
")",
withUser.ToTestWellFormatted().Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_SingletonAsSharedArgument()
{
Assert.Equal(
"new SharedSingletons(" +
" new WithSingletonAndOtherArgument(" +
" SingletonClass.Instance," +
" new Price(10)" +
" )," +
" new WithSingletonArgument(SingletonClass.Instance)" +
")",
new SharedSingletons(
new WithSingletonAndOtherArgument(SingletonClass.Instance, new Price(10)),
new WithSingletonArgument(SingletonClass.Instance)
).ToTestWellFormatted()
.Log(_output)
);
}
[Fact(Skip = "Need to be fixed in scope of puzzle #5")]
public void ArgumentWithNewShouldBeFormatted_SingletonWithOtherArgument()
{
Assert.Equal(
"new WithSingletonAndOtherArgument(" +
" SingletonClass.Instance," +
" new Price(10)" +
")",
new WithSingletonAndOtherArgument(SingletonClass.Instance, new Price(10))
.ToTestWellFormatted()
.Log(_output)
);
}
}
}