|
1 | 1 | ! SPDX-Identifier: MIT
|
2 |
| -module test_string_format_string |
3 |
| - use stdlib_strings, only: format_string, starts_with |
| 2 | +module test_string_format_to_string |
| 3 | + use stdlib_strings, only: format_to_string, starts_with |
4 | 4 | use stdlib_error, only: check
|
5 | 5 | use stdlib_optval, only: optval
|
6 | 6 | implicit none
|
@@ -31,83 +31,83 @@ subroutine check_formatter(actual, expected, description, partial)
|
31 | 31 |
|
32 | 32 | end subroutine check_formatter
|
33 | 33 |
|
34 |
| - subroutine test_format_string_complex |
35 |
| - call check_formatter(format_string((1, 1)), "(1.0", & |
| 34 | + subroutine test_format_to_string_complex |
| 35 | + call check_formatter(format_to_string((1, 1)), "(1.0", & |
36 | 36 | & "Default formatter for complex number", partial=.true.)
|
37 |
| - call check_formatter(format_string((1, 1), '(F6.2)'), "( 1.00, 1.00)", & |
| 37 | + call check_formatter(format_to_string((1, 1), '(F6.2)'), "( 1.00, 1.00)", & |
38 | 38 | & "Formatter for complex number")
|
39 |
| - call check_formatter(format_string((-1, -1), '(F6.2)'), "( -1.00, -1.00)", & |
| 39 | + call check_formatter(format_to_string((-1, -1), '(F6.2)'), "( -1.00, -1.00)", & |
40 | 40 | & "Formatter for negative complex number")
|
41 |
| - call check_formatter(format_string((1, 1), '(SP,F6.2)'), "( +1.00, +1.00)", & |
| 41 | + call check_formatter(format_to_string((1, 1), '(SP,F6.2)'), "( +1.00, +1.00)", & |
42 | 42 | & "Formatter with sign control descriptor for complex number")
|
43 |
| - call check_formatter(format_string((1, 1), '(F6.2)') // format_string((2, 2), '(F7.3)'), & |
| 43 | + call check_formatter(format_to_string((1, 1), '(F6.2)') // format_to_string((2, 2), '(F7.3)'), & |
44 | 44 | & "( 1.00, 1.00)( 2.000, 2.000)", &
|
45 | 45 | & "Multiple formatters for complex numbers")
|
46 | 46 |
|
47 |
| - end subroutine test_format_string_complex |
| 47 | + end subroutine test_format_to_string_complex |
48 | 48 |
|
49 |
| - subroutine test_format_string_integer |
50 |
| - call check_formatter(format_string(100), "100", & |
| 49 | + subroutine test_format_to_string_integer |
| 50 | + call check_formatter(format_to_string(100), "100", & |
51 | 51 | & "Default formatter for integer number")
|
52 |
| - call check_formatter(format_string(100, '(I6)'), " 100", & |
| 52 | + call check_formatter(format_to_string(100, '(I6)'), " 100", & |
53 | 53 | & "Formatter for integer number")
|
54 |
| - call check_formatter(format_string(100, '(I0.6)'), "000100", & |
| 54 | + call check_formatter(format_to_string(100, '(I0.6)'), "000100", & |
55 | 55 | & "Formatter with zero padding for integer number")
|
56 |
| - call check_formatter(format_string(100, '(I6)') // format_string(1000, '(I7)'), & |
| 56 | + call check_formatter(format_to_string(100, '(I6)') // format_to_string(1000, '(I7)'), & |
57 | 57 | & " 100 1000", "Multiple formatters for integers")
|
58 |
| - call check_formatter(format_string(34, '(B8)'), " 100010", & |
| 58 | + call check_formatter(format_to_string(34, '(B8)'), " 100010", & |
59 | 59 | & "Binary formatter for integer number")
|
60 |
| - call check_formatter(format_string(34, '(O0.3)'), "042", & |
| 60 | + call check_formatter(format_to_string(34, '(O0.3)'), "042", & |
61 | 61 | & "Octal formatter with zero padding for integer number")
|
62 |
| - call check_formatter(format_string(34, '(Z3)'), " 22", & |
| 62 | + call check_formatter(format_to_string(34, '(Z3)'), " 22", & |
63 | 63 | & "Hexadecimal formatter for integer number")
|
64 | 64 |
|
65 |
| - end subroutine test_format_string_integer |
| 65 | + end subroutine test_format_to_string_integer |
66 | 66 |
|
67 |
| - subroutine test_format_string_real |
68 |
| - call check_formatter(format_string(100.), "100.0", & |
| 67 | + subroutine test_format_to_string_real |
| 68 | + call check_formatter(format_to_string(100.), "100.0", & |
69 | 69 | & "Default formatter for real number", partial=.true.)
|
70 |
| - call check_formatter(format_string(100., '(F6.2)'), "100.00", & |
| 70 | + call check_formatter(format_to_string(100., '(F6.2)'), "100.00", & |
71 | 71 | & "Formatter for real number")
|
72 |
| - call check_formatter(format_string(289., '(E7.2)'), ".29E+03", & |
| 72 | + call check_formatter(format_to_string(289., '(E7.2)'), ".29E+03", & |
73 | 73 | & "Exponential formatter with rounding for real number")
|
74 |
| - call check_formatter(format_string(128., '(ES8.2)'), "1.28E+02", & |
| 74 | + call check_formatter(format_to_string(128., '(ES8.2)'), "1.28E+02", & |
75 | 75 | & "Exponential formatter for real number")
|
76 | 76 |
|
77 | 77 | ! Wrong demonstration
|
78 |
| - call check_formatter(format_string(-100., '(F6.2)'), "*", & |
| 78 | + call check_formatter(format_to_string(-100., '(F6.2)'), "*", & |
79 | 79 | & "Too narrow formatter for signed real number", partial=.true.)
|
80 |
| - call check_formatter(format_string(1000., '(F6.3)'), "*", & |
| 80 | + call check_formatter(format_to_string(1000., '(F6.3)'), "*", & |
81 | 81 | & "Too narrow formatter for real number", partial=.true.)
|
82 |
| - call check_formatter(format_string(1000., '(7.3)'), "*", & |
| 82 | + call check_formatter(format_to_string(1000., '(7.3)'), "[*]", & |
83 | 83 | & "Invalid formatter for real number", partial=.true.)
|
84 | 84 |
|
85 |
| - end subroutine test_format_string_real |
| 85 | + end subroutine test_format_to_string_real |
86 | 86 |
|
87 |
| - subroutine test_format_string_logical |
88 |
| - call check_formatter(format_string(.true.), "T", & |
| 87 | + subroutine test_format_to_string_logical |
| 88 | + call check_formatter(format_to_string(.true.), "T", & |
89 | 89 | & "Default formatter for logcal value")
|
90 |
| - call check_formatter(format_string(.true., '(L2)'), " T", & |
| 90 | + call check_formatter(format_to_string(.true., '(L2)'), " T", & |
91 | 91 | & "Formatter for logical value")
|
92 |
| - call check_formatter(format_string(.false., '(L2)') // format_string(.true., '(L5)'), & |
| 92 | + call check_formatter(format_to_string(.false., '(L2)') // format_to_string(.true., '(L5)'), & |
93 | 93 | & " F T", "Multiple formatters for logical values")
|
94 | 94 |
|
95 | 95 | ! Wrong demonstration
|
96 |
| - call check_formatter(format_string(.false., '(1x)'), "*", & |
| 96 | + call check_formatter(format_to_string(.false., '(1x)'), "[*]", & |
97 | 97 | & "Invalid formatter for logical value", partial=.true.)
|
98 | 98 |
|
99 |
| - end subroutine test_format_string_logical |
| 99 | + end subroutine test_format_to_string_logical |
100 | 100 |
|
101 | 101 |
|
102 |
| -end module test_string_format_string |
| 102 | +end module test_string_format_to_string |
103 | 103 |
|
104 | 104 | program tester
|
105 |
| - use test_string_format_string |
| 105 | + use test_string_format_to_string |
106 | 106 | implicit none
|
107 | 107 |
|
108 |
| - call test_format_string_complex |
109 |
| - call test_format_string_integer |
110 |
| - call test_format_string_logical |
111 |
| - call test_format_string_real |
| 108 | + call test_format_to_string_complex |
| 109 | + call test_format_to_string_integer |
| 110 | + call test_format_to_string_logical |
| 111 | + call test_format_to_string_real |
112 | 112 |
|
113 | 113 | end program tester
|
0 commit comments