1 module fluentasserts.core.operations.endWith; 2 3 import std..string; 4 5 import fluentasserts.core.results; 6 import fluentasserts.core.evaluation; 7 import fluentasserts.core.serializers; 8 9 import fluentasserts.core.lifecycle; 10 11 version(unittest) { 12 import fluentasserts.core.expect; 13 } 14 15 /// 16 IResult[] endWith(ref Evaluation evaluation) @safe nothrow { 17 evaluation.message.addText("."); 18 19 IResult[] results = []; 20 auto current = evaluation.currentValue.strValue.cleanString; 21 auto expected = evaluation.expectedValue.strValue.cleanString; 22 23 long index = -1; 24 25 try { 26 index = current.lastIndexOf(expected); 27 } catch(Exception) { } 28 29 auto doesEndWith = index >= 0 && index == current.length - expected.length; 30 31 if(evaluation.isNegated) { 32 if(doesEndWith) { 33 evaluation.message.addText(" "); 34 evaluation.message.addValue(evaluation.currentValue.strValue); 35 evaluation.message.addText(" ends with "); 36 evaluation.message.addValue(evaluation.expectedValue.strValue); 37 evaluation.message.addText("."); 38 39 try results ~= new ExpectedActualResult("to not end with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); 40 catch(Exception e) {} 41 } 42 } else { 43 if(!doesEndWith) { 44 evaluation.message.addText(" "); 45 evaluation.message.addValue(evaluation.currentValue.strValue); 46 evaluation.message.addText(" does not end with "); 47 evaluation.message.addValue(evaluation.expectedValue.strValue); 48 evaluation.message.addText("."); 49 50 try results ~= new ExpectedActualResult("to end with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); 51 catch(Exception e) {} 52 } 53 } 54 55 return results; 56 }