#!/bin/java bsh.Interpreter

source("TestHarness.bsh");

foo() { a = "foo"; return this; }
assert(foo().a == "foo");

bar( a ) { assert(a==5); }
bar( 5 );

bar2( a, b ) { return a+b; }
assert( bar2( 100, 200 ) == 300 );

gee( int a ) { b = a; return this; }
assert(gee( 79 ).b == 79);

//print("Trying wrong argument type:");
try { eval( "gee( \"foo\" );" ); } catch( bsh.EvalError e ) { 
    flag(); }

//print("wrong number of args:");
try { eval( "gee()" ); } catch( bsh.EvalError e ) { flag(); }
//print("wrong number of args again:");
try { eval( "gee(1,2)" ); } catch( bsh.EvalError e ) { flag(); }

//print("wrong return type:");
int goo2( String s1 ) { return s1; }
try { eval("goo2(\"foo\");"); } catch( bsh.EvalError e ) {
    flag(); }

String goo3( a ) { return a; }
assert( goo3("foo").equals("foo") ); // == ok here

//print("wrong return type again:");
try { eval("goo3(2)"); } catch ( bsh.EvalError e ) { flag(); }

// should be ok
void booga1() { };
void booga2() { return; };
booga1();
booga2();

//print("return from void method type");
void blah() { return "foo"; }
try { eval("blah();"); } catch ( bsh.EvalError e ) {
    flag(); }

assert( flag() == 6 );

complete();

