10203040506070809010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099010001010102010301040105010601070108010901100111011201130114011501160117011801190120012101220123012401250126012701280129013001310132013301340135013601370138013901400141014201430144014501460 module test.operations.contain; 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 " ~ Type.stringof ~ " values", { Type testValue; Type[] listOfOtherValues; Type[] listOfValues; before({ testValue = "test string".to!Type; listOfOtherValues = ["string".to!Type, "test".to!Type]; listOfOtherValues = ["other".to!Type, "message".to!Type]; }); it("should find two substrings", { expect(testValue).to.contain(["string", "test"]); }); it("should not find matches from a list of strings", { expect(testValue).to.not.contain(["other", "message"]); }); it("should find a char", { expect(testValue).to.contain('s'); }); it("should not find a char that is not in the string", { expect(testValue).to.not.contain('z'); }); it("should show a detailed error message when the strings are not found", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string contains substrings that it should not", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string does not contains a substring", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string contains a substring that it should not", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string does not contains a char", { auto msg = ({ expect(testValue).to.contain('o'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should contain 'o'. 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"); }); it("should throw an error when the string contains a char that it should not", { auto msg = ({ expect(testValue).to.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"); }); }); describe("using a range of " ~ Type.stringof ~ " values", { Type testValue; Type[] listOfOtherValues; Type[] listOfValues; before({ testValue = "test string".to!Type; }); it("should find two substrings", { expect(testValue).to.contain(["string", "test"].inputRangeObject); }); it("should not find matches from a list of strings", { expect(testValue).to.not.contain(["other", "message"].inputRangeObject); }); it("should show a detailed error message when the strings are not found", { auto msg = ({ expect(testValue).to.contain(["other", "message"].inputRangeObject); }).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"); }); it("should throw an error when the string contains substrings that it should not", { auto msg = ({ expect(testValue).to.not.contain(["test", "string"].inputRangeObject); }).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"); }); }); } });
module test.operations.contain; 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 " ~ Type.stringof ~ " values", { Type testValue; Type[] listOfOtherValues; Type[] listOfValues; before({ testValue = "test string".to!Type; listOfOtherValues = ["string".to!Type, "test".to!Type]; listOfOtherValues = ["other".to!Type, "message".to!Type]; }); it("should find two substrings", { expect(testValue).to.contain(["string", "test"]); }); it("should not find matches from a list of strings", { expect(testValue).to.not.contain(["other", "message"]); }); it("should find a char", { expect(testValue).to.contain('s'); }); it("should not find a char that is not in the string", { expect(testValue).to.not.contain('z'); }); it("should show a detailed error message when the strings are not found", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string contains substrings that it should not", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string does not contains a substring", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string contains a substring that it should not", { auto msg = ({ expect(testValue).to.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"); }); it("should throw an error when the string does not contains a char", { auto msg = ({ expect(testValue).to.contain('o'); }).should.throwException!TestException.msg; msg.split("\n")[0].should.equal(`"test string" should contain 'o'. 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"); }); it("should throw an error when the string contains a char that it should not", { auto msg = ({ expect(testValue).to.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"); }); }); describe("using a range of " ~ Type.stringof ~ " values", { Type testValue; Type[] listOfOtherValues; Type[] listOfValues; before({ testValue = "test string".to!Type; }); it("should find two substrings", { expect(testValue).to.contain(["string", "test"].inputRangeObject); }); it("should not find matches from a list of strings", { expect(testValue).to.not.contain(["other", "message"].inputRangeObject); }); it("should show a detailed error message when the strings are not found", { auto msg = ({ expect(testValue).to.contain(["other", "message"].inputRangeObject); }).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"); }); it("should throw an error when the string contains substrings that it should not", { auto msg = ({ expect(testValue).to.not.contain(["test", "string"].inputRangeObject); }).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"); }); }); } });