2
2
module test_string_match
3
3
use testdrive, only : new_unittest, unittest_type, error_type, check
4
4
use stdlib_ascii, only : reverse
5
- use stdlib_strings, only : starts_with, ends_with
5
+ use stdlib_strings, only : starts_with, ends_with, join
6
6
use stdlib_string_type, only : string_type
7
7
implicit none
8
8
@@ -16,7 +16,8 @@ subroutine collect_string_match(testsuite)
16
16
17
17
testsuite = [ &
18
18
new_unittest(" starts_with" , test_starts_with), &
19
- new_unittest(" ends_with" , test_ends_with) &
19
+ new_unittest(" ends_with" , test_ends_with), &
20
+ new_unittest(" join" , test_join) &
20
21
]
21
22
end subroutine collect_string_match
22
23
@@ -77,6 +78,32 @@ subroutine check_ends_with(error, string, substring)
77
78
call check(error, ends_with(string_type(string), string_type(substring)) .eqv. match, message)
78
79
end subroutine check_ends_with
79
80
81
+ subroutine test_join (error )
82
+ type (error_type), allocatable , intent (out ) :: error
83
+ character (len= 5 ) :: test_strings(3 )
84
+
85
+ test_strings = [character (5 ) :: " one" , " two" , " three" ]
86
+ call check_join(error, test_strings, " " , " one two three" )
87
+ if (allocated (error)) return
88
+ call check_join(error, test_strings, " ," , " one,two,three" )
89
+ if (allocated (error)) return
90
+ call check_join(error, test_strings, " -" , " one-two-three" )
91
+ end subroutine test_join
92
+
93
+ subroutine check_join (error , strings , separator , expected )
94
+ type (error_type), allocatable , intent (out ) :: error
95
+ character (len=* ), intent (in ) :: strings(:)
96
+ character (len=* ), intent (in ) :: separator
97
+ character (len=* ), intent (in ) :: expected
98
+ character (len= :), allocatable :: joined
99
+ character (len= :), allocatable :: message
100
+
101
+ joined = join(strings, separator)
102
+ message = " 'join' error: Expected '" // expected // " ' but got '" // joined // " '"
103
+ call check(error, joined == expected, message)
104
+
105
+ end subroutine check_join
106
+
80
107
subroutine test_ends_with (error )
81
108
type (error_type), allocatable , intent (out ) :: error
82
109
call check_ends_with(error, " pattern" , " pat" )
0 commit comments