fluentasserts.core.lifecycle 93/99(93%) 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
329
339
340
359
360
379
380
399
409
419
429
439
449
459
469
479
489
490
509
519
520
539
549
550
569
579
589
590
609
619
629
630
649
659
660
679
689
690
709
710
720
7399
7499
750
760
770
7899
7999
8099
810
8299
8399
8499
850
8699
8799
880
890
900
910
9299
9399
9499
9599
960
970
980
990
10099
10199
10299
1030
1040
1051089
1061089
1071089
1080
1091089
1101089
1111088
1120
1131087
1141089
1151089
1160
1171089
1180
1190
12099
1210
1220
1230
1249
1259
1260
1270
12836
1290
1300
131144
132144
1330
134144
135144
136144
1370
138144
139144
1400
1410
1420
1439
1449
1459
1469
1470
1480
14936
15036
15136
1520
1530
1549
1550
1569
1579
1580
1599
1609
1619
1629
1639
1649
1659
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
180556
1810
182556
1830
1840
1850
1860
187556
1880
189556
190556
1910
192556
1930
1940
1950
196556
1970
1980
1990
200556
201556
2020
2030
2040
2050
2060
2070
2080
2090
2100
2110
2120
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); } }