Skip to content

Commit 0d27f92

Browse files
committed
test join
1 parent f16afd2 commit 0d27f92

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

test/string/test_string_match.f90

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module test_string_match
33
use testdrive, only : new_unittest, unittest_type, error_type, check
44
use stdlib_ascii, only : reverse
5-
use stdlib_strings, only : starts_with, ends_with
5+
use stdlib_strings, only : starts_with, ends_with, join
66
use stdlib_string_type, only : string_type
77
implicit none
88

@@ -16,7 +16,8 @@ subroutine collect_string_match(testsuite)
1616

1717
testsuite = [ &
1818
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) &
2021
]
2122
end subroutine collect_string_match
2223

@@ -77,6 +78,32 @@ subroutine check_ends_with(error, string, substring)
7778
call check(error, ends_with(string_type(string), string_type(substring)) .eqv. match, message)
7879
end subroutine check_ends_with
7980

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+
80107
subroutine test_ends_with(error)
81108
type(error_type), allocatable, intent(out) :: error
82109
call check_ends_with(error, "pattern", "pat")

0 commit comments

Comments
 (0)