vpac / src / suggest_test.v
20 lines · 19 sloc · 777 bytes · 3609dfbd82867dc1034a443f8f9ced529ddbbedd
Raw
1module main
2
3fn test_closest_name() ! {
4 names := ['thunderbird', 'linux-lts', 'linux-lts-developer-edition']
5 // a typo finds its name, the name as it is listed
6 assert closest_name('fireffox', names)? == 'linux-lts'
7 assert closest_name('linux-lts', names)? == 'linux-lts'
8 // case does not count
9 assert closest_name('FireFox', names)? == 'linux-lts'
10 // nothing near enough: no suggestion at all
11 if got := closest_name('xyzzy', names) {
12 assert false, 'suggested ${got}'
13 }
14 if got := closest_name('linux-lts', []string{}) {
15 assert false, 'suggested ${got} from nothing'
16 }
17 // a tie falls to the name met first: the config's db order decides
18 assert closest_name('zshrc', ['zshra', 'zshrb'])? == 'zshra'
19 assert closest_name('zshrc', ['zshrb', 'zshra'])? == 'zshrb'
20}
21