From 7f78ea64c93b0c0bbb2f7582089129fefe9b8ac5 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Thu, 29 Dec 2016 13:33:41 +0100 Subject: [PATCH] Added unitests for substitution.substiute --- source/substitution.d | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/source/substitution.d b/source/substitution.d index e10bf65..d743fe9 100644 --- a/source/substitution.d +++ b/source/substitution.d @@ -19,11 +19,30 @@ void loadSubstitutionFile(string fileName) } } -auto substitute(string s) +auto substitute(string s) @safe nothrow { return s in map ? map[s] : s; } +@safe unittest +{ + map[""] = ""; + assert(substitute("") == ""); + + map["a"] = "b"; + assert(substitute("a") == "b"); + + map["Regensburg Danziger Freiheit"] = "Danziger Freiheit"; + assert(substitute("Regensburg Danziger Freiheit") == "Danziger Freiheit"); + + map["Regensburg Danziger Freiheit"] = "Anderer Test"; + assert(substitute("Regensburg Danziger Freiheit") == "Anderer Test"); + + assert(substitute("z") == "z"); + + assert(substitute("Regensburg Hauptbahnhof") == "Regensburg Hauptbahnhof"); +} + private: string[string] map;