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
234239
240
254239
260
274239
280
290
300
310
324239
330
340
350
360
372397
382397
390
402397
410
422397
4312
440
4524
460
4712
480
490
502397
510
520
530
540
552397
560
570
580
590
602397
610
620
630
640
6512
660
670
680
6924
7024
7114
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..$]; }