| 1 | module main |
| 2 | |
| 3 | fn test_terms_match_edges() { |
| 4 | // every term must be somewhere, in the name or in the description |
| 5 | assert terms_match('zsh', 'a shell', ['zsh']) |
| 6 | assert terms_match('zsh', 'a shell', ['shell']) |
| 7 | assert terms_match('zsh', 'a shell', ['zsh', 'shell']) |
| 8 | assert !terms_match('zsh', 'a shell', ['zsh', 'editor']) |
| 9 | assert !terms_match('zsh', 'a shell', ['bash']) |
| 10 | // case is ignored on both sides |
| 11 | assert terms_match('Zsh', 'A Shell', ['zSH', 'sHELL']) |
| 12 | // a term is a substring, not a word, and may span nothing but itself |
| 13 | assert terms_match('zsh-completions', '', ['sh-comp']) |
| 14 | assert !terms_match('zsh', 'a shell', ['zsh shell']) |
| 15 | // no terms match everything, as a bare pacman -Ss lists everything; an |
| 16 | // empty term is in every text |
| 17 | assert terms_match('zsh', 'a shell', []) |
| 18 | assert terms_match('', '', []) |
| 19 | assert terms_match('zsh', '', ['']) |
| 20 | // nothing to look in matches no real term |
| 21 | assert !terms_match('', '', ['x']) |
| 22 | // multibyte text is matched as text |
| 23 | assert terms_match('grüße', 'ein Paket', ['üß']) |
| 24 | } |
| 25 | |
| 26 | fn test_pkgbuild_matches_as_the_classic_match() { |
| 27 | pkg := PackagePkgbuild{ |
| 28 | name: 'yay-bin' |
| 29 | description: 'Yet another yogurt' |
| 30 | } |
| 31 | assert pkgbuild_matches(pkg, ['yay']) |
| 32 | assert pkgbuild_matches(pkg, ['YOGURT', 'bin']) |
| 33 | assert !pkgbuild_matches(pkg, ['yay', 'paru']) |
| 34 | assert pkgbuild_matches(pkg, []) |
| 35 | // a record with no description still matches by its name |
| 36 | assert pkgbuild_matches(PackagePkgbuild{ name: 'paru' }, ['par']) |
| 37 | assert !pkgbuild_matches(PackagePkgbuild{ name: 'paru' }, ['helper']) |
| 38 | } |
| 39 | |