### ----------------------------------------------------
### -- RakuAST::Utils
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use RakuAST::Utils;
use experimental :rakuast;

plan 7;

sub foo(Int $a, Str $b --> Str:D) { }

my $ast := NameAST("Foo");
is-deeply $ast,
  RakuAST::Name.from-identifier("Foo"),
  'does NameAST work for simple name';

$ast := NameAST("Foo::Bar");
is-deeply $ast,
  RakuAST::Name.from-identifier-parts("Foo", "Bar"),
  'does NameAST work for complex name';

$ast := TypeAST( Array[Int] );
is-deeply $ast,
  RakuAST::Type::Parameterized.new(
    base-type => RakuAST::Type::Simple.new(
      RakuAST::Name.from-identifier("Array")
    ),
    args      => RakuAST::ArgList.new(
      RakuAST::Type::Simple.new(
        RakuAST::Name.from-identifier("Int")
      )
    )
  ),
  'does TypeAST work as expected';
is-deeply $ast.EVAL, Array[Int], 'does the TypeAST EVAL ok';

$ast := ParameterAST( &foo.signature.params[0] );
is-deeply $ast,
  RakuAST::Parameter.new(
    type   => RakuAST::Type::Simple.new(
      RakuAST::Name.from-identifier("Int")
    ),
    target => RakuAST::ParameterTarget::Var.new(
      name => "\$a"
    )
  ),
  'does ParameterAST work as expected';
# Cannot evaluate a RakuAST::Parameter node; expected a compilation unit,
# statement list, statement, or expression
#is-deeply $ast.EVAL, &foo.signature.params[0], 'does the ParameterAST EVAL ok';

$ast := SignatureAST( &foo.signature );
is-deeply $ast,
  RakuAST::Signature.new(
      parameters => (
      RakuAST::Parameter.new(
        type   => RakuAST::Type::Simple.new(
          RakuAST::Name.from-identifier("Int")
        ),
        target => RakuAST::ParameterTarget::Var.new(
          name => "\$a"
        )
      ),
      RakuAST::Parameter.new(
        type   => RakuAST::Type::Simple.new(
          RakuAST::Name.from-identifier("Str")
        ),
        target => RakuAST::ParameterTarget::Var.new(
          name => "\$b"
        )
      ),
    ),
    returns    => RakuAST::Type::Definedness.new(
      base-type => RakuAST::Type::Simple.new(
        RakuAST::Name.from-identifier("Str")
      ),
      definite  => True
    )
  ),
  'does SignatureAST work as expected';
is-deeply $ast.EVAL, &foo.signature, 'does the SignatureAST EVAL ok';

# vim: expandtab shiftwidth=4


