Skip to content

Commit 819bd22

Browse files
committed
added unit tests for find function
1 parent c133ae0 commit 819bd22

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/tests/string/test_string_functions.f90

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module test_string_functions
33
use stdlib_error, only : check
44
use stdlib_string_type, only : string_type, assignment(=), operator(==), &
55
to_lower, to_upper, to_title, to_sentence, reverse
6-
use stdlib_strings, only: slice
6+
use stdlib_strings, only: slice, find
77
implicit none
88

99
contains
@@ -53,7 +53,7 @@ subroutine test_reverse_string
5353

5454
end subroutine test_reverse_string
5555

56-
subroutine test_slice_string
56+
subroutine test_slice
5757
type(string_type) :: test_string
5858
character(len=:), allocatable :: test_char
5959
test_string = "abcdefghijklmnopqrstuvwxyz"
@@ -103,7 +103,20 @@ subroutine test_slice_string
103103
call check(slice(test_char, 2, 16, 3) == "", &
104104
'function slice failed', warn=.false.)
105105

106-
end subroutine test_slice_string
106+
end subroutine test_slice
107+
108+
subroutine test_find
109+
type(string_type) :: test_string, test_pattern
110+
test_string = "qwqwqwqwqwqwqw"
111+
test_pattern = "qwq"
112+
call check(find(test_string, test_pattern, 4) == 7)
113+
call check(find(test_string, test_pattern, 3, .false.) == 9)
114+
call check(find(test_string, test_pattern, 7) == 0)
115+
call check(find("qwqwqwqwqwqwqw", test_pattern) == 1)
116+
call check(find(test_string, "qwq", 2) == 3)
117+
call check(find("qwqwqwqwqwqwqw", "qwq", 2, .false.) == 5)
118+
119+
end subroutine test_find
107120

108121
end module test_string_functions
109122

@@ -117,6 +130,7 @@ program tester
117130
call test_to_title_string
118131
call test_to_sentence_string
119132
call test_reverse_string
120-
call test_slice_string
133+
call test_slice
134+
call test_find
121135

122136
end program tester

0 commit comments

Comments
 (0)