1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/bin/java bsh.Interpreter
source("TestHarness.bsh");
java.lang.System.out.println("Basic print: passed");
System.out.println("Imported java.lang: passed");
System.out.println("print date:");
System.out.println( new java.util.Date() );
System.out.println("print var containing date:");
a = new java.util.Date();
System.out.println( a );
print("method access on var");
s = "failed pass failed";
assert( s.substring(7,11).equals("pass") );
System.out.println("static method access");
assert( System.currentTimeMillis() > 900000000000L );
System.out.println("static field access");
out = System.out;
assert( out instanceof PrintStream );
out.println("more field access:");
// note: this could conceivably change , but I doubt it
assert( java.awt.GridBagConstraints.BOTH == 1 );
assert( this == this );
assert( super == super );
assert( ((ActionListener)this) == ((ActionListener)this) );
// unset works
assert( goober123423 == void );
goober123423=5;
assert( goober123423 != void );
unset("goober123423");
assert( goober123423 == void );
// unset scope works
foo=5;
foo() {
foo=6;
unset("foo");
assert(foo==void);
}
assert(foo==5);
// Can re-declare typed vars with the same type
int a=5;
int a=6;
// but not a different type
assert(isEvalError("Object a=\"foo\""));
// untyped can be overridden with a typed
un1 = "foo";
un1 = 5;
String un1 = "foo";
un1="bar";
assert(isEvalError("un1=5"));
// typed declaration and assignments work
assert( isEvalError("String s1 = 5"));
String s2;
assert( isEvalError("s2 = 5"));
// variable names take precendence over class names, as in Java
assert( java.lang.System.out instanceof PrintStream );
java.lang.System.out.println("ok");
java = 5; // hide class namespace with var
assert( isEvalError("java.lang.System.out instanceof PrintStream"));
// caching of method resolution could mess this up
assert( isEvalError("java.lang.System.out.println(\"ok\")") );
// make sure void assignments don't work in method return
void voidmethod1() { }
assert( isEvalError("s1=voidmethod1()") );
assert( isEvalError("String s2=voidmethod1()") );
complete();
|