1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
;
; under GNU GPL v3
; Alain Coulais, 17 july 2017
;
; remember that ARG_PRESENT() can return TRUE (1)
; if and only if the key can be modified outside
; (If the value is fixed, will return FALSE)
;
; -----------------------------------------------------------------
;
pro MYPROC, value, key=key
;
if ARG_PRESENT(key) then begin
value=1
endif else begin
value=0
endelse
;
end
;
; -----------------------------------------------------------------
;
function MYFUNCTION, key=key
;
if ARG_PRESENT(key) then begin
return, 1
endif else begin
return, 0
endelse
;
end
;
; -----------------------------------------------------------------
;
pro TEST_ARG_PRESENT, help=help, verbose=verbose, no_exit=no_exit, test=test
;
if KEYWORD_SET(help) then begin
print, 'pro TEST_ARG_PRESENT, help=help, verbose=verbose, $'
print, ' no_exit=no_exit, test=test'
return
endif
;
errors=0
value=-1
key_can_change=123
;
; Testing for PROCEDURE the 4 cases (0,0,0,1)
;
MYPROC, value
if (value NE 0) then ERRORS_ADD, errors, 'first PRO case'
;
MYPROC, value, /key
if (value NE 0) then ERRORS_ADD, errors, 'second PRO case'
;
MYPROC, value, key=123
if (value NE 0) then ERRORS_ADD, errors, 'third PRO case'
MYPROC, value, key=key_can_change
if (value NE 1) then ERRORS_ADD, errors, 'fourth PRO case (the ONE !)'
;
; Now testing for FUNCTION the 4 cases (0,0,0,1)
;
value=MYFUNCTION()
if (value NE 0) then ERRORS_ADD, errors, 'first FUN case'
;
value=MYFUNCTION(/key)
if (value NE 0) then ERRORS_ADD, errors, 'second FUN case'
;
value=MYFUNCTION( key=123)
if (value NE 0) then ERRORS_ADD, errors, 'third FUN case'
;
value=MYFUNCTION(key=key_can_change)
if (value NE 1) then ERRORS_ADD, errors, 'fourth FUN case (the ONE !)'
;
;
; ----------------- final message ----------
;
BANNER_FOR_TESTSUITE, 'TEST_ARG_PRESENT', errors
;
if (errors GT 0) AND ~KEYWORD_SET(no_exit) then EXIT, status=1
;
if KEYWORD_SET(test) then STOP
;
end
;
|