| 1 | module main |
| 2 | |
| 3 | fn 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('linx-lts', names)? == 'linux-lts' |
| 7 | assert closest_name('linux-lts', names)? == 'linux-lts' |
| 8 | // case does not count |
| 9 | assert closest_name('Linux-LTS', 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 | |