1 module fluentasserts.core.operations.greaterOrEqualTo; 2 3 import fluentasserts.core.results; 4 import fluentasserts.core.evaluation; 5 6 import fluentasserts.core.lifecycle; 7 8 import std.conv; 9 import std.datetime; 10 11 version(unittest) { 12 import fluentasserts.core.expect; 13 } 14 15 /// 16 IResult[] greaterOrEqualTo(T)(ref Evaluation evaluation) @safe nothrow { 17 evaluation.message.addText("."); 18 19 T expectedValue; 20 T currentValue; 21 22 try { 23 expectedValue = evaluation.expectedValue.strValue.to!T; 24 currentValue = evaluation.currentValue.strValue.to!T; 25 } catch(Exception e) { 26 return [ new MessageResult("Can't convert the values to " ~ T.stringof) ]; 27 } 28 29 auto result = currentValue >= expectedValue; 30 31 return greaterOrEqualToResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); 32 } 33 34 IResult[] greaterOrEqualToDuration(ref Evaluation evaluation) @safe nothrow { 35 evaluation.message.addText("."); 36 37 Duration expectedValue; 38 Duration currentValue; 39 string niceExpectedValue; 40 string niceCurrentValue; 41 42 try { 43 expectedValue = dur!"nsecs"(evaluation.expectedValue.strValue.to!size_t); 44 currentValue = dur!"nsecs"(evaluation.currentValue.strValue.to!size_t); 45 46 niceExpectedValue = expectedValue.to!string; 47 niceCurrentValue = currentValue.to!string; 48 } catch(Exception e) { 49 return [ new MessageResult("Can't convert the values to Duration") ]; 50 } 51 52 auto result = currentValue >= expectedValue; 53 54 return greaterOrEqualToResults(result, niceExpectedValue, niceCurrentValue, evaluation); 55 } 56 57 IResult[] greaterOrEqualToSysTime(ref Evaluation evaluation) @safe nothrow { 58 evaluation.message.addText("."); 59 60 SysTime expectedValue; 61 SysTime currentValue; 62 string niceExpectedValue; 63 string niceCurrentValue; 64 65 try { 66 expectedValue = SysTime.fromISOExtString(evaluation.expectedValue.strValue); 67 currentValue = SysTime.fromISOExtString(evaluation.currentValue.strValue); 68 } catch(Exception e) { 69 return [ new MessageResult("Can't convert the values to SysTime") ]; 70 } 71 72 auto result = currentValue >= expectedValue; 73 74 return greaterOrEqualToResults(result, evaluation.expectedValue.strValue, evaluation.currentValue.strValue, evaluation); 75 } 76 77 private IResult[] greaterOrEqualToResults(bool result, string niceExpectedValue, string niceCurrentValue, ref Evaluation evaluation) @safe nothrow { 78 if(evaluation.isNegated) { 79 result = !result; 80 } 81 82 if(result) { 83 return []; 84 } 85 86 evaluation.message.addText(" "); 87 evaluation.message.addValue(evaluation.currentValue.niceValue); 88 89 IResult[] results = []; 90 91 if(evaluation.isNegated) { 92 evaluation.message.addText(" is greater or equal than "); 93 results ~= new ExpectedActualResult("less than " ~ niceExpectedValue, niceCurrentValue); 94 } else { 95 evaluation.message.addText(" is less than "); 96 results ~= new ExpectedActualResult("greater or equal than " ~ niceExpectedValue, niceCurrentValue); 97 } 98 99 evaluation.message.addValue(niceExpectedValue); 100 evaluation.message.addText("."); 101 102 return results; 103 }