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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
;
; some tests for STRPLIT
;
; Lea Noreskal, June 2010, under GNU GPL V2 or later
;
; Alain Coulais, October 2010:
; -- few extra cases. Also adding tests on count= and lenght= keywords
;
; Alain Coulais, August 2011:
; -- inaccurate tests found, corrected (ARRAY_EQUAL(a,b,/NO_TYPECONC))
; -- change from /quiet to /verbose
; -- no exit on error if /debug or /test (suppose to be interactive ;-)
; -- adding test for bug 3286746 (STR_SEP)
; -- adding basic test for TexToIDL
;
pro IPRINT, texte, indice
print, texte, indice
indice=indice+1
end
;
pro TEST_STRSPLIT, verbose=verbose, test=test, debug=debug, help=help
;
if KEYWORD_SET(help) then begin
print, 'pro TEST_STRSPLIT, verbose=verbose, test=test, debug=debug, help=help'
return
endif
;
nb_pbs=0
indice=0
;
str='$$$$$$$$$$' ; LONG 0
str1='$chops &up str*ings.' ; [1]
str2='ch$ops &up str*ings.' ; [0,3]
str3='$ch$ops &up str*ings.' ; [1,4]
str4='../foo.txt' ; [2,7]
str5=' t e s t '
str6='qwerty'
;
; When Search Pattern is not in Input String (default Search pattern
; is white space ' ')
;
tab=STRSPLIT(str6)
if (tab ne 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str basic 0', /continue
nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str6,/extract)
if (tab ne str6) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str basic 0 bis', /continue
nb_pbs=nb_pbs+1
endif
;
if KEYWORD_SET(debug) then IPRINT, 'ici', indice
;
; When Search Pattern is a stupid void input ''
;
tab=STRSPLIT(str5,'')
if ((SIZE(tab,/type) NE 3) and (tab ne 0)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str basic 1', /continue
nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str5,'',/extract)
if (tab ne '') then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str basic 1 bis', /continue
nb_pbs=nb_pbs+1
endif
;
if KEYWORD_SET(debug) then IPRINT, 'ici', indice
;
; When Search Pattern is not in Input String
;
tab=STRSPLIT(str5,'a')
if ((SIZE(tab,/type) NE 3) and (tab ne 0)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str basic 2', /continue
nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str5,'a',/extract)
if (tab ne str5) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str basic 2 bis', /continue
nb_pbs=nb_pbs+1
endif
;
;
if KEYWORD_SET(debug) then IPRINT, 'ici', indice
;
tab=STRSPLIT(str,'$')
if ((SIZE(tab,/type) NE 3) and (tab ne 0)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str,'$',/ext)
;print , str , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
if(N_ELEMENTS(ext) ne 1) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str extract', /continue
nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str,'$',/preserve)
res=LINDGEN(11)
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str preserve_null', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str,'$',/ext,/preserve)
;print , str , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
if (N_ELEMENTS(ext) ne 11) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str extract', /continue
nb_pbs=nb_pbs+1
endif
;
if KEYWORD_SET(debug) then IPRINT, 'ici', indice
;
tab=STRSPLIT(str1,'$')
res=[1L]
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str1', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str1,'$',/ext)
;print , str1 , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
res=['chops &up str*ings.']
if( (N_ELEMENTS(ext) ne 1) AND (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0 )) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str extract', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str1,'$',/ext,/preserve)
;print , str1 , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
if((N_ELEMENTS(ext) ne 2)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str1 extract preserves', /continue
nb_pbs=nb_pbs+1
endif
;
if KEYWORD_SET(debug) then IPRINT, 'ici', indice
tab=STRSPLIT(str2,'$')
res=LONG([0,3])
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str2', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str2,'$',/ext)
;print , str2 , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
res=['ch' , 'ops &up str*ings.' ]
if ((N_ELEMENTS(ext) ne 2) AND (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0 )) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str extract', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str2,'$',/ext,/preserve)
;print , str2 , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
if ((N_ELEMENTS(ext) ne 2)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str2 extract preserve', /continue
nb_pbs=nb_pbs+1
endif
;
;
tab=STRSPLIT(str2,'$',/preserve)
res=LONG([0,3])
if (ARRAY_EQUAL(tab,res,/NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str2 preserve_null', /continue
nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str3,'$')
res=LONG([1,4])
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str3', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str3,'$',/ext)
;print , str3 , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
res=['ch' , 'ops &up str*ings.' ]
if ((N_ELEMENTS(ext) ne 2) AND (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0 )) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str extract', /continue
nb_pbs=nb_pbs+1
endif
;
ext=STRSPLIT(str3,'$',/ext,/preserve)
;print , str3 , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
if ((N_ELEMENTS(ext) ne 3)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str3 extract preserve', /continue
nb_pbs=nb_pbs+1
endif
;
if KEYWORD_SET(debug) then IPRINT, 'ici', indice
;
tab=STRSPLIT(str4,'.')
res=LONG([2,7])
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str4', /continue
nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str4,'.',/preserve)
res=LONG([0,1,2,7])
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str4 preserve_null', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str4,'.',/ext,/preserve)
;print , str4 , ' Fext> ' , strjoin(ext,'-') , N_ELEMENTS(ext)
if ((N_ELEMENTS(ext) ne 4)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str4 extract , preserve', /continue
nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str5,/preserve)
res=LONG([0,1,3,5,7,9])
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str5 preserve_null', /continue
nb_pbs=nb_pbs+1
endif
ext=STRSPLIT(str5,/preserve,/extract)
if((N_ELEMENTS(ext) ne 6)) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error str5 extract , preserve', /continue
nb_pbs=nb_pbs+1
endif
;
; bug found via STR_SEP 3286746 in the Patch section
;
tab=STR_SEP('ahasadfasdf','dfa')
res=['ahasa','sdf']
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error STR_SEP 3286746', /continue
nb_pbs=nb_pbs+1
endif
tab=STR_SEP('ahasadfasdfa','dfa')
res=['ahasa','s','']
if (ARRAY_EQUAL(tab,res, /NO_TYPECONV) eq 0) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error STR_SEP 3286746, /preserve_null', /continue
nb_pbs=nb_pbs+1
endif
;
;
vide=''
if (EXECUTE('res=TEXTOIDL(vide)') EQ 0) then begin
MESSAGE, /CONTINUE, "Missing TexToIDL in your GDL_PATH or IDL_PATH"
endif else begin
res='!7l!X!U2!N'
tab=TEXTOIDL('\mu^2')
if (res NE tab) then begin
if KEYWORD_SET(verbose) then MESSAGE, 'error when using TexToIDL', /continue
nb_pbs=nb_pbs+1
endif
endelse
;
MESSAGE, /Continue, "=============================="
mess=' errors encoutered during STRSPLIT tests'
if (nb_pbs GT 0) then mess=STRING(nb_pbs)+mess else mess='NO'+mess
MESSAGE, /Continue, mess
;
; if /debug OR /test nodes, we don't want to exit
if (nb_pbs GT 0) then begin
if ~(KEYWORD_SET(debug) or KEYWORD_SET(test)) then EXIT, status=1
endif
;
if KEYWORD_SET(test) then STOP
;
end
|