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
|
#!/bin/java bsh.Interpreter
source("TestHarness.bsh");
int p=1;
{
int p=2;
{
int p=3;
pz=99;
assert( p == 3 );
}
assert( p == 2 );
}
assert( p == 1 );
assert( pz == 99 );
/*
Typed variable declarations inside a block should not leak out.
*/
boolean var = false;
for(int i=0; i<1; i++) {
int var=1;
}
for(int i=0; i<1; i++) {
String var="hello";
}
assert( var == false );
u=2;
int x=2;
int z1=2;
{
assert(u==2);
assert(super.u==2);
u=3;
assert(u==3);
x=3;
assert(x==3);
int z=3;
// bsh allows the redeclaration...
// but the scope should be local
int z1=5;
}
assert( u==3 );
assert( x==3 );
assert( z==void );
assert( z1==2 );
i=0;
while( i++ < 5 ) {
int qz=5;
assert( qz == 5);
}
assert( qz == void);
int i=0;
while( i < 5 ) {
i++;
int qz=5;
assert( qz == 5);
}
assert( qz == void);
if ( true ) {
assert( this == global );
if ( true ) {
assert( this == global );
}
}
complete();
|