fluentasserts.core.expect 53/53(100%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
182397
192397
200
210
220
230
244105
254105
264105
274105
280
290
300
316502
322415
330
340
356502
360
370
380
390
40858
410
420
430
440
45329
46329
470
480
490
500
51513
52513
530
54513
550
560
570
580
598
600
610
620
630
644
650
664
670
680
690
704
714
720
730
740
750
761498
770
780
790
800
81295
820
830
840
850
8662
870
880
890
900
9126
920
930
940
9551
960
970
980
990
10026
1010
1020
1030
1040
10585
1060
1070
1080
1090
11037
1110
1120
1130
114142
1150
1160
1170
11849
1190
1200
1210
12288
1230
1240
1250
12628
1270
1280
1290
1302401
1314
1320
1330
1342401
1350
1360
1370
1380
13910
1400
14110
1420
1430
1440
1450
1462391
1470
1480
1494452
1502226
1510
1520
1530
154330
1550
1560
157660
1580
1590
160165
1610
1620
1632391
1640
1650
1660
1670
1680
1699
1709
1710
1720
1739
1740
1757
1767
1770
1781
1791
1800
1810
1829
1830
1840
1850
1860
1874776
1880
module fluentasserts.core.expect; import fluentasserts.core.lifecycle; import fluentasserts.core.evaluation; import std.traits; import std.conv; /// @safe struct Expect { /// bool isNegated; /// string operationName; this(ValueEvaluation value, const string file, const size_t line) { Lifecycle.instance.beginEvaluation(value) .atSourceLocation(file, line) .usingNegation(isNegated); } this(ref return scope Expect another) { this.isNegated = another.isNegated; this.operationName = another.operationName; Lifecycle.instance.incAssertIndex; } ~this() { if(!Lifecycle.instance.hasOperation) { Lifecycle.instance.usingOperation(operationName); } Lifecycle.instance.endEvaluation; } /// Expect to() { return this; } /// Expect be () { Lifecycle.instance.addText(" be"); return this; } /// Expect not() { isNegated = !isNegated; Lifecycle.instance.usingNegation(isNegated); return this; } /// auto throwAnyException() { return opDispatch!"throwAnyException"; } /// Expect throwException(Type)() { Lifecycle.instance.usingOperation("throwException"); return opDispatch!"throwException"(fullyQualifiedName!Type); } auto because(string reason) { Lifecycle.instance.prependText("Because " ~ reason ~ ", "); return this; } /// auto equal(T)(T value) { return opDispatch!"equal"(value); } /// auto contain(T)(T value) { return opDispatch!"contain"(value); } /// auto greaterThan(T)(T value) { return opDispatch!"greaterThan"(value); } /// auto above(T)(T value) { return opDispatch!"above"(value); } /// auto lessThan(T)(T value) { return opDispatch!"lessThan"(value); } /// auto below(T)(T value) { return opDispatch!"below"(value); } /// auto startWith(T)(T value) { return opDispatch!"startWith"(value); } /// auto endWith(T)(T value) { return opDispatch!"endWith"(value); } auto containOnly(T)(T value) { return opDispatch!"containOnly"(value); } auto approximately(T, U)(T value, U range) { return opDispatch!"approximately"(value, range); } auto between(T, U)(T value, U range) { return opDispatch!"between"(value, range); } auto within(T, U)(T value, U range) { return opDispatch!"within"(value, range); } void addOperationName(string value) { if(this.operationName) { this.operationName ~= "."; } this.operationName ~= value; } /// Expect opDispatch(string methodName)() { addOperationName(methodName); return this; } /// Expect opDispatch(string methodName, Params...)(Params params) if(Params.length > 0) { addOperationName(methodName); static if(Params.length == 1) { auto expectedValue = params[0].evaluate.evaluation; Lifecycle.instance.compareWith(expectedValue); } static if(Params.length > 1) { auto expectedValue = params[0].evaluate.evaluation; static foreach (i, Param; Params) { () @trusted { expectedValue.meta[i.to!string] = params[i].to!string; } (); } Lifecycle.instance.compareWith(expectedValue); } return this; } } /// Expect expect(void delegate() callable, const string file = __FILE__, const size_t line = __LINE__) @trusted { ValueEvaluation value; value.typeName = "callable"; try { callable(); } catch(Exception e) { value.throwable = e; value.meta["Exception"] = "yes"; } catch(Throwable t) { value.throwable = t; value.meta["Throwable"] = "yes"; } return Expect(value, file, line); } /// Expect expect(T)(lazy T testedValue, const string file = __FILE__, const size_t line = __LINE__) @trusted { return Expect(testedValue.evaluate.evaluation, file, line); }