#! /usr/bin/perl # $OpenBSD: check-name,v 1.8 2009/11/03 11:22:53 espie Exp $ # Written by Marc Espie # Public domain use Test::Simple tests => 13; use OpenBSD::Search; use OpenBSD::PackageName; sub check_list { my $expected = shift; @_ = sort(@_); if (@$expected != @_) { return 0; } for my $i (0 .. @_ -1) { if ($expected->[$i] ne $_[$i]) { return 0; } } return 1; } sub check_pkgspec { my ($s, @list) = @_; my $o = OpenBSD::Search::PkgSpec->new($s); return $o->filter(@list); } @list = qw(py-MxDateTime-2.0.1-py2.1); ok(check_list(\@list, check_pkgspec('py-MxDateTime->=2.0-py2.1', @list)), 'flavor with number'); @list = qw(foo-1.0 foo-1.0p0 foo-1.0p25); ok(check_list([qw(foo-1.0)], check_pkgspec('foo-<1.0p0', @list)), 'before 1.0p0 came 1.0'); ok(check_list([qw(foo-1.0 foo-1.0p0)], check_pkgspec('foo-<=1.0p0', @list)), '1.0 and 1.0p0 both match <=1.0p0'); ok(check_list([qw(foo-1.0 foo-1.0p0 foo-1.0p25)], check_pkgspec('foo-1.0', @list)), 'any 1.0p* matches 1.0'); @list = qw(foo-1.0rc2); ok(check_list(\@list, check_pkgspec('foo-<1.0', @list)), 'before 1.0 came 1.0rc2'); @list = qw(foo-1.0); ok(check_list(\@list, check_pkgspec('foo-<1.0pl1', @list)), 'before 1.0pl1 came 1.0'); my @pkglist=qw(foo-1.0 bar-2.0 foo-2.5 foobar-2.3-pouet hugs-noversion baz-0.0 baz-1.1 baz-25.3 pouet-1.0 pouet-zoinx-1.0 pouet-0.0-foo); my $hash = OpenBSD::PackageName::compile_stemlist(@pkglist); ok(check_list([qw(bar-2.0)], $hash->find('bar')), 'simple stem lookup'); ok(check_list([qw(foo-1.0 foo-2.5)], $hash->find('foo')), 'simple stem lookup with several results'); ok(check_list([qw(baz-0.0 baz-1.1 baz-25.3)], $hash->find('baz')), 'stem lookup, no duplicates'); ok(check_list([qw(foobar-2.3-pouet)], $hash->find('foobar')), 'stem lookup with flavor'); ok(check_list([qw(pouet-0.0-foo pouet-1.0)], $hash->find('pouet')), 'complicated stem matching'); ok(check_list([], $hash->find('hugs')), 'bogus stem matching with no version'); ok(check_list([qw(hugs-noversion)], $hash->find('hugs-noversion')), 'stem matching with no version');