Files
harbour-core/harbour/tests/codebl.prg
Viktor Szakats 55801b18c4 2008-08-20 12:50 UTC+0200 Viktor Szakats (harbour.01 syenar hu)
* tests/longdev.prg
   * tests/hbpptest/hbpptest.prg
   * tests/testcgi.prg
   * tests/foreach.prg
   * tests/onidle.prg
   * tests/tstchbx.prg
   * tests/codebl.prg
   * tests/tstdbi.prg
   * tests/vmasort.prg
   * tests/tstasort.prg
   * tests/testbrw.prg
   * tests/inkeytst.prg
   * tests/testrdd2.prg
   * tests/keywords.prg
   * tests/testhtml.prg
   * tests/readhrb.prg
   * tests/stripem.prg
   * tests/wvtext.prg
   * tests/testpre.prg
   * tests/seconds.prg
   * tests/fsplit.prg
   * tests/mousetst.prg
   * contrib/hbmysql/tmysql.prg
   * contrib/hbct/numconv.prg
   * contrib/hbct/ctmisc.prg
   * contrib/hbodbc/todbc.prg
   * contrib/hbapollo/tests/apollo.prg
   * contrib/hbnf/acctyear.prg
   * contrib/hbnf/acctadj.prg
   * contrib/hbnf/nwsem.prg
   * contrib/hbnf/week.prg
   * contrib/hbnf/acctmnth.prg
   * contrib/hbnf/savearr.prg
   * contrib/hbnf/madd.prg
   * contrib/hbnf/mouse1.prg
   * contrib/hbnf/month.prg
   * contrib/hbnf/findith.prg
   * contrib/hbnf/acctweek.prg
   * contrib/hbnf/pegs.prg
   * contrib/hbnf/acctqtr.prg
   * contrib/hbnf/nooccur.prg
   * contrib/hbnf/dayofyr.prg
   * contrib/hbnf/menu1.prg
   * contrib/hbnf/sqzn.prg
   * contrib/hbnf/asum.prg
   * contrib/hbnf/aavg.prg
   * contrib/hbnf/any2any.prg
   * contrib/hbnf/adessort.prg
   * contrib/hbnf/amedian.prg
   * contrib/hbnf/blink.prg
   * contrib/hbnf/qtr.prg
   * contrib/hbnf/aredit.prg
   * contrib/hbnf/xbox.prg
   * contrib/hbnf/ftround.prg
   * contrib/hbnf/invclr.prg
   * contrib/hbnf/tempfile.prg
   * contrib/hbnf/diskfunc.prg
   * contrib/hbnf/mouse2.prg
   * contrib/hbnf/daytobow.prg
   * contrib/hbnf/anomatch.prg
   * contrib/hbnf/datecnfg.prg
   * contrib/hbnf/tbwhile.prg
   * contrib/hbnf/year.prg
   * contrib/hbnf/elapsed.prg
   * contrib/hbnf/dfile.prg
   * contrib/hbnf/clrsel.prg
   * contrib/hbmisc/twirler.prg
   * contrib/hbmisc/fileread.prg
   * contrib/hbmisc/stringp.prg
   * contrib/hbgf/hbgfw32/winctrl.prg
   * contrib/hbgf/hbgfw32/form.prg
   * contrib/hbgf/hbgfos2/winctrl.prg
   * contrib/hbgf/hbgfos2/tform.prg
   * contrib/hbtip/httpcln.prg
   * contrib/hbvpdf/hbvpdf.prg
   * contrib/hbvpdf/hbvpdft.prg
   * contrib/examples/guestbk/guestbk.prg
   * contrib/examples/pe/editorhi.prg
     * Some more general code cleanups ( if() -> iif() ).
2008-08-20 11:04:28 +00:00

172 lines
3.7 KiB
Plaintext

//
// $Id$
//
STATIC cbStatic
Function Main()
Local a := TestBlocks()
LOCAL cb
qout( eval( a[ 1 ] ) ) // 23
qout( eval( a[ 2 ], 42 ) ) // 42
qout( eval( a[ 1 ] ) ) // 42
qout( eval( a[ 2 ], 15 ) ) // 15
mqout( 15, eval( a[ 1 ] ) ) // 15 15
mqout( 14, eval( a[ 1 ] ) ) // 14 15
mqout( 42, eval( a[ 2 ], 42 ) ) // 42 42
mqout( 14, eval( a[ 2 ], 42 ) ) // 14 42
mqout( 42, eval( a[ 1 ] ) ) // 42 42
mqout( 14, eval( a[ 1 ] ) ) // 14 42
GetArray( @a )
PrintArray( @a )
qout( "Test for variables passed by reference in a codeblock" )
DetachWithRefer()
qout( "Test for indirect detaching of local variables" )
DetachToStatic( 1 )
mqout( 2, EVAL( cbStatic, 1 ) )
mqout( 3, EVAL( cbStatic, 2 ) )
cb :=cbStatic
DetachToStatic( 100 )
mqout( 200, EVAL( cbStatic, 100 ) )
mqout( 300, EVAL( cbStatic, 200 ) )
mqout( 4, EVAL( cb, 3 ) )
ReferParam()
Return( NIL )
Static Function TestBlocks()
LOCAL nFoo := 23
Return( { {|| nFoo }, {|n| nFoo := n } } )
Static Function mqout( nExpected, nGot )
qout( nExpected, nGot )
Return( NIL )
/////////////////////////////////////////////////////////////////
PROCEDURE GetArray( a )
LOCAL i
a :=ARRAY( 100 )
FOR i:=1 TO 100
IF (i % 6) == 0
a[ i-2 ] =NIL
a[ i-4 ] =NIL
ENDIF
a[ i ] := TestBlocks()
NEXT
RETURN
PROCEDURE PrintArray( a )
LOCAL i
FOR i:=1 TO 100
IF a[i] != NIL
EVAL( a[ i ][ 2 ], i )
mqout( i, EVAL( a[ i ][ 1 ] ) )
ENDIF
NEXT
RETURN
//////////////////////////////////////////////////////////////////
Function DetachWithRefer()
Local nTest
Local bBlock1 := MakeBlock()
Local bBlock2 := {|| DoThing( @nTest ), qout( nTest ) }
eval( bBlock1 )
eval( bBlock2 )
Return( NIL )
Function MakeBlock()
Local nTest
RETURN( {|| DoThing( @nTest ), qout( nTest ) } )
Function DoThing( n )
n := 42
Return( NIL )
//////////////////////////////////////////////////////////////////////
FUNCTION DetachToStatic( n )
cbStatic ={|x| n+x}
RETURN NIL
// ------------------------------------------------------------
Function ReferParam()
Local bResult
? "Test for codeblock parameter passed by reference"
PassByValue( {|lEnd| ;
bResult := GetBlock( @lEnd ), ;
SetByRef( @lEnd ) } )
// Clipper & xHarbour it's .T.
//In Harbour it is .F.
? "Printed value in Clipper .T. =", Eval( bResult )
?
// Notice the Clipper bug: GetBlock is receiving the reference to
// the codeblock parameter than the value of EVAL(bResult) shouldn't
// depend on the order of block creation/value changing (GetBlock/SetRef).
PassByRef( {|lEnd| ;
bResult := GetBlock( @lEnd ), ;
SetByRef( @lEnd ) } )
// Clipper & xHarbour it's .T.
//In Harbour it is .F.
? "Printed value in Clipper .T. =", Eval( bResult )
?
? "2nd test for codeblock parameter passed by reference"
PassByValue( {|lEnd| ;
SetByRef( @lEnd ), ;
bResult := GetBlock( @lEnd ) } )
// Clipper & xHarbour it's .T.
//In Harbour it is .F.
? "Printed value in Clipper .F. =", Eval( bResult )
?
PassByRef( {|lEnd| ;
SetByRef( @lEnd ), ;
bResult := GetBlock( @lEnd ) } )
// Clipper & xHarbour it's .T.
//In Harbour it is .F.
? "Printed value in Clipper .F. =", Eval( bResult )
?
Return Nil
Static Function PassByValue( bBlock )
Local lSomeVar := .T.
Eval( bBlock, lSomeVar )
? "lSomeVar value in Clipper .T. =", lSomeVar
Return .T.
Static Function PassByRef( bBlock )
Local lSomeVar := .T.
Eval( bBlock, @lSomeVar )
? "lSomeVar value in Clipper .F. =", lSomeVar
Return .T.
Static Function SetByRef( lVar )
lVar := .F.
Return Nil
Static Function GetBlock( lVar )
Return {|| lVar }
// ------------------------------------------------------------