test.operations.containOnly 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
module test.operations.containOnly; import fluentasserts.core.expect; import fluent.asserts; import trial.discovery.spec; import std.string; import std.conv; import std.meta; import std.algorithm; import std.range; alias s = Spec!({ alias StringTypes = AliasSeq!(string, wstring, dstring); static foreach(Type; StringTypes) { describe("using a range of " ~ Type.stringof, { Type[] testValues; Type[] testValuesWithOtherOrder; Type[] otherTestValues; before({ testValues = [ "40".to!Type, "41".to!Type, "42".to!Type ]; testValuesWithOtherOrder = [ "42".to!Type, "41".to!Type, "40".to!Type ]; otherTestValues = [ "50".to!Type, "51".to!Type ]; }); it("should find all items in the expected list", { expect(testValues).to.containOnly(testValuesWithOtherOrder); }); it("should not fail on checking if the list contains only a substring", { expect(testValues).not.to.containOnly(testValues[0..2]); }); it("should find all duplicated items", { expect(testValues ~ testValues).to.containOnly(testValuesWithOtherOrder ~ testValuesWithOtherOrder); }); it("should not fail on checking if the list contains only a substring of unique values", { expect(testValues ~ testValues).not.to.containOnly(testValues); }); it("should throw a detailed error when the array does not contain only the provided values", { auto msg = ({ expect(testValues).to.containOnly(testValues[0..2]); }).should.throwException!TestException.msg; msg.split('\n')[0].should.equal(testValues.to!string ~ " should containOnly " ~ testValues[0..2].to!string ~ "."); msg.split('\n')[2].strip.should.equal("Actual:" ~ testValues.to!string); msg.split('\n')[4].strip.should.equal("Missing:" ~ testValues[$-1..$].to!string); }); it("should throw a detailed error when the list shoul not contain some values", { auto msg = ({ expect(testValues).to.not.containOnly(testValuesWithOtherOrder); }).should.throwException!TestException.msg; msg.split('\n')[0].should.equal(testValues.to!string ~ " should not containOnly " ~ testValuesWithOtherOrder.to!string ~ "."); msg.split('\n')[2].strip.should.equal("Expected:to not contain " ~ testValuesWithOtherOrder.to!string); msg.split('\n')[3].strip.should.equal("Actual:" ~ testValues.to!string); }); }); } alias NumericTypes = AliasSeq!(byte, ubyte, short, ushort, int, uint, long, ulong, float, double, real, ifloat, idouble, ireal, cfloat, cdouble, creal); static foreach(Type; NumericTypes) { describe("using a range of " ~ Type.stringof, { Type[] testValues; Type[] testValuesWithOtherOrder; Type[] otherTestValues; static if(is(ifloat == Type) || is(idouble == Type) || is(ireal == Type)) { before({ testValues = [ 40i, 41i, 42i]; testValuesWithOtherOrder = [ 42i, 41i, 40i]; otherTestValues = [ 50i, 51i ]; }); } else { before({ testValues = [ cast(Type) 40, cast(Type) 41, cast(Type) 42 ]; testValuesWithOtherOrder = [ cast(Type) 42, cast(Type) 41, cast(Type) 40 ]; otherTestValues = [ cast(Type) 50, cast(Type) 51 ]; }); } it("should find all items in the expected list", { expect(testValues).to.containOnly(testValuesWithOtherOrder); }); it("should not fail on checking if the list contains only a substring", { expect(testValues).not.to.containOnly(testValues[0..2]); }); it("should find all duplicated items", { expect(testValues ~ testValues).to.containOnly(testValuesWithOtherOrder ~ testValuesWithOtherOrder); }); it("should not fail on checking if the list contains only a substring of unique values", { expect(testValues ~ testValues).not.to.containOnly(testValues); }); it("should throw a detailed error when the array does not contain only the provided values", { auto msg = ({ expect(testValues).to.containOnly(testValues[0..2]); }).should.throwException!TestException.msg; msg.split('\n')[0].should.equal(testValues.to!string ~ " should containOnly " ~ testValues[0..2].to!string ~ "."); msg.split('\n')[2].strip.should.equal("Actual:" ~ testValues.to!string); msg.split('\n')[4].strip.should.equal("Missing:" ~ testValues[$-1..$].to!string); }); it("should throw a detailed error when the list shoul not contain some values", { auto msg = ({ expect(testValues).to.not.containOnly(testValuesWithOtherOrder); }).should.throwException!TestException.msg; msg.split('\n')[0].should.equal(testValues.to!string ~ " should not containOnly " ~ testValuesWithOtherOrder.to!string ~ "."); msg.split('\n')[2].strip.should.equal("Expected:to not contain " ~ testValuesWithOtherOrder.to!string); msg.split('\n')[3].strip.should.equal("Actual:" ~ testValues.to!string); }); }); } });