#!/bin/java bsh.Interpreter

source("TestHarness.bsh");


// basic
byte b = (byte)2;
byte b = 0xff;
byte b = 2;
i=b;
assert( i == 2 );
char c = 'A';
char c = 5;
short s = (short)2;
short s = 2;
int i = 2;
float f = 3.0f;

// In Java float's don't get auto cast in declarations
//assert( isEvalError("float f = 3.0"));
float f = 3.0;

double d = 3.0;

// promote
double d1 = 3.0f;
assert( d1.getType() == Double.TYPE );
long l1 = 5;
assert( l1.getType() == Long.TYPE );
l1 = (byte)5;
assert( l1.getType() == Long.TYPE );

// basic assignment promotion
int i2 = (byte)5;
long l1 = 5;
assert(l1==5);
long l2 = b;
assert(l2==2);

long l3=(byte)2;

/*
	Unification of wrapper types with primitives
*/
Integer iw = 2;
Double dw = 2.0;
assert( iw == i );
assert( dw == b );

// preserve identity semantics
// .equal wrappers don't test ==
assert( !(iw == dw) );

assert( iw instanceof Integer );
assert( iw != null );
Integer in = null;
assert( in == null );

// Basic promotion of primitives
byte b1 = (byte)5;
short s1 = (short)5;
int i1 = 5;
long l1 = 5;
float f1 = 5.0f;
double d1 = 5.0;
char c1 = (char)42;

s1=b1;

i1=b1;
i1=s1;
i1=c1;

l1=b1;
l1=s1;
l1=c1;
l1=i1;
//l1=d1; // double to long?

f1=b1;
f1=s1;
f1=c1;
f1=i1;

d1=b1;
d1=s1;
d1=i1;
d1=l1;

// Numeric style promotion of primitive wrappers

// characters wrappers ok
Byte bw1 = (byte)5;
Short sw1 = (short)5;
Integer iw1 = 5;
Long lw1 = 5;
Float fw1 = 5.0f;
Double dw1 = 5.0;
Character cw1 = (char)42;

sw1=b1;

iw1=b1;
iw1=s1;
iw1=c1;

lw1=b1;
lw1=s1;
lw1=c1;
lw1=i1;
// lw1=d1; // double to Long?

fw1=b1;
fw1=s1;
fw1=c1;
fw1=i1;

dw1=b1;
dw1=s1;
dw1=i1;
dw1=l1;

double d123=3.0;
float f123=3.0;
d123=f123;
assert( d123.getType() == Double.TYPE );
assert( f123.getType() == Float.TYPE );
assert(isEvalError("f123=d123"));
assert(isEvalError("d123=true"));
assert(isEvalError("d123=null"));

complete();
