fluentasserts.core.string 0/0(100%) 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
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1800
1810
1820
1830
1840
1850
1860
1870
1880
1890
1900
1910
1920
1930
1940
1950
1960
1970
1980
1990
2000
2010
2020
2030
2040
2050
2060
2070
2080
2090
2100
2110
2120
2130
2140
2150
2160
2170
2180
2190
2200
2210
2220
2230
2240
2250
2260
2270
2280
2290
2300
2310
2320
2330
2340
2350
2360
2370
2380
2390
2400
2410
2420
2430
2440
2450
2460
2470
2480
2490
2500
2510
2520
2530
2540
2550
2560
2570
2580
2590
2600
2610
2620
2630
2640
2650
2660
2670
2680
2690
2700
2710
2720
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); }