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
|
#!/bin/java bsh.Interpreter
source("TestHarness.bsh");
// Object imports
Map map = new HashMap();
map.put("foo", "bar");
this.namespace.importObject( map );
assert( get("foo").equals("bar") );
put("goo", "gee");
assert( get("goo").equals("gee") );
toString();
StringBuffer sb = new StringBuffer("foobar99blahgee");
this.namespace.importObject(sb);
assert( substring(0,3).equals("foo") );
assert( indexOf("99") == 6 );
// Static imports
static import java.lang.Math.*;
// equivalent to
//this.namespace.importStatic( java.lang.Math.class );
assert( sqrt(4.0) == 2.0 );
// object again
assert( substring(0,3).equals("foo") );
// fields
assert( PI > 3.0 && PI < 4.0 );
Fields.staticField2 = 42;
static import Fields.*;
assert( staticField2 == 42 );
staticField2 = 43;
assert( staticField2 == 43 );
assert( Fields.staticField2 == 43 );
Fields fields = new Fields();
importObject( fields );
fields.x = 99;
assert( fields.x == 99 );
assert( x == 99 );
x=100;
assert( x == 100 );
assert( fields.x == 100 );
complete();
|