@@ -3,6 +3,7 @@ module test_string_functions
3
3
use stdlib_error, only : check
4
4
use stdlib_string_type, only : string_type, assignment (= ), operator (==), &
5
5
to_lower, to_upper, to_title, to_sentence, reverse
6
+ use stdlib_strings, only: slice
6
7
implicit none
7
8
8
9
contains
@@ -52,6 +53,41 @@ subroutine test_reverse_string
52
53
53
54
end subroutine test_reverse_string
54
55
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
+
55
91
end module test_string_functions
56
92
57
93
@@ -64,5 +100,6 @@ program tester
64
100
call test_to_title_string
65
101
call test_to_sentence_string
66
102
call test_reverse_string
103
+ call test_slice_string
67
104
68
105
end program tester
0 commit comments