fluentasserts.core.basetype 115/123(93%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
135
140
150
162
172
180
190
202
212
220
230
242
252
260
270
282
292
300
310
322
332
340
350
360
370
380
392
402
412
420
430
443
452
460
470
482
490
503
512
520
530
542
550
560
570
580
592
602
612
620
630
643
652
660
670
682
692
702
710
723
732
740
750
762
772
782
790
800
810
820
832
842
852
860
872
882
890
900
913
922
930
940
950
962
970
983
992
1000
1010
1020
1032
1040
1050
1060
1070
1082
1092
1102
1110
1122
1132
1140
1150
1163
1172
1180
1190
1200
1212
1222
1232
1240
1253
1262
1270
1280
1290
1302
1310
1320
1330
1340
1352
1362
1372
1382
1392
1400
1412
1422
1432
1442
1450
1460
1473
1482
1490
1500
1510
1522
1532
1542
1550
1563
1572
1580
1590
1600
1612
1622
1632
1640
1653
1662
1670
1680
1690
1702
1712
1722
1730
1743
1752
1760
1770
1780
1792
1802
1812
1820
1830
1840
1850
1862
1872
1882
1890
1900
1913
1922
1930
1940
1952
1962
1972
1980
1993
2002
2010
2020
2032
2042
2052
2060
2070
2080
2090
2100
2111
2120
2130
2140
2152
2160
2170
2180
2190
2202
2212
2220
2231
2240
2250
2262
2270
2282
2291
2300
2312
2320
2331
2340
2350
2362
2370
2381
2392
2400
2410
2422
2430
2440
2450
2460
2471
2482
2490
module fluentasserts.core.basetype; public import fluentasserts.core.base; import fluentasserts.core.results; import std.string; import std.conv; import std.algorithm; /// When there is a lazy number that throws an it should throw that exception unittest { int someLazyInt() { throw new Exception("This is it."); } ({ someLazyInt.should.equal(3); }).should.throwAnyException.withMessage("This is it."); ({ someLazyInt.should.be.greaterThan(3); }).should.throwAnyException.withMessage("This is it."); ({ someLazyInt.should.be.lessThan(3); }).should.throwAnyException.withMessage("This is it."); ({ someLazyInt.should.be.between(3, 4); }).should.throwAnyException.withMessage("This is it."); ({ someLazyInt.should.be.approximately(3, 4); }).should.throwAnyException.withMessage("This is it."); } @("numbers equal") unittest { ({ 5.should.equal(5); 5.should.not.equal(6); }).should.not.throwAnyException; auto msg = ({ 5.should.equal(6); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should equal 6. 5 is not equal to 6."); msg = ({ 5.should.not.equal(5); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should not equal 5. 5 is equal to 5."); } @("bools equal") unittest { ({ true.should.equal(true); true.should.not.equal(false); }).should.not.throwAnyException; auto msg = ({ true.should.equal(false); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("true should equal false."); msg.split("\n")[2].strip.should.equal("Expected:false"); msg.split("\n")[3].strip.should.equal("Actual:true"); msg = ({ true.should.not.equal(true); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("true should not equal true."); msg.split("\n")[2].strip.should.equal("Expected:not true"); msg.split("\n")[3].strip.should.equal("Actual:true"); } @("numbers greater than") unittest { ({ 5.should.be.greaterThan(4); 5.should.not.be.greaterThan(6); 5.should.be.above(4); 5.should.not.be.above(6); }).should.not.throwAnyException; auto msg = ({ 5.should.be.greaterThan(5); 5.should.be.above(5); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should be greater than 5. 5 is less than or equal to 5."); msg = ({ 5.should.not.be.greaterThan(4); 5.should.not.be.above(4); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should not be greater than 4. 5 is greater than 4."); } @("numbers less than") unittest { ({ 5.should.be.lessThan(6); 5.should.not.be.lessThan(4); 5.should.be.below(6); 5.should.not.be.below(4); }).should.not.throwAnyException; auto msg = ({ 5.should.be.lessThan(4); 5.should.be.below(4); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should be less than 4. 5 is greater than or equal to 4."); msg.split("\n")[2].strip.should.equal("Expected:less than 4"); msg.split("\n")[3].strip.should.equal("Actual:5"); msg = ({ 5.should.not.be.lessThan(6); 5.should.not.be.below(6); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should not be less than 6. 5 is less than 6."); } @("numbers between") unittest { ({ 5.should.be.between(4, 6); 5.should.be.between(6, 4); 5.should.not.be.between(5, 6); 5.should.not.be.between(4, 5); 5.should.be.within(4, 6); 5.should.be.within(6, 4); 5.should.not.be.within(5, 6); 5.should.not.be.within(4, 5); }).should.not.throwAnyException; auto msg = ({ 5.should.be.between(5, 6); 5.should.be.within(5, 6); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should be between 5 and 6. 5 is less than or equal to 5."); msg.split("\n")[2].strip.should.equal("Expected:a value inside (5, 6) interval"); msg.split("\n")[3].strip.should.equal("Actual:5"); msg = ({ 5.should.be.between(4, 5); 5.should.be.within(4, 5); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal("5 should be between 4 and 5. 5 is greater than or equal to 5."); msg.split("\n")[2].strip.should.equal("Expected:a value inside (4, 5) interval"); msg.split("\n")[3].strip.should.equal("Actual:5"); msg = ({ 5.should.not.be.between(4, 6); 5.should.not.be.within(4, 6); }).should.throwException!TestException.msg; msg.split("\n")[0].strip.should.equal("5 should not be between 4 and 6."); msg.split("\n")[2].strip.should.equal("Expected:a value outside (4, 6) interval"); msg.split("\n")[3].strip.should.equal("Actual:5"); msg = ({ 5.should.not.be.between(6, 4); 5.should.not.be.within(6, 4); }).should.throwException!TestException.msg; msg.split("\n")[0].strip.should.equal("5 should not be between 6 and 4."); msg.split("\n")[2].strip.should.equal("Expected:a value outside (4, 6) interval"); msg.split("\n")[3].strip.should.equal("Actual:5"); } /// numbers approximately unittest { ({ (10f/3f).should.be.approximately(3, 0.34); (10f/3f).should.not.be.approximately(3, 0.1); }).should.not.throwAnyException; auto msg = ({ (10f/3f).should.be.approximately(3, 0.1); }).should.throwException!TestException.msg; msg.split("\n")[0].strip.should.contain("(10f/3f) should be approximately 3±0.1."); msg.split("\n")[2].strip.should.contain("Expected:3±0.1"); msg.split("\n")[3].strip.should.contain("Actual:3.33333"); msg = ({ (10f/3f).should.not.be.approximately(3, 0.34); }).should.throwException!TestException.msg; msg.split("\n")[0].strip.should.contain("(10f/3f) should not be approximately 3±0.34."); msg.split("\n")[2].strip.should.contain("Expected:not 3±0.34"); msg.split("\n")[3].strip.should.contain("Actual:3.33333"); } /// should throw exceptions for delegates that return basic types unittest { int value() { throw new Exception("not implemented value"); } void voidValue() { throw new Exception("nothing here"); } void noException() { } value().should.throwAnyException.withMessage.equal("not implemented value"); voidValue().should.throwAnyException.withMessage.equal("nothing here"); bool thrown; try { noException.should.throwAnyException; } catch (TestException e) { e.msg.should.startWith("noException should throw any exception. No exception was thrown."); thrown = true; } thrown.should.equal(true); thrown = false; try { voidValue().should.not.throwAnyException; } catch(TestException e) { thrown = true; e.msg.split("\n")[0].should.equal("voidValue() should not throw any exception. `object.Exception` saying `nothing here` was thrown."); } thrown.should.equal(true); } /// it should compile const comparison unittest { const actual = 42; actual.should.equal(42); }