= #JxnPortable/docs/programmer_examples/demos/PrimitiveParameterCast_char_UnitTest.jxn

#ifndef noFiles
! run as single file
resetAll = true
#else
! run as part of a set of multiple files
noFiles = noFiles + 1
resetAll = false
#endif
!
#ifndef ut
@Date()
ut = @JxnUnitTest();
#endif
#ifndef ut_ok
ut_ok = @JxnUnitTest();
#endif
!
! reset debug to default (abort on unexpected exception => must be recognized and fixed e.g. using $this.test( "..." ) )
oldDebug = $this.setDebug true


#function $test( $1 )
JxnPrimitiveWrapper.setPluggable $1
JxnPrimitiveWrapper.getParameterCast()
!
d8 = 64.
f4 = JxnCast.toFloat 64.
i8 = JxnCast.toLong 64
i4 = 64
i2 = JxnCast.toShort 64
by1 = JxnCast.toByte 64
ch2 = '@'
!
$exp = "invokeMethod: JxnParameterCheck.testChar( double ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar d8" )
$exp = "invokeMethod: JxnParameterCheck.testChar( float ) undefined, ...";
ut_ok.assertException( $exp,  $this.test "JxnParameterCheck.testChar f4" )
#if $1.equals "Safe"
ut.assertEquals( "char:@", JxnParameterCheck.testChar( i8 ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( i4 ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( i2 ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( by1 ) )
ut.assertEquals( "char:1", JxnParameterCheck.testChar( true ) )
ut.assertEquals( "char:0", JxnParameterCheck.testChar( false ) )
#else
$exp = "invokeMethod: JxnParameterCheck.testChar( long ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar i8" )
$exp = "invokeMethod: JxnParameterCheck.testChar( int ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar i4" ) ) )
$exp = "invokeMethod: JxnParameterCheck.testChar( short ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar i2" )
$exp = "invokeMethod: JxnParameterCheck.testChar( byte ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar by1" )
$exp = "invokeMethod: JxnParameterCheck.testChar( boolean ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar true" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testChar false" )
#endif
ut.assertEquals( "char:@", JxnParameterCheck.testChar( JxnCast.toChar( d8 ) ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( JxnCast.toChar( f4 ) ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( JxnCast.toChar( i8 ) ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( JxnCast.toChar( i4 ) ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( JxnCast.toChar( i2 ) ) )
ut.assertEquals( "char:@", JxnParameterCheck.testChar( JxnCast.toChar( by1 ) ) )
ut.assertEquals( "char:1", JxnParameterCheck.testChar( JxnCast.toChar( true ) ) )
ut.assertEquals( "char:0", JxnParameterCheck.testChar( JxnCast.toChar( false ) ) )
!
ut.assertEquals( "double:64.0",   JxnParameterCheck.testDouble( ch2 ) )
ut.assertEquals( "float:64.0",    JxnParameterCheck.testFloat( ch2 ) )
ut.assertEquals( "long:64",       JxnParameterCheck.testLong( ch2 ) )
ut.assertEquals( "int:64",        JxnParameterCheck.testInt( ch2 ) )
#if $1.equals "Safe"
ut.assertEquals( "short:64",      JxnParameterCheck.testShort( ch2 ) )
ut.assertEquals( "byte:64",       JxnParameterCheck.testByte( ch2 ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( ch2 ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( '1' ) )
#else
$exp = "invokeMethod: JxnParameterCheck.testShort( char ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testShort ch2" )
$exp = "invokeMethod: JxnParameterCheck.testByte( char ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testByte ch2" )
$exp = "invokeMethod: JxnParameterCheck.testBoolean( char ) undefined, ...";
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean ch2" )
ut_ok.assertException( $exp, $this.test "JxnParameterCheck.testBoolean '1'" )
#endif
ut.assertEquals( "short:64", JxnParameterCheck.testShort( JxnCast.toShort( ch2 ) ) )
ut.assertEquals( "byte:64",  JxnParameterCheck.testByte( JxnCast.toByte( ch2 ) ) )
ut.assertEquals( "boolean:false", JxnParameterCheck.testBoolean( JxnCast.toBoolean( ch2 ) ) )
ut.assertEquals( "boolean:true",  JxnParameterCheck.testBoolean( JxnCast.toBoolean( '1' ) ) )
!
ia = { 0 : 127 }
@String JxnCast.toChar ia[32:]
ut.assertEquals( "1TYty", squeeze @String JxnCast.toChar sw( JxnCast.toBoolean JxnCast.toChar ia, ia, 32 ) )
!
#return
#endfunction
$test.setDebug 1


$test "Safe"
$test "Java"

JxnPrimitiveWrapper.setPluggable ""


! >>> keep/move this block at/to end of file >>>
$this.setDebug oldDebug
!
ut.summary()
ut_ok.summary()
JxnUnitTestFailureExpected.summaryAll( resetAll )
! <<< keep/move this block at/to end of file <<<