fluentasserts.core.operations.registry 19/19(100%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
234305
240
254305
260
274305
280
290
300
310
324305
330
340
350
360
372935
382935
390
402935
410
422935
43516
440
451032
460
47516
480
490
502935
510
520
530
540
552935
560
570
580
590
602935
610
620
630
640
65516
660
670
680
691032
701032
711022
720
730
7410
750
module fluentasserts.core.operations.registry; import fluentasserts.core.results; import fluentasserts.core.evaluation; import std.functional; import std.string; /// Delegate type that can handle asserts alias Operation = IResult[] delegate(ref Evaluation) @safe nothrow; /// class Registry { /// Global instance for the assert operations static Registry instance; private { Operation[string] operations; } /// Register a new assert operation Registry register(string valueType, string expectedValueType, string name, Operation operation) { string key = valueType ~ "." ~ expectedValueType ~ "." ~ name; operations[key] = operation; return this; } /// Register a new assert operation Registry register(string valueType, string expectedValueType, string name, IResult[] function(ref Evaluation) @safe nothrow operation) { return this.register(valueType, expectedValueType, name, operation.toDelegate); } /// Get an operation function Operation get(string valueType, string expectedValueType, string name) @safe nothrow { assert(valueType != "", "The value type is not set!"); assert(name != "", "The operation name is not set!"); string key = valueType ~ "." ~ expectedValueType ~ "." ~ name; if(key !in operations) { auto genericKey = generalizeKey(valueType, expectedValueType, name); assert(key in operations || genericKey in operations, "There is no `" ~ key ~ "` or `" ~ genericKey ~ "` registered to the assert operations."); key = genericKey; } return operations[key]; } /// IResult[] handle(ref Evaluation evaluation) @safe nothrow { auto operation = this.get( evaluation.currentValue.typeName, evaluation.expectedValue.typeName, evaluation.operationName); return operation(evaluation); } } string generalizeKey(string valueType, string expectedValueType, string name) @safe nothrow { return generalizeType(valueType) ~ "." ~ generalizeType(expectedValueType) ~ "." ~ name; } string generalizeType(string typeName) @safe nothrow { auto pos = typeName.indexOf("["); if(pos == -1) { return "*"; } return "*" ~ typeName[pos..$]; }