@@ -58,53 +58,66 @@ end subroutine test_reverse_string
58
58
59
59
subroutine test_slice_string
60
60
type (string_type) :: test_string
61
- character (len= :), allocatable :: test_char
62
61
test_string = " abcdefghijklmnopqrstuvwxyz"
63
- test_char = " abcdefghijklmnopqrstuvwxyz"
64
-
65
- call check(slice(test_string, 2 , 16 , 3 ) == " behkn" , &
66
- ' function slice failed' , warn= .false. )
67
- call check(slice(test_char, first= 15 , stride=- 1 ) == " onmlkjihgfedcba" , &
68
- ' function slice failed' , warn= .false. )
69
- call check(slice(test_string, last= 22 , stride=- 1 ) == " zyxwv" , &
70
- ' function slice failed' , warn= .false. )
71
- call check(slice(test_char, 7 , 2 ) == " gfedcb" , &
72
- ' function slice failed' , warn= .false. )
73
- call check(slice(test_string, 7 , 2 , 1 ) == " " , &
74
- ' function slice failed' , warn= .false. )
75
- call check(slice(test_char, 2 , 6 , - 1 ) == " " , &
76
- ' function slice failed' , warn= .false. )
77
- call check(slice(test_string, stride=- 1 ) == " zyxwvutsrqponmlkjihgfedcba" , &
78
- ' function slice failed' , warn= .false. )
79
- call check(slice(test_string, 7 , 7 , - 4 ) == " g" , &
80
- ' function slice failed' , warn= .false. )
81
- call check(slice(test_char, 7 , 7 , 3 ) == " g" , &
82
- ' function slice failed' , warn= .false. )
83
- call check(slice(test_string, 7 , 7 , 3 ) == " g" , &
84
- ' function slice failed' , warn= .false. )
85
- call check(slice(test_char, 7 , - 10 ) == " gfedcba" , &
86
- ' function slice failed' , warn= .false. )
87
- call check(slice(test_string, 500 , 22 ) == " zyxwv" , &
88
- ' function slice failed' , warn= .false. )
89
- call check(slice(test_char, 50 , 27 ) == " " , &
90
- ' function slice failed' , warn= .false. )
91
- call check(slice(test_string, - 20 , - 200 ) == " " , &
92
- ' function slice failed' , warn= .false. )
93
- call check(slice(test_char, first= 0 , stride=- 1 ) == " " , &
94
- ' function slice failed' , warn= .false. )
95
- call check(slice(test_string, last= 27 , stride=- 2 ) == " " , &
96
- ' function slice failed' , warn= .false. )
97
- call check(slice(test_char, first= 27 , stride= 2 ) == " " , &
98
- ' function slice failed' , warn= .false. )
99
- call check(slice(test_string, - 500 , 500 ) == " abcdefghijklmnopqrstuvwxyz" , &
100
- ' function slice failed' , warn= .false. )
101
62
63
+ ! Only one argument is given
64
+ ! Valid
65
+ call check(slice(test_string, first= 10 ) == " jklmnopqrstuvwxyz" ) ! last=+inf
66
+ call check(slice(test_string, last= 10 ) == " abcdefghij" ) ! first=-inf
67
+ call check(slice(test_string, stride= 3 ) == " adgjmpsvy" ) ! first=-inf, last=+inf
68
+ call check(slice(test_string, stride=- 3 ) == " zwtqnkheb" ) ! first=+inf, last=-inf
69
+
70
+ ! Invalid
71
+ call check(slice(test_string, first= 27 ) == " " ) ! last=+inf
72
+ call check(slice(test_string, first=- 10 ) == " abcdefghijklmnopqrstuvwxyz" ) ! last=+inf
73
+ call check(slice(test_string, last=- 2 ) == " " ) ! first=-inf
74
+ call check(slice(test_string, last= 30 ) == " abcdefghijklmnopqrstuvwxyz" ) ! first=-inf
75
+ call check(slice(test_string, stride= 0 ) == " abcdefghijklmnopqrstuvwxyz" ) ! stride=1
76
+
77
+ ! Only two arguments are given
78
+ ! Valid
79
+ call check(slice(test_string, first= 10 , last= 20 ) == " jklmnopqrst" )
80
+ call check(slice(test_string, first= 7 , last= 2 ) == " gfedcb" ) ! stride=-1
81
+ call check(slice(test_string, first= 10 , stride=- 2 ) == " jhfdb" ) ! last=-inf
82
+ call check(slice(test_string, last= 21 , stride=- 2 ) == " zxv" ) ! first=+inf
83
+
84
+ ! Atleast one argument is invalid
85
+ call check(slice(test_string, first= 30 , last=- 3 ) == " zyxwvutsrqponmlkjihgfedcba" )
86
+ call check(slice(test_string, first= 1 , last=- 20 ) == " a" )
87
+ call check(slice(test_string, first= 7 , last=- 10 ) == " gfedcba" )
88
+ call check(slice(test_string, first= 500 , last= 22 ) == " zyxwv" )
89
+ call check(slice(test_string, first= 50 , last= 27 ) == " " )
90
+ call check(slice(test_string, first=- 20 , last= 0 ) == " " )
91
+ call check(slice(test_string, last=- 3 , stride=- 2 ) == " zxvtrpnljhfdb" ) ! first=+inf
92
+ call check(slice(test_string, last= 10 , stride= 0 ) == " abcdefghij" ) ! stride=1
93
+ call check(slice(test_string, first=- 2 , stride=- 2 ) == " " ) ! last=-inf
94
+ call check(slice(test_string, first= 27 , stride= 2 ) == " " ) ! last=+inf
95
+ call check(slice(test_string, last= 27 , stride=- 1 ) == " " ) ! first=+inf
96
+
97
+ ! All three arguments are given
98
+ ! Valid
99
+ call check(slice(test_string, first= 2 , last= 16 , stride= 3 ) == " behkn" )
100
+ call check(slice(test_string, first= 16 , last= 2 , stride=- 3 ) == " pmjgd" )
101
+ call check(slice(test_string, first= 7 , last= 7 , stride=- 4 ) == " g" )
102
+ call check(slice(test_string, first= 7 , last= 7 , stride= 3 ) == " g" )
103
+ call check(slice(test_string, first= 2 , last= 6 , stride=- 1 ) == " " )
104
+ call check(slice(test_string, first= 20 , last= 10 , stride= 2 ) == " " )
105
+
106
+ ! Invalid
107
+ call check(slice(test_string, first= 20 , last= 30 , stride= 2 ) == " tvxz" )
108
+ call check(slice(test_string, first=- 20 , last= 30 , stride= 2 ) == " acegikmoqsuwy" )
109
+ call check(slice(test_string, first= 26 , last= 30 , stride= 1 ) == " z" )
110
+ call check(slice(test_string, first= 1 , last=- 20 , stride=- 1 ) == " a" )
111
+ call check(slice(test_string, first= 26 , last= 20 , stride= 1 ) == " " )
112
+ call check(slice(test_string, first= 1 , last= 20 , stride=- 1 ) == " " )
113
+
102
114
test_string = " "
103
- test_char = " "
104
- call check(slice(test_string, 2 , 16 , 3 ) == " " , &
105
- ' function slice failed' , warn= .false. )
106
- call check(slice(test_char, 2 , 16 , 3 ) == " " , &
107
- ' function slice failed' , warn= .false. )
115
+ ! Empty string input
116
+ call check(slice(test_string, first=- 2 , last= 6 ) == " " )
117
+ call check(slice(test_string, first= 6 , last=- 2 ) == " " )
118
+ call check(slice(test_string, first=- 10 ) == " " ) ! last=+inf
119
+ call check(slice(test_string, last= 10 ) == " " ) ! first=-inf
120
+ call check(slice(test_string) == " " )
108
121
109
122
end subroutine test_slice_string
110
123
0 commit comments