File: test_strsplit.pro

package info (click to toggle)
gnudatalanguage 1.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,368 kB
  • sloc: cpp: 189,797; ansic: 46,721; sh: 677; python: 474; makefile: 146; xml: 69; f90: 28
file content (379 lines) | stat: -rw-r--r-- 11,360 bytes parent folder | download | duplicates (5)
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
;
; 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
;
; A bug 554 about "length" was corrected in July 2013.
;
pro IPRINT, texte, indice
print, texte, indice
indice=indice+1
end
;
pro TEST_STRSPLIT, no_exit=no_exit, verbose=verbose, test=test, debug=debug, help=help
;
if KEYWORD_SET(help) then begin
   print, 'pro TEST_STRSPLIT, no_exit=no_exit, 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'
str7='aa;aaaaaaaaa;aaaaaaaaaa'  ; cf bug 554
strarray=[str,str1,str2,str3,str4,str5,str6,str7]
;
; 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

ext=STRSPLIT(str,'$',/preserve,length=length)
if ARRAY_EQUAL(length,replicate(0,STRLEN(str)+1)) eq 0 then begin 
   if KEYWORD_SET(verbose) then MESSAGE, 'error str len+preserve', /continue
   nb_pbs=nb_pbs+1
endif

ext=STRSPLIT(str,'$',length=length)
if (length ne 0) then begin 
   if KEYWORD_SET(verbose) then MESSAGE, 'error str len', /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(str4,'.',length=length)
if ARRAY_EQUAL(length,[4,3]) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str4 length', /continue
   nb_pbs=nb_pbs+1
endif
tab=STRSPLIT(str4,'.',length=length,/preserve)
if ARRAY_EQUAL(length,[0,0,4,3]) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str4 length+preserve', /continue
   nb_pbs=nb_pbs+1
endif
;
; few tests on str7
;
pos=STRSPLIT(str7,';',length=length)
if ARRAY_EQUAL(length,[2,9,10]) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 length', /continue
   nb_pbs=nb_pbs+1
endif
if ARRAY_EQUAL(pos,[0,3,13]) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 pos', /continue
   nb_pbs=nb_pbs+1
endif
;
pos=STRSPLIT(str7,'.',length=length)
if ARRAY_EQUAL(length,23) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 length no sep', /continue
   nb_pbs=nb_pbs+1
endif
if (pos NE 0) then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 pos no sep', /continue
   nb_pbs=nb_pbs+1
endif
;
pos=STRSPLIT(str7,'a',length=length)
if ARRAY_EQUAL(length,[1,1]) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 length <<a>>', /continue
   nb_pbs=nb_pbs+1
endif
if ARRAY_EQUAL(pos,[2,12]) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 pos <<a>>', /continue
   nb_pbs=nb_pbs+1
endif
;
pos=STRSPLIT(str7,'a',length=length,/preserve)
exp_pos=LONG([INDGEN(3), INDGEN(9)+4,INDGEN(10)+14])
exp_len=LONARR(STRLEN(str7)-1)
exp_len[2]=1
exp_len[2+9]=1
;
if ARRAY_EQUAL(pos,exp_pos) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 pos <<a>> /preserve', /continue
   nb_pbs=nb_pbs+1
endif
if ARRAY_EQUAL(length,exp_len) eq 0 then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'error str7 length <<a>> /preserve', /continue
   nb_pbs=nb_pbs+1
endif
;
; tests on str5
;
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
;
; we must return a STRARR except for ''
;
tab=STRSPLIT('eeee','e',/extract)
if (SIZE(tab, /n_dim) NE 0) then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'bad size for void string', /continue
   nb_pbs=nb_pbs+1
endif
tab=STRSPLIT('eeABCee','e',/extract)
if (SIZE(tab, /n_dim) NE 1) then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'bad size for 1D STRARR', /continue
   nb_pbs=nb_pbs+1
endif
if (tab NE 'ABC') then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'bad value in STRARR', /continue
   nb_pbs=nb_pbs+1
endif
tab=STRSPLIT('eeABCeeABCee','e',/extract)
if (SIZE(tab, /n_dim) NE 1) then begin
   if KEYWORD_SET(verbose) then MESSAGE, 'bad size for 2 elements STRARR', /continue
   nb_pbs=nb_pbs+1
endif

;textoidl uses strstrans which uses strsplit
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

;new version: supports arrays:
res=strsplit(strarray,COUNT=c, LENGTH=l)
;
line="======================================="
MESSAGE, /Continue, line
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
MESSAGE, /Continue, " "
MESSAGE, /Continue, line
;
; 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) or KEYWORD_SET(no_exit)) then EXIT, status=1
endif
;
if KEYWORD_SET(test) then STOP
;
end