#!/usr/bin/ruby

#
## Returns String
#
func concat(a,b) -> "" {
    a+b
}

assert_eq(concat("a", "b"), "ab");

try {
        concat([1],[2]);
        die "error!";
}
catch {
    ## ok
}


#
## Returns number
#
func add(a,b) -> Num {
    a+b;
}

assert_eq(add(1,2), 3);

try {
    add("1", "2");
    die "error!";
}
catch {
    ## ok
}


#
## Returns a user-defined type
#
class Point(a,b) { };

func point(a, b) -> Point {
    Point(a, b);
}

assert(point(1,2).is_a(Point));

func fake_point(a, b) -> Point {
    [a, b];
}

try {
    fake_point(1,2);
    die "error!";
}
catch {
    ## ok
}

#
## Return more types
#

func foo() -> (String, Number) {
    ("abc", 42)
}

var(str, num) = foo();
assert_eq(str, "abc");
assert_eq(num, 42);

#
## Generic types
#

func bar(a, b) -> Object {
    a + b
}

assert_eq(bar(1, 2), 3);
assert_eq(bar("a", "b"), "ab");

#
## Test passed!
#
say "** Test passed!";
