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
|
#!/bin/java bsh.Interpreter
source("TestHarness.bsh");
/**
I'm just taking a shotgun approach here... we need better tests.
*/
a=5;
a*=2;
assert(a==10);
assert( (255 ^ 128) == 127 );
a=0xff;
a^=128;
assert(a==127);
assert( 13%10 == 3 );
// booleans comparison
assert ( true == true );
assert ( false == false );
assert ( true != false );
assert ( !(true == false) );
// instanceof and null
assert( !(null instanceof String) );
assert( isEvalError("true instanceof 5") );
assert( isEvalError("true instanceof true") );
assert( isEvalError("new Object() instanceof 5") );
assert( isEvalError("new Object() instanceof true") );
assert( isEvalError("5 instanceof true") );
assert( isEvalError("null instanceof null") );
a="foo";
assert( isEvalError("a instanceof null") );
assert( a instanceof String );
// void
assert( void == void );
assert( void != null );
assert( undefinedVariable == void );
def="foo";
assert( def != void );
// hmm... direct values compared?
assert( "foo" != void );
// instanceof and void
assert( isEvalError("void instanceof 5") );
assert( isEvalError("new Object() instanceof void") );
assert( isEvalError("null instanceof void") );
/*
Uncomment these if we start enforcing operations on primitive/non-prim
*/
/*
// can't compare void with primitive
assert( isEvalError("5 != void") );
assert( isEvalError("void != 5") );
assert( isEvalError("true != void") );
assert( isEvalError("void != true") );
assert( isEvalError("void != false") );
// can't compare boolean to anything but boolean
assert( isEvalError("true != null") );
assert( isEvalError("null != false") );
assert( isEvalError("null != true") );
assert( isEvalError("true == null") );
assert( isEvalError("null == true") );
assert( isEvalError("true == new Object()") );
assert( isEvalError("true != new Object()") );
assert( isEvalError("new Object() != false") );
assert( isEvalError("true == 5") );
assert( isEvalError("true != 5") );
assert( isEvalError("5 != false") );
*/
complete();
|