|
| 1 | +!***************************************************************************************** |
| 2 | +!> |
| 3 | +! Module for the 27th unit test. |
| 4 | + |
| 5 | +module jf_test_27_mod |
| 6 | + |
| 7 | + use json_module, rk => json_rk, lk => json_lk, ik => json_ik, ck => json_ck, cdk => json_cdk |
| 8 | + use, intrinsic :: iso_fortran_env , only: error_unit, output_unit |
| 9 | + |
| 10 | + implicit none |
| 11 | + |
| 12 | +contains |
| 13 | + |
| 14 | + subroutine test_27(error_cnt) |
| 15 | + |
| 16 | + !! Test the printing of vectors on one line |
| 17 | + |
| 18 | + implicit none |
| 19 | + |
| 20 | + integer,intent(out) :: error_cnt |
| 21 | + |
| 22 | + type(json_value),pointer :: p |
| 23 | + type(json_core) :: json |
| 24 | + type(json_file) :: f |
| 25 | + |
| 26 | + character(kind=CK,len=*),parameter :: json_str = & |
| 27 | + '{"int_vec": [1,2,3], "int": 1, "object": {"int_vec": [1,2,3]},'//& |
| 28 | + '"vec": [[1,2],[3,4]], "vec_of_objects": [{"a":1},{"bvec":[1,2,3]}]}' |
| 29 | + |
| 30 | + error_cnt = 0 |
| 31 | + call json%initialize(compress_vectors=.true.) |
| 32 | + if (json%failed()) then |
| 33 | + call json%print_error_message(error_unit) |
| 34 | + error_cnt = error_cnt + 1 |
| 35 | + end if |
| 36 | + |
| 37 | + write(error_unit,'(A)') '' |
| 38 | + write(error_unit,'(A)') '=================================' |
| 39 | + write(error_unit,'(A)') ' TEST 27' |
| 40 | + write(error_unit,'(A)') '=================================' |
| 41 | + write(error_unit,'(A)') '' |
| 42 | + |
| 43 | + write(error_unit,'(A)') '' |
| 44 | + write(error_unit,'(A)') 'JSON string: '//json_str |
| 45 | + |
| 46 | + write(error_unit,'(A)') '' |
| 47 | + write(error_unit,'(A)') 'parsing...' |
| 48 | + call json%parse(p,json_str) |
| 49 | + if (json%failed()) then |
| 50 | + call json%print_error_message(error_unit) |
| 51 | + error_cnt = error_cnt + 1 |
| 52 | + end if |
| 53 | + |
| 54 | + write(error_unit,'(A)') '' |
| 55 | + write(error_unit,'(A)') 'printing...' |
| 56 | + call json%print(p,output_unit) |
| 57 | + |
| 58 | + ! test json_file interface |
| 59 | + f = json_file(p) |
| 60 | + call f%initialize(compress_vectors=.true.) |
| 61 | + call f%print_file() |
| 62 | + |
| 63 | + if (f%failed()) then |
| 64 | + call f%print_error_message(error_unit) |
| 65 | + error_cnt = error_cnt + 1 |
| 66 | + end if |
| 67 | + |
| 68 | + ! clean up |
| 69 | + write(error_unit,'(A)') '' |
| 70 | + write(error_unit,'(A)') 'destroy...' |
| 71 | + call json%destroy(p) |
| 72 | + if (json%failed()) then |
| 73 | + call json%print_error_message(error_unit) |
| 74 | + error_cnt = error_cnt + 1 |
| 75 | + end if |
| 76 | + |
| 77 | + end subroutine test_27 |
| 78 | + |
| 79 | +end module jf_test_27_mod |
| 80 | +!***************************************************************************************** |
| 81 | + |
| 82 | +!***************************************************************************************** |
| 83 | +program jf_test_27 |
| 84 | + |
| 85 | + !! 27th unit test. |
| 86 | + |
| 87 | + use jf_test_27_mod , only: test_27 |
| 88 | + implicit none |
| 89 | + integer :: n_errors |
| 90 | + n_errors = 0 |
| 91 | + call test_27(n_errors) |
| 92 | + if (n_errors /= 0) stop 1 |
| 93 | + |
| 94 | +end program jf_test_27 |
| 95 | +!***************************************************************************************** |
0 commit comments