1 module fuzzyd_test;
2 
3 import std.stdio;
4 import std.array;
5 import std.algorithm;
6 import std.algorithm.comparison : equal;
7 
8 import fuzzyd.core;
9 
10 private FuzzyResult[] prepare(string s)
11 {
12     string[] source = [
13         "cd Documents", "curl localhost/foo", "cp bar ../foo",
14         "rm -rf Downloads", "vi ~/Documents"
15     ];
16     FuzzyResult[] response = new FuzzyResult[source.length];
17     fuzzy(source)(s, response);
18     return response;
19 }
20 
21 @("Matches in expected order")
22 unittest
23 {
24     auto result = prepare("docts").map!(x => x.value);
25     const expected = [
26         "cd Documents", "vi ~/Documents", "curl localhost/foo",
27         "rm -rf Downloads", "cp bar ../foo"
28     ];
29     assert(equal(expected, result));
30 }
31 
32 @("Matches indexes")
33 unittest
34 {
35     const result = prepare("docts")[0].matches;
36     const expected = [1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1];
37     assert(equal(expected, result));
38 }
39 
40 @("Result is empty if provided db is empty")
41 unittest
42 {
43     string[] source = [];
44     FuzzyResult[] result = new FuzzyResult[0];
45     fuzzy(source)("f", result);
46     assert(result.empty);
47 }
48 
49 @("Unicode support")
50 unittest
51 {
52     // string[] source = ["férias"];
53     // auto result = new FuzzyResult[source.length];
54     // fuzzy(source)("fé", result);
55     // assert(equal([1, 1, 0, 0, 0, 0], result[0].matches));
56     // fuzzy(["foo", "bar", "baz"])("br", result);
57 
58 string[] source = ["cd Documents"
59                   ,"curl localhost/foo"
60                   ,"rm -rf Downloads"
61                   ,"vi ~/Documents"];
62 
63 auto result = new FuzzyResult[source.length];
64 auto fzy = fuzzy(source);
65 
66 fzy("docts", result);
67 writeln(result);
68 }