102030405060708090100110120130140150160170180195200215220235245250265270280290300310320330340350360370385390400410420430440450460470480490505510 module fluentasserts.core.operations.startWith; import std.string; import fluentasserts.core.results; import fluentasserts.core.evaluation; import fluentasserts.core.serializers; import fluentasserts.core.lifecycle; version(unittest) { import fluentasserts.core.expect; } static immutable startWithDescription = "Tests that the tested string starts with the expected value."; /// IResult[] startWith(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText("."); IResult[] results = []; auto index = evaluation.currentValue.strValue.cleanString.indexOf(evaluation.expectedValue.strValue.cleanString); auto doesStartWith = index == 0; if(evaluation.isNegated) { if(doesStartWith) { evaluation.message.addText(" "); evaluation.message.addValue(evaluation.currentValue.strValue); evaluation.message.addText(" starts with "); evaluation.message.addValue(evaluation.expectedValue.strValue); evaluation.message.addText("."); try results ~= new ExpectedActualResult("to not start with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); catch(Exception e) {} } } else { if(!doesStartWith) { evaluation.message.addText(" "); evaluation.message.addValue(evaluation.currentValue.strValue); evaluation.message.addText(" does not start with "); evaluation.message.addValue(evaluation.expectedValue.strValue); evaluation.message.addText("."); try results ~= new ExpectedActualResult("to start with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); catch(Exception e) {} } } return results; }
module fluentasserts.core.operations.startWith; import std.string; import fluentasserts.core.results; import fluentasserts.core.evaluation; import fluentasserts.core.serializers; import fluentasserts.core.lifecycle; version(unittest) { import fluentasserts.core.expect; } static immutable startWithDescription = "Tests that the tested string starts with the expected value."; /// IResult[] startWith(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText("."); IResult[] results = []; auto index = evaluation.currentValue.strValue.cleanString.indexOf(evaluation.expectedValue.strValue.cleanString); auto doesStartWith = index == 0; if(evaluation.isNegated) { if(doesStartWith) { evaluation.message.addText(" "); evaluation.message.addValue(evaluation.currentValue.strValue); evaluation.message.addText(" starts with "); evaluation.message.addValue(evaluation.expectedValue.strValue); evaluation.message.addText("."); try results ~= new ExpectedActualResult("to not start with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); catch(Exception e) {} } } else { if(!doesStartWith) { evaluation.message.addText(" "); evaluation.message.addValue(evaluation.currentValue.strValue); evaluation.message.addText(" does not start with "); evaluation.message.addValue(evaluation.expectedValue.strValue); evaluation.message.addText("."); try results ~= new ExpectedActualResult("to start with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); catch(Exception e) {} } } return results; }