fluentasserts.core.string 138/138(100%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
146
150
160
172
182
190
200
212
222
230
240
252
262
270
280
292
302
310
320
332
342
350
360
372
382
390
400
410
420
430
442
452
460
470
483
492
500
510
522
532
542
550
562
572
580
590
603
612
620
630
642
652
662
670
682
692
700
710
723
732
740
750
762
772
782
790
802
812
820
830
843
852
860
870
882
892
902
910
920
930
940
952
962
970
980
993
1002
1010
1020
1032
1042
1052
1060
1072
1082
1090
1100
1113
1122
1130
1140
1152
1162
1172
1180
1192
1202
1210
1220
1233
1242
1250
1260
1272
1282
1292
1300
1312
1322
1330
1340
1353
1362
1370
1380
1392
1402
1412
1420
1430
1440
1450
1462
1472
1482
1490
1500
1512
1522
1532
1540
1550
1562
1572
1582
1590
1600
1613
1622
1630
1640
1652
1662
1672
1680
1693
1702
1710
1720
1732
1742
1752
1760
1773
1782
1790
1800
1812
1822
1832
1840
1853
1862
1870
1880
1892
1902
1912
1920
1933
1942
1950
1960
1972
1982
1992
2000
2013
2022
2030
2040
2052
2062
2072
2080
2090
2100
2110
2122
2132
2140
2150
2162
2172
2180
2190
2203
2212
2220
2230
2242
2250
2263
2272
2280
2290
2302
2310
2323
2331
2342
2350
2360
2372
2382
2392
2400
2410
2420
2430
2440
2451
2460
2470
2482
2490
2501
2511
2520
2530
2542
2550
2562
2571
2580
2590
2602
2610
2620
2630
2640
2651
2661
2670
2682
2692
2700
2712
2722
2730
module fluentasserts.core.string; public import fluentasserts.core.base; import fluentasserts.core.results; import std.string; import std.conv; import std.algorithm; import std.array; /// When there is a lazy string that throws an it should throw that exception unittest { string someLazyString() { throw new Exception("This is it."); } ({ someLazyString.should.equal(""); }).should.throwAnyException.withMessage("This is it."); ({ someLazyString.should.contain(""); }).should.throwAnyException.withMessage("This is it."); ({ someLazyString.should.contain([""]); }).should.throwAnyException.withMessage("This is it."); ({ someLazyString.should.contain(' '); }).should.throwAnyException.withMessage("This is it."); ({ someLazyString.should.startWith(" "); }).should.throwAnyException.withMessage("This is it."); ({ someLazyString.should.endWith(" "); }).should.throwAnyException.withMessage("This is it."); } @("string startWith") unittest { ({ "test string".should.startWith("test"); }).should.not.throwAnyException; auto msg = ({ "test string".should.startWith("other"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`"test string" does not start with "other"`); msg.split("\n")[2].strip.should.equal(`Expected:to start with "other"`); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); ({ "test string".should.not.startWith("other"); }).should.not.throwAnyException; msg = ({ "test string".should.not.startWith("test"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`"test string" starts with "test"`); msg.split("\n")[2].strip.should.equal(`Expected:to not start with "test"`); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); ({ "test string".should.startWith('t'); }).should.not.throwAnyException; msg = ({ "test string".should.startWith('o'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`"test string" does not start with 'o'`); msg.split("\n")[2].strip.should.equal("Expected:to start with 'o'"); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); ({ "test string".should.not.startWith('o'); }).should.not.throwAnyException; msg = ({ "test string".should.not.startWith('t'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`"test string" starts with 't'`); msg.split("\n")[2].strip.should.equal(`Expected:to not start with 't'`); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); } @("string endWith") unittest { ({ "test string".should.endWith("string"); }).should.not.throwAnyException; auto msg = ({ "test string".should.endWith("other"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`"test string" does not end with "other"`); msg.split("\n")[2].strip.should.equal(`Expected:to end with "other"`); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); ({ "test string".should.not.endWith("other"); }).should.not.throwAnyException; msg = ({ "test string".should.not.endWith("string"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should not end with "string". "test string" ends with "string".`); msg.split("\n")[2].strip.should.equal(`Expected:to not end with "string"`); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); ({ "test string".should.endWith('g'); }).should.not.throwAnyException; msg = ({ "test string".should.endWith('t'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`"test string" does not end with 't'`); msg.split("\n")[2].strip.should.equal("Expected:to end with 't'"); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); ({ "test string".should.not.endWith('w'); }).should.not.throwAnyException; msg = ({ "test string".should.not.endWith('g'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`"test string" ends with 'g'`); msg.split("\n")[2].strip.should.equal("Expected:to not end with 'g'"); msg.split("\n")[3].strip.should.equal(`Actual:"test string"`); } @("string contain") unittest { ({ "test string".should.contain(["string", "test"]); "test string".should.not.contain(["other", "message"]); }).should.not.throwAnyException; ({ "test string".should.contain("string"); "test string".should.not.contain("other"); }).should.not.throwAnyException; ({ "test string".should.contain('s'); "test string".should.not.contain('z'); }).should.not.throwAnyException; auto msg = ({ "test string".should.contain(["other", "message"]); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should contain ["other", "message"]. ["other", "message"] are missing from "test string".`); msg.split("\n")[2].strip.should.equal(`Expected:to contain all ["other", "message"]`); msg.split("\n")[3].strip.should.equal("Actual:test string"); msg = ({ "test string".should.not.contain(["test", "string"]); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should not contain ["test", "string"]. ["test", "string"] are present in "test string".`); msg.split("\n")[2].strip.should.equal(`Expected:to not contain any ["test", "string"]`); msg.split("\n")[3].strip.should.equal("Actual:test string"); msg = ({ "test string".should.contain("other"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should contain "other". other is missing from "test string".`); msg.split("\n")[2].strip.should.equal(`Expected:to contain "other"`); msg.split("\n")[3].strip.should.equal("Actual:test string"); msg = ({ "test string".should.not.contain("test"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should not contain "test". test is present in "test string".`); msg.split("\n")[2].strip.should.equal(`Expected:to not contain "test"`); msg.split("\n")[3].strip.should.equal("Actual:test string"); msg = ({ "test string".should.contain('o'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.contain(`o is missing from "test string"`); msg.split("\n")[2].strip.should.equal("Expected:to contain 'o'"); msg.split("\n")[3].strip.should.equal("Actual:test string"); msg = ({ "test string".should.not.contain('t'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should not contain 't'. t is present in "test string".`); msg.split("\n")[2].strip.should.equal("Expected:to not contain 't'"); msg.split("\n")[3].strip.should.equal("Actual:test string"); } @("string equal") unittest { ({ "test string".should.equal("test string"); }).should.not.throwAnyException; ({ "test string".should.not.equal("test"); }).should.not.throwAnyException; auto msg = ({ "test string".should.equal("test"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should equal "test". "test string" is not equal to "test".`); msg = ({ "test string".should.not.equal("test string"); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should not equal "test string". "test string" is equal to "test string".`); msg = ({ ubyte[] data = [115, 111, 109, 101, 32, 100, 97, 116, 97, 0, 0]; data.assumeUTF.to!string.should.equal("some data"); }).should.throwException!TestException.msg; msg.should.contain(`Actual:"some data\0\0"`); msg.should.contain(`data.assumeUTF.to!string should equal "some data". "some data\0\0" is not equal to "some data".`); msg.should.contain(`some data[+\0\0]`); } /// should throw exceptions for delegates that return basic types unittest { string value() { throw new Exception("not implemented"); } value().should.throwAnyException.withMessage.equal("not implemented"); string noException() { return null; } 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); } @("const string equal") unittest { const string constValue = "test string"; immutable string immutableValue = "test string"; constValue.should.equal("test string"); immutableValue.should.equal("test string"); "test string".should.equal(constValue); "test string".should.equal(immutableValue); }