### ----------------------------------------------------
### -- P5getservbyname
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/getservbyname.rakutest
### ----------------------------------------------------
use Test;
use P5getservbyname;

plan 12;

my @smtp = 'smtp', $*KERNEL.name eq 'darwin' ?? '' !! 'mail',25,'tcp';

is getservbyname(Scalar, "smtp","tcp"), 25,
  'did we find smtp by name in scalar context';

my @byname = getservbyname("smtp","tcp");
is-deeply @byname, @smtp, 'did we find smtp by name';

is getservbyport(Scalar, 25,"tcp"), "smtp",
  'did we find ourselves by port in scalar context';

my @byport = getservbyport(25,"tcp");
is-deeply @byport, @smtp, 'did we find smtp by port';

my $servname = getservent(Scalar);
ok ?$servname, 'did we get a serv name';

is setservent(False), 1, 'does setservent(False) return the undocumented 1';
is setservent(True),  1, 'does setservent(True) return the undocumented 1';

is endservent(), 1, 'does endservent return the undocumented 1';

is getservbyname(Scalar, "thisnameshouldnotexist", "tcp"), Nil,
  'did lookup by non-existing name fail in scalar context';
is-deeply getservbyname("thisnameshouldnotexist", "tcp"), (),
  'did lookup by non-existing name fail';

is getservbyport(Scalar, 99999, "tcp"), Nil,
  'did lookup by non-existing port fail in scalar context';
is-deeply getservbyport(99999, "foo"), (),
  'did lookup by non-existing port fail';

# vim: expandtab shiftwidth=4


