### ----------------------------------------------------
### -- String::Color
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use String::Color;

plan 12;

my str @colors = <green blue orange yellow purple>;

my $sc := String::Color.new:
  generator => -> str $string {
      $string eq "liz"
        ?? "red"
        !! @colors.shift;
  }

isa-ok $sc, String::Color;
my str @to-add = <liz_ liz timo jnthn nine nwc10 vrurg>;
is-deeply $sc.add(@to-add), @to-add, 'were they all added';

ok $sc.known("red"), "is 'red' a known color";
nok $sc.known("cyan"), "is 'cyan' a NOT known color";
is $sc.elems, 8, 'is number of elements ok';

is-deeply
  $sc.Map,
  Map.new((
    ""    => "",
    jnthn => 'blue',
    liz   => 'red',
    liz_  => 'red',
    nine  => 'orange',
    nwc10 => 'yellow',
    timo  => 'green',
    vrurg => 'purple'
  )),
  'did the mapping go ok';

$sc := String::Color.new:
  generator => -> str $string { "foo" },
  colors => {
    jnthn => 'blue',
    liz   => 'red',
    liz_  => 'red',
    nine  => 'orange',
    nwc10 => 'yellow',
    timo  => 'green',
    vrurg => 'purple'
  }

is-deeply
  $sc.Map,
  Map.new((
    ""    => "",
    jnthn => 'blue',
    liz   => 'red',
    liz_  => 'red',
    nine  => 'orange',
    nwc10 => 'yellow',
    timo  => 'green',
    vrurg => 'purple'
  )),
  'did the mapping go ok from saved';

my str @aliases = <liz liz_>;;
for @aliases {
    is-deeply $sc.aliases($_), @aliases, "right aliases for $_";
}

is-deeply $sc.add("masak"), (my str @ = <masak>),
  'could we add masak just by themselves';
is-deeply $sc.add(<moritz masak nine>), (my str @ = <moritz>),
  'did nine and masak not get added again';

is-deeply
  $sc.Map,
  Map.new((
    ""     => "",
    jnthn  => 'blue',
    liz    => 'red',
    liz_   => 'red',
    masak  => 'foo',
    moritz => 'foo',
    nine   => 'orange',
    nwc10  => 'yellow',
    timo   => 'green',
    vrurg  => 'purple'
  )),
  'did the mapping go ok again';

# vim: expandtab shiftwidth=4


