module main fn test_terms_match_edges() { // every term must be somewhere, in the name or in the description assert terms_match('zsh', 'a shell', ['zsh']) assert terms_match('zsh', 'a shell', ['shell']) assert terms_match('zsh', 'a shell', ['zsh', 'shell']) assert !terms_match('zsh', 'a shell', ['zsh', 'editor']) assert !terms_match('zsh', 'a shell', ['bash']) // case is ignored on both sides assert terms_match('Zsh', 'A Shell', ['zSH', 'sHELL']) // a term is a substring, not a word, and may span nothing but itself assert terms_match('zsh-completions', '', ['sh-comp']) assert !terms_match('zsh', 'a shell', ['zsh shell']) // no terms match everything, as a bare pacman -Ss lists everything; an // empty term is in every text assert terms_match('zsh', 'a shell', []) assert terms_match('', '', []) assert terms_match('zsh', '', ['']) // nothing to look in matches no real term assert !terms_match('', '', ['x']) // multibyte text is matched as text assert terms_match('grüße', 'ein Paket', ['üß']) } fn test_pkgbuild_matches_as_the_classic_match() { pkg := PackagePkgbuild{ name: 'yay-bin' description: 'Yet another yogurt' } assert pkgbuild_matches(pkg, ['yay']) assert pkgbuild_matches(pkg, ['YOGURT', 'bin']) assert !pkgbuild_matches(pkg, ['yay', 'paru']) assert pkgbuild_matches(pkg, []) // a record with no description still matches by its name assert pkgbuild_matches(PackagePkgbuild{ name: 'paru' }, ['par']) assert !pkgbuild_matches(PackagePkgbuild{ name: 'paru' }, ['helper']) }