File: test_str_functions.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 (96 lines) | stat: -rw-r--r-- 2,600 bytes parent folder | download | duplicates (7)
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
;
; Alain Coulais, 16 Avril 2010
;
; Few basic tests on functions working on Strings
;
; Adding few new tests for STRMID, /reverse was broken but not tested !
; We really need as exhaustive as possible tests to avoid
; any unwanted regression, including improbables (e.g. typo in commit !)
;
pro TEST_STRMID, exit_on_error=exit_on_error, test=test
;
a='azerty'
flag_pb=0
;
if NOT(STRCMP(a,STRMID(a,0))) then flag_pb=1
if NOT(STRCMP(a,STRMID(a,0,100))) then flag_pb=flag_pb+1
;
res=STRMID(a,3)
if NOT(STRCMP(res,'rty')) then flag_pb=flag_pb+1
;
res=STRMID(a,3,1)
if NOT(STRCMP(res,'r')) then flag_pb=flag_pb+1
;
res=STRMID(a,2,1,/reverse)
if NOT(STRCMP(res,'r')) then flag_pb=flag_pb+1
;
res=STRMID(a,2,/reverse)
if NOT(STRCMP(res,'rty')) then flag_pb=flag_pb+1
;
if flag_pb GT 0 then begin
    MESSAGE, /continue, STRING(flag_pb)+' ERROR(s) found in STRMID'
    if KEYWORD_SET(exit_on_error) then  EXIT, status=1
endif else begin
    MESSAGE, /continue, 'No ERROR found in STRMID'
endelse
;
if KEYWORD_SET(test) then STOP
;
end
;
; ---------------
;
; return "0" when the arrays of substrings are different, else return "1"
function STRCMP_MULTI, str1, str2, debug=debug
;
if N_ELEMENTS(str1) NE N_ELEMENTS(str2) then return, 0
;
for ii=0, N_ELEMENTS(str1)-1 do begin
    if KEYWORD_SET(debug) then print, ii, str1[ii],str2[ii]
    if NOT(STRCMP(str1[ii],str2[ii])) then return, 0
endfor
return, 1
end
;
; -----------------------
;
pro TEST_STRSPLIT, exit_on_error=exit_on_error, test=test, debug=debug
;
str = 'rouge&&bleu&&jaune&&pair&impair'
expected_res1=['rouge','bleu','jaune','pair','impair']
expected_res2=['rouge','bleu','jaune','pair&impair']
;
flag_pb=0
res1=STRSPLIT(str,'&&',/EXTRACT)
if NOT(STRCMP_MULTI(res1,expected_res1,debug=debug)) then flag_pb=flag_pb+1
;
res2=STRSPLIT(str,'&&',/EXTRACT,/REGEX)
if NOT(STRCMP_MULTI(res2,expected_res2,debug=debug)) then flag_pb=flag_pb+1
;
str2 = '<4>What<1>a<7>tangled<3>web<2>we<6>weave.'
expected_res=['What','a','tangled','web','we','weave.']
res = STRSPLIT(str2,'<[0-9]+>',/EXTRACT,/REGEX)
if NOT(STRCMP_MULTI(res,expected_res,debug=debug)) then flag_pb=flag_pb+1
;
if flag_pb GT 0 then begin
    MESSAGE, /continue, STRING(flag_pb)+' ERROR(s) found in STRSPLIT'
    if KEYWORD_SET(exit_on_error) then  EXIT, status=1
endif else begin
    MESSAGE, /continue, 'No ERROR found in STRSPLIT'
endelse
;
if KEYWORD_SET(test) then STOP
;
end
;
; ---------------
;
pro TEST_STR_FUNCTIONS
;
; this is bad because tests in TEST_STRSPLIT
; will not be done if fails in TEST_STRMID ...
; 
TEST_STRMID, /exit_on_error
TEST_STRSPLIT, /exit_on_error
;
end