Skip to content

Commit ba6870f

Browse files
committed
coverage increase for swap function.
1 parent 747c0b7 commit ba6870f

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

src/tests/jf_test_16.f90

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ subroutine test_16(error_cnt)
112112
write(error_unit,'(A)') 'Error: this should have failed.'
113113
error_cnt = error_cnt + 1
114114
else
115-
write(error_unit,'(A)') 'Success: This operation is not allowed.'
116115
call json%clear_exceptions()
117116
end if
118117
nullify(p1)
@@ -132,6 +131,86 @@ subroutine test_16(error_cnt)
132131
nullify(p1)
133132
nullify(p2)
134133

134+
call json%destroy(p)
135+
136+
!...........................................................................
137+
! other special cases:
138+
139+
!swap first and last items in a list
140+
write(error_unit,'(A)') ''
141+
write(error_unit,'(A)') '.....................................'
142+
write(error_unit,'(A)') ''
143+
write(error_unit,'(A)') 'Original:'
144+
call json%parse(p, '{ "color": "red", "width": 10, "height": 2 }')
145+
if (json%failed()) then
146+
call json%print_error_message(error_unit)
147+
error_cnt = error_cnt + 1
148+
end if
149+
call json%print(p,error_unit)
150+
write(error_unit,'(A)') ''
151+
write(error_unit,'(A)') 'Swap: color <-> height'
152+
call json%get(p,'color',p1)
153+
call json%get(p,'height',p2)
154+
call json%swap(p1,p2)
155+
if (json%failed()) then
156+
call json%print_error_message(error_unit)
157+
error_cnt = error_cnt + 1
158+
end if
159+
call json%print(p,output_unit)
160+
nullify(p1)
161+
nullify(p2)
162+
call json%destroy(p)
163+
164+
!p2 is first child:
165+
write(error_unit,'(A)') ''
166+
write(error_unit,'(A)') '.....................................'
167+
write(error_unit,'(A)') ''
168+
write(error_unit,'(A)') 'Original:'
169+
call json%parse(p, '{ "color": "red", "width": 10, "height": 2 }')
170+
if (json%failed()) then
171+
call json%print_error_message(error_unit)
172+
error_cnt = error_cnt + 1
173+
end if
174+
call json%print(p,error_unit)
175+
write(error_unit,'(A)') ''
176+
write(error_unit,'(A)') 'Swap: width <-> color'
177+
call json%get(p,'width',p1)
178+
call json%get(p,'color',p2)
179+
call json%swap(p1,p2)
180+
if (json%failed()) then
181+
call json%print_error_message(error_unit)
182+
error_cnt = error_cnt + 1
183+
end if
184+
call json%print(p,output_unit)
185+
nullify(p1)
186+
nullify(p2)
187+
call json%destroy(p)
188+
189+
!p2 is last child:
190+
write(error_unit,'(A)') ''
191+
write(error_unit,'(A)') '.....................................'
192+
write(error_unit,'(A)') ''
193+
write(error_unit,'(A)') 'Original:'
194+
call json%parse(p, '{ "color": "red", "width": 10, "height": 2 }')
195+
if (json%failed()) then
196+
call json%print_error_message(error_unit)
197+
error_cnt = error_cnt + 1
198+
end if
199+
call json%print(p,error_unit)
200+
write(error_unit,'(A)') ''
201+
write(error_unit,'(A)') 'Swap: width <-> height'
202+
call json%get(p,'width',p1)
203+
call json%get(p,'height',p2)
204+
call json%swap(p1,p2)
205+
if (json%failed()) then
206+
call json%print_error_message(error_unit)
207+
error_cnt = error_cnt + 1
208+
end if
209+
call json%print(p,output_unit)
210+
nullify(p1)
211+
nullify(p2)
212+
call json%destroy(p)
213+
135214
end subroutine test_16
136215

137216
end module jf_test_16_mod

0 commit comments

Comments
 (0)