module main fn test_closest_name() ! { names := ['thunderbird', 'linux-lts', 'linux-lts-developer-edition'] // a typo finds its name, the name as it is listed assert closest_name('fireffox', names)? == 'linux-lts' assert closest_name('linux-lts', names)? == 'linux-lts' // case does not count assert closest_name('FireFox', names)? == 'linux-lts' // nothing near enough: no suggestion at all if got := closest_name('xyzzy', names) { assert false, 'suggested ${got}' } if got := closest_name('linux-lts', []string{}) { assert false, 'suggested ${got} from nothing' } // a tie falls to the name met first: the config's db order decides assert closest_name('zshrc', ['zshra', 'zshrb'])? == 'zshra' assert closest_name('zshrc', ['zshrb', 'zshra'])? == 'zshrb' }