### ----------------------------------------------------
### -- Net::NetRC
### -- Licenses: Artistic-2.0
### -- Authors: Humberto Massa
### -- File: t/02-functionality.rakutest
### ----------------------------------------------------
use Test;

my $netrc-fake = q:to/ENDNETRC/;

# comment, but there is white lines above
# a while line below here

   # another comment here, indented
   #
   # now a global macdef
   macdef global
   test
   test
   # - more content
   # test
   #

   machine simmetric

default login anonymous    # ooh, a comment!
password anonymous@mailinator.com
macdef login
teste
vai

# faz parte do macdef

macdef logout
#--end macdef (?)
#
something or
#-- macdef ignored (or is it?)
#
something
# or other
macdef logout
logout again

machine setup.org
account vai # login massa

machine example.org
account bicho
# account nobicho
login massa
password not-my-real-pass
macdef autophage
eat my shorts



ENDNETRC

use Net::NetRC;

plan 9;

my $netrc;
lives-ok {
   $netrc = netrc $netrc-fake
}
ok $netrc.defined;

is-deeply $netrc<google.com>, {
   login => 'anonymous',
   password => 'anonymous@mailinator.com',
   'macdef:logout' => [('something or', 'something'), ('logout again',)],
   'macdef:login' => ('teste', 'vai'),
};
is $netrc<example.org><account>, 'bicho';
is $netrc<example.org><password>, 'not-my-real-pass';
is-deeply $netrc<simmetric>, {};

lives-ok {
   my %hash = netrc $netrc-fake;
   nok %hash<google.com>
}

dies-ok {
   my $x = netrc '/unexistent/file'.IO
}

done-testing;




