diff --git a/source/fluentasserts/core/basetype.d b/source/fluentasserts/core/basetype.d index 8d92b2f..e669a55 100644 --- a/source/fluentasserts/core/basetype.d +++ b/source/fluentasserts/core/basetype.d @@ -7,144 +7,6 @@ import std.string; import std.conv; import std.algorithm; -@trusted: - -struct ShouldBaseType(T) { - private const T testData; - - this(U)(U value) { - valueEvaluation = value.evaluation; - testData = value.value; - } - - mixin ShouldCommons; - mixin ShouldThrowableCommons; - - alias above = typeof(this).greaterThan; - alias below = typeof(this).lessThan; - alias within = typeof(this).between; - - auto equal(const T someValue, const string file = __FILE__, const size_t line = __LINE__) { - validateException; - - addMessage(" equal `"); - addValue(someValue.to!string); - addMessage("`"); - beginCheck; - - auto isSame = testData == someValue; - - static if(is( T == bool )) { - auto expected = expectedValue ? someValue.to!string : (!someValue).to!string; - } else { - auto expected = expectedValue ? someValue.to!string : ("not " ~ someValue.to!string); - } - - return result(isSame, new ExpectedActualResult(expected, testData.to!string), file, line); - } - - auto greaterThan()(const T someValue, const string file = __FILE__, const size_t line = __LINE__) - if(!is(T == bool)) - { - validateException; - - addMessage(" greater than `"); - addValue(someValue.to!string); - addMessage("`"); - beginCheck; - - auto isGreater = testData > someValue; - auto mode = isGreater ? "greater than" : "less than or equal to"; - auto expectedMode = isGreater ? "less than or equal to" : "greater than"; - - Message[] msg = [ - Message(false, "`"), - Message(true, testData.to!string), - Message(false, "` is " ~ mode ~ " `"), - Message(true, someValue.to!string), - Message(false, "`.") - ]; - - return result(isGreater, msg, new ExpectedActualResult(expectedMode ~ " `" ~ someValue.to!string ~ "`", testData.to!string), file, line); - } - - auto lessThan()(const T someValue, const string file = __FILE__, const size_t line = __LINE__) - if(!is(T == bool)) - { - validateException; - - addMessage(" less than `"); - addValue(someValue.to!string); - addMessage("`"); - beginCheck; - - auto isLess = testData < someValue; - - Message[] msg = [ - Message(false, "`"), - Message(true, testData.to!string), - Message(false, isLess ? "` is less than `" : "` is greater or equal to `"), - Message(true, someValue.to!string), - Message(false, "`.") - ]; - - auto expectedMode = isLess ? "greater or equal to" : "less than"; - - return result(isLess, msg, new ExpectedActualResult(expectedMode ~ " `" ~ someValue.to!string ~ "`", testData.to!string), file, line); - } - - auto between()(const T limit1, const T limit2, const string file = __FILE__, const size_t line = __LINE__) - if(!is(T == bool)) - { - validateException; - - T min = limit1 < limit2 ? limit1 : limit2; - T max = limit1 > limit2 ? limit1 : limit2; - - addMessage(" between `"); - addValue(min.to!string); - addMessage("` and `"); - addValue(max.to!string); - addMessage("`"); - beginCheck; - - auto isLess = testData <= min; - auto isGreater = testData >= max; - auto isBetween = !isLess && !isGreater; - - Message[] msg; - - auto interval = "a value " ~ (expectedValue ? "inside" : "outside") ~ " (" ~ min.to!string ~ ", " ~ max.to!string ~ ") interval"; - - if(expectedValue) { - msg ~= [ Message(false, "`"), Message(true, testData.to!string), Message(false, "`") ]; - - if(isLess) { - msg ~= [ Message(false, " is less than or equal to `"), Message(true, min.to!string), Message(false, "`.") ]; - } - - if(isGreater) { - msg ~= [ Message(false, " is greater than or equal to `"), Message(true, max.to!string), Message(false, "`.") ]; - } - } - - return result(isBetween, msg, new ExpectedActualResult(interval, testData.to!string), file, line); - } - - auto approximately()(const T someValue, const T delta, const string file = __FILE__, const size_t line = __LINE__) - if(!is(T == bool)) - { - validateException; - - addMessage(" equal `"); - addValue(someValue.to!string ~ "±" ~ delta.to!string); - addMessage("`"); - beginCheck; - - return between(someValue - delta, someValue + delta, file, line); - } -} - /// When there is a lazy number that throws an it should throw that exception unittest { int someLazyInt() { diff --git a/source/fluentasserts/core/string.d b/source/fluentasserts/core/string.d index cb662c6..86f4c52 100644 --- a/source/fluentasserts/core/string.d +++ b/source/fluentasserts/core/string.d @@ -8,183 +8,6 @@ import std.conv; import std.algorithm; import std.array; -@safe: - -struct ShouldString { - private { - const string testData; - } - - mixin ShouldCommons; - mixin ShouldThrowableCommons; - - this(string value) { - testData = value; - } - - this(U)(U value) { - valueEvaluation = value.evaluation; - testData = value.value; - } - - auto equal(const string someString, const string file = __FILE__, const size_t line = __LINE__) @trusted { - validateException; - - addMessage(" equal `"); - addValue(someString.to!string); - addMessage("`"); - beginCheck; - - auto isSame = testData == someString; - - Message[] msg = [ - Message(false, "`"), - Message(true, testData), - Message(false, "` is" ~ (expectedValue ? " not" : "") ~ " equal to `"), - Message(true, someString), - Message(false, "`.") - ]; - - version(DisableDiffResult) { - return result(isSame, msg, cast(IResult[])[ new ExpectedActualResult(someString, testData) ], file, line); - } else { - return result(isSame, msg, cast(IResult[])[ new DiffResult(someString, testData), new ExpectedActualResult(someString, testData) ], file, line); - } - } - - auto contain(const string[] someStrings, const string file = __FILE__, const size_t line = __LINE__) { - validateException; - - addMessage(" contain `"); - addValue(someStrings.to!string); - addMessage("`"); - beginCheck; - - if(expectedValue) { - auto missingValues = someStrings.filter!(a => testData.indexOf(a) == -1).array; - Message[] msg = [ - Message(true, missingValues.to!string), - Message(false, " are missing from `"), - Message(true, testData), - Message(false, "`.") - ]; - - return result(missingValues.length == 0, msg, new ExpectedActualResult("to contain all " ~ someStrings.to!string, testData), file, line); - } else { - auto presentValues = someStrings.filter!(a => testData.indexOf(a) != -1).array; - Message[] msg = [ - Message(true, presentValues.to!string), - Message(false, " are present in `"), - Message(true, testData), - Message(false, "`.") - ]; - - return result(presentValues.length != 0, msg, new ExpectedActualResult("to not contain any " ~ someStrings.to!string, testData), file, line); - } - } - - auto contain(const string someString, const string file = __FILE__, const size_t line = __LINE__) { - validateException; - - addMessage(" contain `"); - addValue(someString); - addMessage("`"); - beginCheck; - - auto index = testData.indexOf(someString); - auto isPresent = index >= 0; - - Message[] msg = [ - Message(false, "`"), - Message(true, someString), - Message(false, expectedValue ? "` is missing from `" : "` is present in `"), - Message(true, testData), - Message(false, "`.") - ]; - - auto mode = expectedValue ? "to contain" : "to not contain"; - - return result(isPresent, msg, new ExpectedActualResult(mode ~ " `" ~ someString ~ "`", testData), file, line); - } - - auto contain(const char someChar, const string file = __FILE__, const size_t line = __LINE__) { - validateException; - - addMessage(" contain `"); - addValue(someChar.to!string); - addMessage("`"); - beginCheck; - - auto index = testData.indexOf(someChar); - auto isPresent = index >= 0; - - Message[] msg = [ - Message(false, "`"), - Message(true, someChar.to!string), - Message(false, isPresent ? "` is present in `" : "` is not present in `"), - Message(true, testData), - Message(false, "`.") - ]; - - auto mode = expectedValue ? "to contain" : "to not contain"; - - return result(isPresent, msg, new ExpectedActualResult(mode ~ " `" ~ someChar ~ "`", testData), file, line); - } - - auto startWith(T)(const T someString, const string file = __FILE__, const size_t line = __LINE__) { - validateException; - - addMessage(" start with `"); - addValue(someString.to!string); - addMessage("`"); - beginCheck; - - auto index = testData.indexOf(someString); - auto doesStartWith = index == 0; - - Message[] msg = [ - Message(false, "`"), - Message(true, testData.to!string), - Message(false, expectedValue ? "` does not start with `" : "` does start with `"), - Message(true, someString.to!string), - Message(false, "`.") - ]; - - auto mode = expectedValue ? "to start with " : "to not start with "; - - return result(doesStartWith, msg, new ExpectedActualResult(mode ~ "`" ~ someString.to!string ~ "`", testData), file, line); - } - - auto endWith(T)(const T someString, const string file = __FILE__, const size_t line = __LINE__) { - validateException; - - addMessage(" end with `"); - addValue(someString.to!string); - addMessage("`"); - beginCheck; - - auto index = testData.lastIndexOf(someString); - - static if(is(T == string)) { - auto doesEndWith = index == testData.length - someString.length; - } else { - auto doesEndWith = index == testData.length - 1; - } - - Message[] msg = [ - Message(false, "`"), - Message(true, testData.to!string), - Message(false, expectedValue ? "` does not end with `" : "` does end with `"), - Message(true, someString.to!string), - Message(false, "`.") - ]; - - auto mode = expectedValue ? "to end with " : "to not end with "; - - return result(doesEndWith, msg, new ExpectedActualResult(mode ~ "`" ~ someString.to!string ~ "`", testData), file, line); - } -} - /// When there is a lazy string that throws an it should throw that exception unittest { string someLazyString() {