RegressionTests__BlockTest.st
author Claus Gittinger <cg@exept.de>
Fri, 31 Aug 2007 17:47:11 +0200
changeset 334 a9657208d19b
parent 181 a56517005229
child 606 42c26f8c0ce6
permissions -rw-r--r--
oops - bytecode version generated wrong jitted code for Expecco::Browser reinitialize. must check this !!!.

"{ Package: 'exept:regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#BlockTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression'
!


!BlockTest methodsFor:'defects'!

g
    ^ True "/ the class here

    "Created: / 31-08-2007 / 17:40:37 / cg"
!

h
    ^ True "/ the class here

    "Created: / 31-08-2007 / 17:40:39 / cg"
!

testBlockWithEQEQ_1
    |b v|

    b := [ self g == self h ].
    v := b value.
    self assert:(v == true).


    "
     self new testBlockWithEQEQ_1
    "

    "Created: / 31-08-2007 / 17:41:59 / cg"
!

testBlockWithEQEQ_2
    |b v|

    b := [ 
%{
#ifdef FOO
%}.
            self thisIsNeverCalled.
%{
#endif
%}.
            self g == self h 
         ].
    v := b value.
    self assert:(v == true).


    "
     self new testBlockWithEQEQ_2
    "

    "Created: / 31-08-2007 / 17:42:02 / cg"
!

testBlockWithEQEQ_3
    |b p v|

    p := self.

    [

        b := [ 
%{
#ifdef FOO
%}.
            self thisIsNeverCalled.
%{
#endif
%}.
            p g == p h 
         ].
    ] value.

    v := b value.
    self assert:(v == true).


    "
     self new testBlockWithEQEQ_3
    "

    "Created: / 31-08-2007 / 17:44:07 / cg"
!

testBlockWithEQEQ_4
    |b p v Tmp|

    p := self.

    [

        b := [   |foo|
%{
#ifdef FOO
%}.
            foo := Timestamp now.
            Tmp isNil ifTrue:[
                Tmp := 'flags' copy.
            ] ifFalse:[
                ObjectMemory stopBackgroundCollector.
            ].
            self thisIsNeverCalled.
%{
#endif
%}.
            p g == p h 
         ].
    ] perform:((Base64Coder decode:'dmFsdWU=') asString asSymbol).

    v := b value.
    self assert:(v == true).


    "
     self new testBlockWithEQEQ_4
    "

    "Created: / 31-08-2007 / 17:44:38 / cg"
! !

!BlockTest methodsFor:'varArgBlocks'!

getBlock1
     |b|

     b := [:arg | Transcript 
                        show:'invoked with arg:'; 
                        showCR:arg
          ].
     ^ b
!

getVarArgBlock1
     |b|

     b := [:argList | Transcript 
			show:'invoked with args:'; 
			showCR:argList
	  ] asVarArgBlock.
     ^ b


!

getVarArgBlock2
     |b|

     b := [:argList | Transcript 
			show:'invoked with args:'; 
			showCR:argList.
		      argList
	  ] asVarArgBlock.
     ^ b


!

getVarArgBlock3
     |b|

     b := [:argList | Transcript 
			show:'invoked with args:'; 
			showCR:argList.
		      argList size
	  ] asVarArgBlock.
     ^ b


!

testBlock1
    |b|

    b := self getBlock1.

    b code notNil ifTrue:[
        Transcript showCR:'before call: *** blocks code is jitted'
    ] ifFalse:[
        Transcript showCR:'before call: blocks code is NOT jitted'
    ].
    b value:nil.
    b code notNil ifTrue:[
        Transcript showCR:'after call: blocks code is jitted'
    ] ifFalse:[
        Transcript showCR:'after call: *** blocks code is NOT jitted'
    ].

    b value:#foo.
    b value:1.
    b value:2

    "
     self new testBlock1
    "
!

testVarArgBlock1
    |b|

    b := self getVarArgBlock1.

    b value.
    b code notNil ifTrue:[
        Transcript showCR:'blocks code is jitted'
    ] ifFalse:[
        Transcript showCR:'*** blocks code is NOT jitted'
    ].

    b value.
    b value:'arg1'.
    b value:'arg1' value:'arg2' value:'arg3' value:'arg4'

    "
     self new testVarArgBlock1
    "
!

testVarArgBlock2
    |b|

    b := self getVarArgBlock2.

    b value.
    b code notNil ifTrue:[
        Transcript showCR:'blocks code is jitted'
    ] ifFalse:[
        Transcript showCR:'*** blocks code is NOT jitted'
    ].

    self assert:( b value     = #() ).
    self assert:( (b value:1) = #(1) ).
    self assert:( (b value:1 value:2) = #(1 2) ).
    self assert:( (b value:1 value:2 value:3) = #(1 2 3) ).
    self assert:( (b value:1 value:2 value:3 value:4) = #(1 2 3 4) ).
    self assert:( (b valueWithArguments:#(1 2 3 4)) = #(1 2 3 4) ).

    self assert:( (b perform:#value)     = #()  ).
    self assert:( (b perform:#'value:' with:1) = #(1) ).
    self assert:( (b perform:#'value:value:' with:1 with:2) = #(1 2) ).
    self assert:( (b perform:#'value:value:value:' with:1 with:2 with:3) = #(1 2 3) ).
    self assert:( (b perform:#'value:value:value:value:' with:1 with:2 with:3 with:4) = #(1 2 3 4) ).
    self assert:( (b perform:#'valueWithArguments:' with:#(1 2 3 4)) = #(1 2 3 4) ).

    "
     self new testVarArgBlock2
    "
!

testVarArgBlock3
    |b|

    b := self getVarArgBlock3.

    b value.
    b code notNil ifTrue:[
        Transcript showCR:'blocks code is jitted'
    ] ifFalse:[
        Transcript showCR:'*** blocks code is NOT jitted'
    ].

    self assert:( b value     = 0  ).
    self assert:( (b value:1) = 1  ).
    self assert:( (b value:1 value:2) = 2 ).
    self assert:( (b value:1 value:2 value:3) = 3 ).
    self assert:( (b value:1 value:2 value:3 value:4) = 4 ).
    self assert:( (b valueWithArguments:#(1 2 3 4)) = 4 ).

    self assert:( (b perform:#value)     = 0  ).
    self assert:( (b perform:#'value:' with:1) = 1 ).
    self assert:( (b perform:#'value:value:' with:1 with:2) = 2 ).
    self assert:( (b perform:#'value:value:value:' with:1 with:2 with:3) = 3 ).
    self assert:( (b perform:#'value:value:value:value:' with:1 with:2 with:3 with:4) = 4 ).
    self assert:( (b perform:#'valueWithArguments:' with:#(1 2 3 4)) = 4 ).

    "
     self new testVarArgBlock3
    "
!

xtestAll
    self testVarArgBlocks.

    "
     self new xtestAll
    "
!

xtestVarArgBlocks
    self testVarArgBlock1.
    self testVarArgBlock2.
    self testVarArgBlock3.
! !

!BlockTest class methodsFor:'documentation'!

version
    ^ '$Header$'
! !