1 module dunitconversion.tests.aliasdictionary;
2 
3 import dunitconversion.aliasdictionary;
4 
5 import std.exception;
6 import std.algorithm;
7 import std.json;
8 import std.file;
9 
10 unittest {
11     auto dictionary = new AliasDictionary;
12     assert(dictionary.isEmpty);
13     dictionary.addAlias("m", "meter");
14     dictionary.addAlias("m", "meters");
15     assert(!dictionary.isEmpty);
16 
17 
18     assert("m" in dictionary);
19     assert("meter" in dictionary);
20     assert("meters" in dictionary);
21     assert("bzz" !in dictionary);
22 
23     assert(dictionary.name("meter") == "m");
24     assert(dictionary.name("meters") == "m");
25     assertThrown!Exception(dictionary.name("caboo!"));
26 
27     auto aliases = dictionary.aliases("m");
28     assert(aliases.length == 2);
29     assert(aliases.canFind("meter"));
30     assert(aliases.canFind("meters"));
31 
32     dictionary.clear();
33     assert(dictionary.isEmpty);
34     assert("m" !in dictionary);
35     assert("meter" !in dictionary);
36     assert("meters" !in dictionary);
37     assert("bzz" !in dictionary);
38 }
39 
40 unittest {
41     auto dictionary = new AliasDictionary;
42     dictionary.loadFromJson(parseJSON(readText("./test/aliases.json")));
43     assert(!dictionary.isEmpty);
44     assert("m" in dictionary);
45     assert("meter" in dictionary);
46     assert("meters" in dictionary);
47     assert("bzz" !in dictionary);
48 
49     auto aliases = dictionary.aliases("m");
50     assert(aliases.length == 2);
51     assert(aliases.canFind("meter"));
52     assert(aliases.canFind("meters"));
53 
54     aliases = dictionary.aliases("m/s");
55     assert(aliases.length == 1);
56     assert(aliases.canFind("mps"));
57     assert(!aliases.canFind("meters"));
58 
59 }