@@ -319,13 +319,62 @@ pure function carray_to_string(carray) result(string)
319
319
end function carray_to_string
320
320
321
321
subroutine test_replace_all
322
- character (len= :), allocatable :: test_string
323
- test_string = " qwqwqwqwqwqwqwqwpqr"
324
- call check(replace_all(test_string, " qwq" , " wqw" , .true. ) == " wqwwqwwqwwqwwqwwqwwqwwpqr" )
325
- call check(replace_all(test_string, " qwq" , " abcd" ) == " abcdwabcdwabcdwabcdwpqr" )
326
- call check(replace_all(test_string, " " , " abcd" ) == test_string)
322
+ type (string_type) :: test_string_1, test_pattern_1, test_replacement_1
323
+ type (string_type) :: test_string_2, test_pattern_2, test_replacement_2
324
+ test_string_1 = " mutate DNA sequence: GTTATCGTATGCCGTAATTAT"
325
+ test_pattern_1 = " TAT"
326
+ test_replacement_1 = " ATA"
327
+ test_string_2 = " mutate DNA sequence: AGAGAGCCTAGAGAGAG"
328
+ test_pattern_2 = " AGA"
329
+ test_replacement_2 = " aga"
330
+
331
+ ! all 3 as string_type
332
+ call check(replace_all(test_string_1, test_pattern_1, test_replacement_1) == &
333
+ & " mutate DNA sequence: GTATACGATAGCCGTAATATA" , &
334
+ & " Replace_all: all 3 string_type, test case 1" )
335
+ call check(replace_all(test_string_2, test_pattern_2, test_replacement_2) == &
336
+ & " mutate DNA sequence: agaGAGCCTagaGagaG" , &
337
+ & " Replace_all: all 3 string_type, test case 2" )
338
+ call check(replace_all(test_string_2, test_pattern_2, test_replacement_1) == &
339
+ & " mutate DNA sequence: ATAGAGCCTATAGATAG" , &
340
+ & " Replace_all: all 3 string_type, test case 3" )
341
+
342
+ ! 2 as string_type and 1 as character scalar
343
+ call check(replace_all(test_string_1, " tat" , test_replacement_1) == &
344
+ & " muATAe DNA sequence: GTTATCGTATGCCGTAATTAT" , &
345
+ & " Replace_all: 2 string_type & 1 character scalar, test case 1" )
346
+ call check(replace_all(test_string_2, test_pattern_2, " GC" ) == &
347
+ & " mutate DNA sequence: GCGAGCCTGCGGCG" , &
348
+ & " Replace_all: 2 string_type & 1 character scalar, test case 2" )
349
+ call check(replace_all(" mutate DNA sequence: AGAGAGCCTAGAGAGAG" , test_pattern_2, &
350
+ & test_replacement_2) == " mutate DNA sequence: agaGAGCCTagaGagaG" , &
351
+ & " Replace_all: 2 string_type & 1 character scalar, test case 3" )
327
352
328
- call check(replace_all(" " , " qwq" , " abcd" ) == " " )
353
+
354
+ ! 1 as string_type and 2 as character scalar
355
+ call check(replace_all(test_string_1, " TAT" , " ATA" ) == &
356
+ & " mutate DNA sequence: GTATACGATAGCCGTAATATA" , &
357
+ & " Replace_all: 1 string_type & 2 character scalar, test case 1" )
358
+ call check(replace_all(" mutate DNA sequence: AGAGAGCCTAGAGAGAG" , test_pattern_2, &
359
+ & " GC" ) == " mutate DNA sequence: GCGAGCCTGCGGCG" , &
360
+ & " Replace_all: 1 string_type & 2 character scalar, test case 2" )
361
+ call check(replace_all(" mutate DNA sequence: GTTATCGTATGCCGTAATTAT" , " TA" , &
362
+ & test_replacement_2) == " mutate DNA sequence: GTagaTCGagaTGCCGagaATagaT" , &
363
+ & " Replace_all: 1 string_type & 2 character scalar, test case 3" )
364
+ call check(replace_all(" mutate DNA sequence: GTTATCGTATGCCGTAATTAT" , &
365
+ & test_pattern_1, " " ) == " mutate DNA sequence: GTCGGCCGTAAT" , &
366
+ & " Replace_all: 1 string_type & 2 character scalar, test case 4" )
367
+ call check(replace_all(test_string_1, " " , " anything here" ) == test_string_1, &
368
+ & " Replace_all: 1 string_type & 2 character scalar, test case 5" )
369
+ call check(replace_all(" " , test_pattern_2, " anything here" ) == " " , &
370
+ & " Replace_all: 1 string_type & 2 character scalar, test case 6" )
371
+
372
+ ! all 3 as character scalar
373
+ call check(replace_all(" mutate DNA sequence: GTTATCGTATGCCGTAATTAT" , &
374
+ & " GT" , " gct" ) == " mutate DNA sequence: gctTATCgctATGCCgctAATTAT" , &
375
+ & " Replace_all: all 3 character scalar, test case 1" )
376
+ call check(replace_all(" " , " anything here" , " anything here" ) == " " , &
377
+ & " Replace_all: all 3 character scalar, test case 2" )
329
378
330
379
end subroutine test_replace_all
331
380
0 commit comments