#!/bin/java bsh.Interpreter

source("TestHarness.bsh");

if ( Interpreter.LOCALSCOPING )
{
foo() {
	a =1;
	bar() {
		a = 2;
		gee() {
			a = 3;
			super.b = 31;
			super.c = 9;
			global.b = 32;
			
			print("gee");

			val() {
				return 42;
			}

			return this;
		}
		print("bar");
		return this;
	}
	print("foo");
	return this;
}

foo = foo();
bar = foo.bar();
gee = bar.gee();
val = gee.val();

assert(foo.a == 1);
assert(bar.a == 2);
assert(gee.a == 3);
assert(val == 42);

assert( foo().bar().gee().val() == 42 );

assert( b == 32 );
assert( bar.b == 31 ); 
assert( foo.b == 32 ); // global
assert( foo.c == void );
}
else
{
foo() {
	this.a =1;
	bar() {
		this.a = 2;
		gee() {
			this.a = 3;

			// if we really want to set a var in our parent's namespace
			// from a child namespace
			barns=super;
			barns.b = 31;
			barns.c = 9;

			global.b = 32;
			
			print("gee");

			val() {
				return 42;
			}

			return this;
		}
		print("bar");
		return this;
	}
	print("foo");
	return this;
}

foo = foo();
bar = foo.bar();
gee = bar.gee();
val = gee.val();

assert(foo.a == 1);
assert(bar.a == 2);
assert(gee.a == 3);
assert(val == 42);

assert( foo().bar().gee().val() == 42 );

assert( b == 32 );
assert( bar.b == 31 ); 
assert( foo.b == 32 ); // global
assert( foo.c == void );
}

complete();
