fluentasserts.core.operations.endWith 10/23(43%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
194
200
214
224
234
240
254
260
270
284
290
300
318
320
334
340
350
360
370
380
390
400
410
420
430
440
454
460
470
480
490
500
510
520
530
540
550
560
574
580
module fluentasserts.core.operations.endWith; 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 endWithDescription = "Tests that the tested string ends with the expected value."; /// IResult[] endWith(ref Evaluation evaluation) @safe nothrow { evaluation.message.addText("."); IResult[] results = []; auto current = evaluation.currentValue.strValue.cleanString; auto expected = evaluation.expectedValue.strValue.cleanString; long index = -1; try { index = current.lastIndexOf(expected); } catch(Exception) { } auto doesEndWith = index >= 0 && index == current.length - expected.length; if(evaluation.isNegated) { if(doesEndWith) { evaluation.message.addText(" "); evaluation.message.addValue(evaluation.currentValue.strValue); evaluation.message.addText(" ends with "); evaluation.message.addValue(evaluation.expectedValue.strValue); evaluation.message.addText("."); try results ~= new ExpectedActualResult("to not end with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); catch(Exception e) {} } } else { if(!doesEndWith) { evaluation.message.addText(" "); evaluation.message.addValue(evaluation.currentValue.strValue); evaluation.message.addText(" does not end with "); evaluation.message.addValue(evaluation.expectedValue.strValue); evaluation.message.addText("."); try results ~= new ExpectedActualResult("to end with " ~ evaluation.expectedValue.strValue, evaluation.currentValue.strValue); catch(Exception e) {} } } return results; }