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     return fuzzy(source)(s);
17 }
18 
19 @("Matches in expected order")
20 unittest
21 {
22     auto result = prepare("docts").map!(x => x.value);
23     const expected = [
24         "cd Documents", "vi ~/Documents", "rm -rf Downloads",
25         "curl localhost/foo", "cp bar ../foo"
26     ];
27     assert(equal(expected, result));
28 }
29 
30 @("Matches indexes")
31 unittest
32 {
33     const result = prepare("docts")[0].matches.array();
34     const expected = [0, 1, 3, 4, 5, 10, 11];
35     assert(equal(expected, result));
36 }
37 
38 @("Result is empty if no provided db was empty")
39 unittest
40 {
41     string[] source = [];
42     const result = fuzzy(source)("f");
43     assert(result.empty);
44 }
45 
46 @("Score is normalized")
47 unittest
48 {
49     // string[] source = [ "fzf", "foo", "bar", "faz"];
50     // const FuzzyResult[] invalid = fuzzy(source)("f").filter!(x => x.score > 1 || x.score < 0).array;
51     // assert(invalid.empty);
52 
53 string[] source = ["cd Documents"
54                   ,"curl localhost/foo"
55                   ,"rm -rf Downloads"
56                   ,"vi ~/Documents"];
57 
58 auto fzy = fuzzy(source);
59 
60 writeln(fzy("docts"));
61 }