@@ -31,6 +31,7 @@ subroutine test_23(error_cnt)
31
31
integer :: ival
32
32
real (wp) :: rval
33
33
logical :: found
34
+ character (kind= json_CK,len= 10 ),dimension (:),allocatable :: cval_array
34
35
35
36
error_cnt = 0
36
37
call json% initialize( trailing_spaces_significant= .true. ,&
@@ -76,83 +77,115 @@ subroutine test_23(error_cnt)
76
77
write (error_unit,' (A)' ) ' '
77
78
key = ' /version/svn'
78
79
call json% get(key, ival)
79
- if (json% failed()) then
80
- call json% print_error_message(error_unit)
81
- error_cnt = error_cnt + 1
82
- else
83
- write (error_unit,' (A,I5)' ) key// ' = ' ,ival
84
- end if
80
+ call check_i()
85
81
86
82
write (error_unit,' (A)' ) ' '
87
83
key = ' /data/0/array/1'
88
84
call json% get(key, cval)
89
- if (json% failed()) then
90
- call json% print_error_message(error_unit)
91
- error_cnt = error_cnt + 1
92
- else
93
- write (error_unit,' (A)' ) key// ' = ' // trim (cval)
94
- end if
85
+ call check_c()
95
86
96
87
write (error_unit,' (A)' ) ' '
97
88
key = ' /files/0'
98
89
call json% get(key, cval)
99
- if (json% failed()) then
100
- call json% print_error_message(error_unit)
101
- error_cnt = error_cnt + 1
102
- else
103
- write (error_unit,' (A)' ) key// ' = ' // trim (cval)
104
- end if
90
+ call check_c()
105
91
106
92
write (error_unit,' (A)' ) ' '
107
93
key = ' /files/1'
108
94
call json% get(key, cval)
109
- if (json% failed()) then
110
- call json% print_error_message(error_unit)
111
- error_cnt = error_cnt + 1
112
- else
113
- write (error_unit,' (A)' ) key// ' = ' // trim (cval)
114
- end if
95
+ call check_c()
115
96
116
97
write (error_unit,' (A)' ) ' '
117
98
key = ' /files/2'
118
99
call json% get(key, cval)
119
- if (json% failed()) then
120
- call json% print_error_message(error_unit)
121
- error_cnt = error_cnt + 1
122
- else
123
- write (error_unit,' (A)' ) key// ' = ' // trim (cval)
124
- end if
100
+ call check_c()
125
101
126
102
write (error_unit,' (A)' ) ' '
127
103
key = ' /data/1/real'
128
104
call json% get(key, rval)
129
- if (json% failed()) then
130
- call json% print_error_message(error_unit)
131
- error_cnt = error_cnt + 1
132
- else
133
- write (error_unit,' (A,E30.16)' ) key// ' = ' ,rval
134
- end if
105
+ call check_i()
135
106
136
107
write (error_unit,' (A)' ) ' '
137
108
key = ' /files/3'
138
109
call json% get(key, cval) ! has hex characters
139
- if (json% failed()) then
140
- call json% print_error_message(error_unit)
141
- error_cnt = error_cnt + 1
142
- else
143
- write (error_unit,' (A)' ) key// ' = ' // trim (cval)
144
- end if
110
+ call check_c()
145
111
146
112
write (error_unit,' (A)' ) ' '
147
113
key = ' /files/4'
148
114
call json% get(key, cval) ! string with spaces and no escape characters
115
+ call check_c()
116
+
117
+ ! Test the examples in the RFC 6901 spec:
118
+
119
+ write (error_unit,' (A)' ) ' '
120
+ key = " "
121
+ call json% get(key, p) ! the whole document
149
122
if (json% failed()) then
150
- call json% print_error_message(error_unit)
151
- error_cnt = error_cnt + 1
123
+ write (error_unit,' (A)' ) ' Error: could not find ' // key
124
+ error_cnt = error_cnt + 1
125
+ end if
126
+
127
+ write (error_unit,' (A)' ) ' '
128
+ key = " /rfc6901 tests/foo"
129
+ call json% get(key, cval_array) ! ["bar", "baz"]
130
+ if (json% failed()) then
131
+ write (error_unit,' (A)' ) ' Error: could not find ' // key
132
+ error_cnt = error_cnt + 1
152
133
else
153
- write (error_unit,' (A)' ) key// ' = ' // trim (cval)
134
+ write (error_unit,' (A)' ) key// ' = ' ,cval_array
154
135
end if
155
136
137
+ write (error_unit,' (A)' ) ' '
138
+ key = " /rfc6901 tests/foo/0"
139
+ call json% get(key, cval) ! "bar"
140
+ call check_c() ! "bar"
141
+
142
+ write (error_unit,' (A)' ) ' '
143
+ key = " /rfc6901 tests/ "
144
+ call json% get(key, ival)
145
+ call check_i() ! 0
146
+
147
+ write (error_unit,' (A)' ) ' '
148
+ key = " /rfc6901 tests/a~1b"
149
+ call json% get(key, ival)
150
+ call check_i() ! 1
151
+
152
+ write (error_unit,' (A)' ) ' '
153
+ key = " /rfc6901 tests/c%d"
154
+ call json% get(key, ival)
155
+ call check_i() ! 2
156
+
157
+ write (error_unit,' (A)' ) ' '
158
+ key = " /rfc6901 tests/e^f"
159
+ call json% get(key, ival)
160
+ call check_i() ! 3
161
+
162
+ write (error_unit,' (A)' ) ' '
163
+ key = " /rfc6901 tests/g|h"
164
+ call json% get(key, ival)
165
+ call check_i() ! 4
166
+
167
+ write (error_unit,' (A)' ) ' '
168
+ key = " /rfc6901 tests/i\\j"
169
+ call json% get(key, ival)
170
+ call check_i() ! 5
171
+
172
+ write (error_unit,' (A)' ) ' '
173
+ key = " /rfc6901 tests/k\"" l"
174
+ call json% get(key, ival)
175
+ call check_i() ! 6
176
+
177
+ write (error_unit,' (A)' ) ' '
178
+ key = " /rfc6901 tests/ "
179
+ call json% get(key, ival)
180
+ call check_i() ! 7
181
+
182
+ write (error_unit,' (A)' ) ' '
183
+ key = " /rfc6901 tests/m~0n"
184
+ call json% get(key, ival)
185
+ call check_i() ! 8
186
+
187
+
188
+
156
189
!
157
190
! Test of values that aren't there:
158
191
! Note: when using the "found" output, the exceptions are cleared automatically.
@@ -211,6 +244,38 @@ subroutine test_23(error_cnt)
211
244
error_cnt = error_cnt + 1
212
245
end if
213
246
247
+ contains
248
+
249
+ subroutine check_c ()
250
+
251
+ ! ! check results of a character test
252
+
253
+ implicit none
254
+
255
+ if (json% failed()) then
256
+ call json% print_error_message(error_unit)
257
+ error_cnt = error_cnt + 1
258
+ else
259
+ write (error_unit,' (A)' ) key// ' = ' // cval
260
+ end if
261
+
262
+ end subroutine check_c
263
+
264
+ subroutine check_i ()
265
+
266
+ ! ! check results of an integer test
267
+
268
+ implicit none
269
+
270
+ if (json% failed()) then
271
+ call json% print_error_message(error_unit)
272
+ error_cnt = error_cnt + 1
273
+ else
274
+ write (error_unit,' (A,I5)' ) key// ' = ' ,ival
275
+ end if
276
+
277
+ end subroutine check_i
278
+
214
279
end subroutine test_23
215
280
216
281
end module jf_test_23_mod
0 commit comments