Files
harbour-core/tests/foreach.prg
Przemysław Czerpak 877ddb4a06 2013-04-18 14:58 UTC+0200 Przemysław Czerpak (druzus/at/poczta.onet.pl)
* .gitignore
    ! removed executable file permission

  * package/mpkg_src.sh
    ! added executable file permission

  * contrib/hbct/screen2.c
    % use STR API for parameters instead of using local conversions

  * contrib/hbct/token1.c
    % small simplification

  * contrib/hbnetio/netiosrv.c
    + respect timeout parameter also in send operation

  * contrib/make.hb
    ! moved project name normalization and directory verification to
      AddProject() function. It fixes HB_BUILD_ADDONS envvar functionality.

  * doc/xhb-diff.txt
    + added new paragraph: DECLARATION AND INITIALIZATION OF VARIABLES

  * src/rtl/hbcom.c
    * added 3-rd parameter to TIOCEXCL and TIOCNXCL ioctl() codes
      to pacify valgrind warnings

  * include/hbexpra.c
    ! fixed compilation with HB_USE_ENUM_FUNCTIONS macro

  * include/hbapicls.h
  * include/hbcompdf.h
  * include/hbexpra.c
  * src/compiler/harbour.y
  * src/vm/classes.c
    + added support for :__enumIsFirst() iterator message. It's opposite
      to recently added :__enumIsLast()
    + added support for overloading :__enumIsFirst() and :__enumIsLast()
      functionality in custom FOR EACH implementations

  * include/hbcompdf.h
  * include/hbexpra.c
  * src/compiler/harbour.y
    + added support for reverting :__enumIsFirst() and :__enumIsLast()
      messages in descendant FOR EACH loops. It's disabled now by 2 #if 0
      but I think it should be discussed. Should we keep it enable it?
      The answer is not trivial when FOR EACH is used to iterate some
      objects. In general such names are confusing.

  * src/compiler/harbour.yyc
  * src/compiler/harbour.yyh
    * regenerated using bison 2.5

  * tests/foreach.prg
    + added :__enumIsFirst() to test code

  * tests/foreach2.prg
    ! typo in comment
2013-04-18 14:58:40 +02:00

168 lines
4.7 KiB
Plaintext

#define LEFTEQUAL( l, r ) ( Left( l, Len( r ) ) == r )
PROCEDURE Main()
LOCAL A := { "one ", "two ", "three" }
LOCAL AA := { "AA-one ", "AA-two ", "AA-three", "AA-four " }
LOCAL c := "abcdefghij"
LOCAL enum := "b"
LOCAL bb, cc
LOCAL i
#if 0
test( @a, b )
test( a, @b )
test( @a, @b )
#endif
? "========================================================"
? "before loop: ENUM=", ENUM
? "before loop: a[1]=", a[ 1 ], "a[2]=", a[ 2 ], "a[3]=", a[ 3 ]
FOR EACH enum IN A
? "start: ENUM=", enum
IF LEFTEQUAL( enum, "two" )
enum := Upper( enum )
ENDIF
? "end: ENUM=", enum, ;
"| index:", enum:__enumIndex(), ;
"| value:", enum:__enumValue(), ;
"| base:", ValType( enum:__enumBase() ), ;
"| isfirst:", enum:__enumIsFirst(), ;
"| islast:", enum:__enumIsLast()
NEXT
? "after loop ENUM=", enum
? "after loop: a[1]=", a[ 1 ], "a[2]=", a[ 2 ], "a[3]=", a[ 3 ]
? "-----------------"
?
Inkey( 0 )
? "========================================================"
? "Testing passing by reference"
? "before loop: ENUM=", enum
? "after loop: a[1]=", a[ 1 ], "a[2]=", a[ 2 ], "a[3]=", a[ 3 ]
FOR EACH enum IN A
IF LEFTEQUAL( Upper( enum ), "TWO" )
enum := Upper( enum )
? "before passing by @ | ENUM=", enum, ;
"| index:", enum:__enumIndex(), ;
"| value:", enum:__enumValue(), ;
"| base:", ValType( enum:__enumBase() ), ;
"| isfirst:", enum:__enumIsFirst(), ;
"| islast:", enum:__enumIsLast()
testBYREF( @enum )
? " after passing by @ | ENUM=", enum, ;
"| index:", enum:__enumIndex(), ;
"| value:", enum:__enumValue(), ;
"| base:", ValType( enum:__enumBase() ), ;
"| isfirst:", enum:__enumIsFirst(), ;
"| islast:", enum:__enumIsLast()
ENDIF
NEXT
? "after loop ENUM=", enum
? "after loop: a[1]=", a[ 1 ], "a[2]=", a[ 2 ], "a[3]=", a[ 3 ]
Inkey( 0 )
? "========================================================"
? "Testing BREAK"
? "before loop: ENUM=", enum
? "after loop: a[1]=", a[ 1 ], "a[2]=", a[ 2 ], "a[3]=", a[ 3 ]
BEGIN SEQUENCE
FOR EACH enum IN A DESCEND
? "loop: ENUM=", enum, ;
"| index:", enum:__enumIndex(), ;
"| value:", enum:__enumValue(), ;
"| base:", ValType( enum:__enumBase() ), ;
"| isfirst:", enum:__enumIsFirst(), ;
"| islast:", enum:__enumIsLast()
TESTbreak( enum )
NEXT
RECOVER USING i
? "after loop ENUM=", enum
? "after loop: a[1]=", a[ 1 ], "a[2]=", a[ 2 ], "a[3]=", a[ 3 ]
? "recover variable i=", i
END SEQUENCE
Inkey( 0 )
? "========================================================"
? "before loop: ENUM=", enum
? "before loop: c=", c
BEGIN SEQUENCE
FOR EACH enum IN c
? "start: ENUM=", enum
IF LEFTEQUAL( enum, "d" )
enum := Upper( enum )
ENDIF
Testbreak( enum )
? "end: ENUM=", enum, ;
"| index:", enum:__enumIndex(), ;
"| value:", enum:__enumValue(), ;
"| base:", ValType( enum:__enumBase() ), ;
"| isfirst:", enum:__enumIsFirst(), ;
"| islast:", enum:__enumIsLast()
NEXT
RECOVER USING i
? "after loop ENUM=", enum
? "after loop: c=", c
? "recover variable i=", i
END SEQUENCE
? "========================================================"
FOR EACH enum, bb, cc IN A, AA, c
? enum, enum:__enumIndex(), enum:__enumValue()
? bb, bb:__enumIndex(), bb:__enumValue()
? cc, cc:__enumIndex(), cc:__enumValue()
NEXT
Inkey( 0 )
? "========================================================"
FOR EACH enum, bb, cc IN A, AA, c DESCEND
? enum, enum:__enumIndex(), enum:__enumValue()
? bb, bb:__enumIndex(), bb:__enumValue()
? cc, cc:__enumIndex(), cc:__enumValue()
NEXT
FOR EACH enum IN a
BEGIN SEQUENCE
IF LEFTEQUAL( enum, "2" )
BREAK
ENDIF
END SEQUENCE
NEXT
FOR EACH enum IN a
BEGIN SEQUENCE
IF LEFTEQUAL( enum, "2" )
? "Breaking... enum=", enum
BREAK enum
ENDIF
RECOVER USING enum
? "after recovery: enum=", enum
END SEQUENCE
NEXT
RETURN
STATIC PROCEDURE TESTbreak( v )
IF LEFTEQUAL( v, "2" ) .OR. LEFTEQUAL( v, "d" )
? "issuing break"
Break( v )
ENDIF
RETURN
STATIC PROCEDURE TESTBYREF( enum )
? "start of testBYREF ENUM=", enum
FOR EACH enum IN { 1, 2, 3 }
? " -testBYREF=", enum
NEXT
? "end of loop: ENUM=", enum
enum := "22222"
? "end of testBYREF ENUM=", enum
RETURN