|
| 1 | +! SPDX-Identifier: MIT |
| 2 | +module test_string_functions |
| 3 | + use stdlib_error, only : check |
| 4 | + use stdlib_string_type, only : string_type, assignment(=), operator(==), & |
| 5 | + to_lower, to_upper, to_title, reverse |
| 6 | + implicit none |
| 7 | + |
| 8 | +contains |
| 9 | + |
| 10 | + subroutine test_to_lower_string |
| 11 | + type(string_type) :: test_string, compare_string |
| 12 | + test_string = "To_LoWEr !$%-az09AZ" |
| 13 | + compare_string = "to_lower !$%-az09az" |
| 14 | + |
| 15 | + call check(to_lower(test_string) == compare_string) |
| 16 | + |
| 17 | + end subroutine test_to_lower_string |
| 18 | + |
| 19 | + subroutine test_to_upper_string |
| 20 | + type(string_type) :: test_string, compare_string |
| 21 | + test_string = "To_UpPeR !$%-az09AZ" |
| 22 | + compare_string = "TO_UPPER !$%-AZ09AZ" |
| 23 | + |
| 24 | + call check(to_upper(test_string) == compare_string) |
| 25 | + |
| 26 | + end subroutine test_to_upper_string |
| 27 | + |
| 28 | + subroutine test_to_title_string |
| 29 | + type(string_type) :: test_string, compare_string |
| 30 | + test_string = "_#To tiTlE !$%-az09AZ" |
| 31 | + compare_string = "_#To title !$%-a09az" |
| 32 | + |
| 33 | + call check(to_title(test_string) == compare_string) |
| 34 | + |
| 35 | + end subroutine test_to_title_string |
| 36 | + |
| 37 | + subroutine test_reverse_string |
| 38 | + type(string_type) :: test_string, compare_string |
| 39 | + test_string = "_To ReVerSe !$%-az09AZ " |
| 40 | + compare_string = " ZA90za-%$! eSreVeR oT_" |
| 41 | + |
| 42 | + call check(reverse(test_string) == compare_string) |
| 43 | + |
| 44 | + end subroutine test_reverse_string |
| 45 | + |
| 46 | +end module test_string_functions |
| 47 | + |
| 48 | + |
| 49 | +program tester |
| 50 | + use test_string_functions |
| 51 | + implicit none |
| 52 | + |
| 53 | + call test_to_lower_string |
| 54 | + call test_to_upper_string |
| 55 | + call test_to_title_string |
| 56 | + call test_reverse_string |
| 57 | + |
| 58 | +end program tester |
0 commit comments