fluentasserts.core.lifecycle 98/99(98%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
321
331
340
351
360
371
380
391
401
411
421
431
441
451
461
471
481
490
501
511
520
531
541
550
561
571
581
590
601
611
621
630
641
651
660
671
681
690
701
710
720
7311
7411
750
760
770
7811
7911
8011
810
8211
8311
8411
850
8611
8711
880
890
900
910
9211
9311
9411
9511
960
970
980
990
10011
10111
10211
1030
1040
105121
106121
107121
1080
109121
110121
111121
1120
113121
114121
115121
1160
117121
1180
1190
12011
1210
1220
1230
1241
1251
1260
1270
1284
1290
1300
13116
13216
1330
13416
13516
13616
1370
13816
13916
1400
1410
1420
1431
1441
1451
1461
1470
1480
1494
1504
1514
1520
1530
1541
1550
1561
1571
1580
1591
1601
1611
1621
1631
1641
1651
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1803269
1810
1823269
1830
1840
1850
1860
1875169
1880
1893267
1903267
1910
1923264
19318
1940
1950
1963246
1970
1980
1990
2003246
2012759
2020
2030
2040
205487
2060
2070
208487
209487
2100
2110
212487
2130
2140
module fluentasserts.core.lifecycle; import fluentasserts.core.base; import fluentasserts.core.evaluation; import fluentasserts.core.operations.approximately; import fluentasserts.core.operations.arrayEqual; import fluentasserts.core.operations.beNull; import fluentasserts.core.operations.between; import fluentasserts.core.operations.contain; import fluentasserts.core.operations.endWith; import fluentasserts.core.operations.equal; import fluentasserts.core.operations.greaterThan; import fluentasserts.core.operations.greaterOrEqualTo; import fluentasserts.core.operations.instanceOf; import fluentasserts.core.operations.lessThan; import fluentasserts.core.operations.lessOrEqualTo; import fluentasserts.core.operations.registry; import fluentasserts.core.operations.startWith; import fluentasserts.core.operations.throwable; import fluentasserts.core.results; import fluentasserts.core.serializers; import std.meta; import std.conv; import std.datetime; alias BasicNumericTypes = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real); alias NumericTypes = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real/* , ifloat, idouble, ireal, cfloat, cdouble, creal, char, wchar, dchar*/); alias StringTypes = AliasSeq!(string, wstring, dstring, const(char)[]); static this() { SerializerRegistry.instance = new SerializerRegistry; Lifecycle.instance = new Lifecycle; ResultGlyphs.resetDefaults; Registry.instance = new Registry(); Registry.instance.describe("approximately", approximatelyDescription); Registry.instance.describe("equal", equalDescription); Registry.instance.describe("beNull", beNullDescription); Registry.instance.describe("between", betweenDescription); Registry.instance.describe("within", betweenDescription); Registry.instance.describe("contain", containDescription); Registry.instance.describe("greaterThan", greaterThanDescription); Registry.instance.describe("above", greaterThanDescription); Registry.instance.describe("greaterOrEqualTo", greaterOrEqualToDescription); Registry.instance.describe("lessThan", lessThanDescription); Registry.instance.register!(Duration, Duration)("lessThan", &lessThanDuration); Registry.instance.register!(Duration, Duration)("below", &lessThanDuration); Registry.instance.register!(SysTime, SysTime)("lessThan", &lessThanSysTime); Registry.instance.register!(SysTime, SysTime)("below", &lessThanSysTime); Registry.instance.register!(Duration, Duration)("greaterThan", &greaterThanDuration); Registry.instance.register!(Duration, Duration)("greaterOrEqualTo", &greaterOrEqualToDuration); Registry.instance.register!(Duration, Duration)("above", &greaterThanDuration); Registry.instance.register!(SysTime, SysTime)("greaterThan", &greaterThanSysTime); Registry.instance.register!(SysTime, SysTime)("greaterOrEqualTo", &greaterOrEqualToSysTime); Registry.instance.register!(SysTime, SysTime)("above", &greaterThanSysTime); Registry.instance.register!(Duration, Duration)("between", &betweenDuration); Registry.instance.register!(Duration, Duration)("within", &betweenDuration); Registry.instance.register!(SysTime, SysTime)("between", &betweenSysTime); Registry.instance.register!(SysTime, SysTime)("within", &betweenSysTime); Registry.instance.register("*", "*", "equal", &equal); static foreach(Type; NumericTypes) { Registry.instance.register(Type.stringof ~ "[]", Type.stringof ~ "[]", "equal", &arrayEqual); Registry.instance.register(Type.stringof ~ "[]", "void[]", "equal", &arrayEqual); } static foreach(Type; BasicNumericTypes) { Registry.instance.register(Type.stringof, Type.stringof, "greaterOrEqualTo", &greaterOrEqualTo!Type); Registry.instance.register(Type.stringof, Type.stringof, "greaterThan", &greaterThan!Type); Registry.instance.register(Type.stringof, Type.stringof, "above", &greaterThan!Type); Registry.instance.register(Type.stringof, Type.stringof, "lessOrEqualTo", &lessOrEqualTo!Type); Registry.instance.register(Type.stringof, Type.stringof, "lessThan", &lessThan!Type); Registry.instance.register(Type.stringof, Type.stringof, "below", &lessThan!Type); Registry.instance.register(Type.stringof, Type.stringof, "between", &between!Type); Registry.instance.register(Type.stringof, Type.stringof, "within", &between!Type); } /// special cases for .length and other comparisons with int types static foreach(Type; BasicNumericTypes) { Registry.instance.register(Type.stringof, "int", "lessOrEqualTo", &lessOrEqualTo!Type); Registry.instance.register(Type.stringof, "int", "lessThan", &lessThan!Type); Registry.instance.register(Type.stringof, "int", "greaterOrEqualTo", &greaterOrEqualTo!Type); Registry.instance.register(Type.stringof, "int", "greaterThan", &greaterThan!Type); } /// static foreach(Type1; NumericTypes) { Registry.instance.register(Type1.stringof ~ "[]", "void[]", "approximately", &approximatelyList); Registry.instance.register("*[]", "*", "contain", &arrayContain); Registry.instance.register("*[][]", "*[][]", "containOnly", &arrayContainOnly); static foreach(Type2; NumericTypes) { Registry.instance.register(Type1.stringof, Type2.stringof, "equal", &equal); Registry.instance.register(Type1.stringof ~ "[]", Type2.stringof ~ "[]", "equal", &arrayEqual); Registry.instance.register(Type1.stringof ~ "[]", "void[]", "equal", &arrayEqual); Registry.instance.register(Type1.stringof ~ "[]", Type2.stringof ~ "[]", "contain", &arrayContain); Registry.instance.register(Type1.stringof ~ "[]", "void[]", "contain", &arrayContain); Registry.instance.register(Type1.stringof ~ "[]", Type2.stringof, "contain", &arrayContain); Registry.instance.register(Type1.stringof ~ "[]", Type2.stringof ~ "[]", "containOnly", &arrayContainOnly); Registry.instance.register(Type1.stringof ~ "[]", "void[]", "containOnly", &arrayContainOnly); Registry.instance.register(Type1.stringof ~ "[]", Type2.stringof ~ "[]", "approximately", &approximatelyList); Registry.instance.register(Type1.stringof, Type2.stringof, "approximately", &approximately); } Registry.instance.register("object.Object[]", "object.Object[]", "containOnly", &arrayContainOnly); } Registry.instance.register("*[]", "*[]", "contain", &arrayContain); Registry.instance.register("*[]", "*[]", "containOnly", &arrayContainOnly); static foreach(Type1; StringTypes) { Registry.instance.register(Type1.stringof ~ "[]", "void[]", "equal", &arrayEqual); static foreach(Type2; StringTypes) { Registry.instance.register(Type1.stringof, Type2.stringof, "equal", &equal); Registry.instance.register(Type1.stringof ~ "[]", Type2.stringof ~ "[]", "equal", &arrayEqual); Registry.instance.register(Type1.stringof, Type2.stringof ~ "[]", "contain", &contain); Registry.instance.register(Type1.stringof, Type2.stringof, "contain", &contain); Registry.instance.register(Type1.stringof ~ "[]", Type2.stringof ~ "[]", "containOnly", &arrayContainOnly); Registry.instance.register(Type1.stringof, Type2.stringof, "startWith", &startWith); Registry.instance.register(Type1.stringof, Type2.stringof, "endWith", &endWith); } } Registry.instance.register("*[]", "*[]", "equal", &arrayEqual); Registry.instance.register("*[*]", "*[*]", "equal", &arrayEqual); Registry.instance.register("*[][]", "*[][]", "equal", &arrayEqual); Registry.instance.register("*", "*", "equal", &equal); static foreach(Type; StringTypes) { Registry.instance.register(Type.stringof, "char", "contain", &contain); Registry.instance.register(Type.stringof, "char", "startWith", &startWith); Registry.instance.register(Type.stringof, "char", "endWith", &endWith); } Registry.instance.register("*", "*", "instanceOf", &instanceOf); Registry.instance.register("callable", "", "throwAnyException", &throwAnyException); Registry.instance.register("callable", "", "throwException", &throwException); Registry.instance.register("*", "*", "throwAnyException", &throwAnyException); Registry.instance.register("*", "*", "throwAnyException.withMessage.equal", &throwAnyExceptionWithMessage); Registry.instance.register("*", "*", "throwException", &throwException); Registry.instance.register("*", "*", "throwException.withMessage.equal", &throwExceptionWithMessage); Registry.instance.register("*", "*", "throwSomething", &throwAnyException); Registry.instance.register("*", "*", "throwSomething.withMessage.equal", &throwAnyExceptionWithMessage); Registry.instance.register("*", "*", "beNull", &beNull); } /// The assert lifecycle @safe class Lifecycle { /// Global instance for the assert lifecicle static Lifecycle instance; private { /// int totalAsserts; } /// Method called when a new value is evaluated int beginEvaluation(ValueEvaluation value) @safe nothrow { totalAsserts++; return totalAsserts; } /// void endEvaluation(ref Evaluation evaluation) @trusted { if(evaluation.isEvaluated) return; evaluation.isEvaluated = true; auto results = Registry.instance.handle(evaluation); if(evaluation.currentValue.throwable !is null) { throw evaluation.currentValue.throwable; } if(evaluation.expectedValue.throwable !is null) { throw evaluation.currentValue.throwable; } if(results.length == 0) { return; } version(DisableSourceResult) {} else { results ~= evaluation.source; } if(evaluation.message !is null) { results = evaluation.message ~ results; } throw new TestException(results, evaluation.source.file, evaluation.source.line); } }