fluentasserts.core.lifecycle 83/84(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
410
421
431
440
451
461
470
481
491
500
511
521
530
541
551
560
571
581
590
600
6120
6220
6320
640
650
660
6711
6811
6911
700
7111
7211
7311
740
7511
7611
770
780
790
800
8111
8211
8311
8411
850
860
870
880
8920
900
910
92400
93400
94400
950
96400
97400
98400
990
100400
101400
102400
1030
104400
1050
1060
1070
1080
1094
1100
1110
11216
11316
1140
11516
11616
11716
11816
11916
1200
12116
12216
1230
1240
1250
1261
1271
1280
1290
1304
1314
1324
1330
1340
1351
1360
1371
1381
1390
1401
1411
1421
1431
1441
1451
1461
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1613522
1620
1633522
1640
1650
1660
1670
1685590
1690
1703520
1713520
1720
1733517
17418
1750
1760
1773499
1780
1790
1800
1813499
1822970
1830
1840
1850
186529
1870
1880
189529
190529
1910
1920
193529
1940
1950
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.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)("above", &greaterThanDuration); Registry.instance.register!(SysTime, SysTime)("greaterThan", &greaterThanSysTime); 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("string", "string", "equal", &equal); Registry.instance.register("bool", "bool", "equal", &equal); static foreach(Type; NumericTypes) { Registry.instance.register(Type.stringof, Type.stringof, "equal", &equal); 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); 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); } } 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, "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, Type2.stringof, "startWith", &startWith); Registry.instance.register(Type1.stringof, Type2.stringof, "endWith", &endWith); } } 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); } }