@@ -3,6 +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
67 implicit none
78
89contains
@@ -52,6 +53,41 @@ subroutine test_reverse_string
5253
5354 end subroutine test_reverse_string
5455
56+ subroutine test_slice_string
57+ type (string_type) :: test_string
58+ test_string = " abcdefghijklmnopqrstuvwxyz"
59+
60+ call check(slice(test_string, 2 , 16 , 3 ) == " behkn" , &
61+ ' function slice failed' , warn= .false. )
62+ call check(slice(test_string, 15 , stride=- 1 ) == " onmlkjihgfedcba" , &
63+ ' function slice failed' , warn= .false. )
64+ call check(slice(test_string, last= 22 , stride=- 1 ) == " zyxwv" , &
65+ ' function slice failed' , warn= .false. )
66+ call check(slice(test_string, 7 , 2 ) == " gfedcb" , &
67+ ' function slice failed' , warn= .false. )
68+ call check(slice(test_string, 7 , 2 , 1 ) == " " , &
69+ ' function slice failed' , warn= .false. )
70+ call check(slice(test_string, 2 , 6 , - 1 ) == " " , &
71+ ' function slice failed' , warn= .false. )
72+ call check(slice(test_string, stride=- 1 ) == " zyxwvutsrqponmlkjihgfedcba" , &
73+ ' function slice failed' , warn= .false. )
74+ call check(slice(test_string, 7 , 7 , - 4 ) == " g" , &
75+ ' function slice failed' , warn= .false. )
76+ call check(slice(test_string, 7 , 7 , 3 ) == " g" , &
77+ ' function slice failed' , warn= .false. )
78+ call check(slice(test_string, 7 , 7 , 3 ) == " g" , &
79+ ' function slice failed' , warn= .false. )
80+ call check(slice(test_string, 7 , - 10 ) == " gfedcba" , &
81+ ' function slice failed' , warn= .false. )
82+ call check(slice(test_string, 500 , 22 ) == " zyxwv" , &
83+ ' function slice failed' , warn= .false. )
84+
85+ test_string = " "
86+ call check(slice(test_string, 2 , 16 , 3 ) == " " , &
87+ ' function slice failed' , warn= .false. )
88+
89+ end subroutine test_slice_string
90+
5591end module test_string_functions
5692
5793
@@ -64,5 +100,6 @@ program tester
64100 call test_to_title_string
65101 call test_to_sentence_string
66102 call test_reverse_string
103+ call test_slice_string
67104
68105end program tester
0 commit comments