|
| 1 | +!***************************************************************************************** |
| 2 | +!> |
| 3 | +! Module for the 32nd unit test. |
| 4 | + |
| 5 | +module jf_test_32_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_32(error_cnt) |
| 15 | + |
| 16 | + !! Test all the options and wrappers for [[json_get_path]]. |
| 17 | + |
| 18 | + implicit none |
| 19 | + |
| 20 | + integer,intent(out) :: error_cnt |
| 21 | + integer :: i !! counter |
| 22 | + integer :: j !! counter |
| 23 | + integer :: k !! counter |
| 24 | + type(json_core) :: json |
| 25 | + type(json_value),pointer :: p, p_var |
| 26 | + character(kind=CK,len=:),allocatable :: path_ck |
| 27 | + character(kind=CDK,len=:),allocatable :: path_cdk |
| 28 | + logical(LK) :: use_alt_array_tokens |
| 29 | + logical(LK) :: found |
| 30 | + |
| 31 | + character(kind=CK,len=1),parameter :: path_sep_ck = CK_'.' |
| 32 | + character(kind=CDK,len=1),parameter :: path_sep_cdk = CDK_'.' |
| 33 | + character(kind=CK,len=*),parameter :: json_string = CK_'{ "struct": {"a": [1,2]} }' |
| 34 | + |
| 35 | + error_cnt = 0 |
| 36 | + |
| 37 | + write(error_unit,'(A)') '' |
| 38 | + write(error_unit,'(A)') '=================================' |
| 39 | + write(error_unit,'(A)') ' TEST 32' |
| 40 | + write(error_unit,'(A)') '=================================' |
| 41 | + write(error_unit,'(A)') '' |
| 42 | + |
| 43 | + call json%initialize() |
| 44 | + |
| 45 | + call json%parse(p,json_string) |
| 46 | + if (json%failed()) then |
| 47 | + call json%print_error_message(error_unit) |
| 48 | + error_cnt = error_cnt + 1 |
| 49 | + else |
| 50 | + |
| 51 | + call json%get(p,CK_'struct.a(1)',p_var) |
| 52 | + |
| 53 | + if (json%failed()) then |
| 54 | + call json%print_error_message(error_unit) |
| 55 | + error_cnt = error_cnt + 1 |
| 56 | + else |
| 57 | + |
| 58 | + ! CK version: |
| 59 | + do i=1,2 |
| 60 | + use_alt_array_tokens = i==1 |
| 61 | + do j=1,2 |
| 62 | + if (j==1) then |
| 63 | + call json%get_path(p_var, path_ck, found, use_alt_array_tokens, path_sep_ck) |
| 64 | + else |
| 65 | + call json%get_path(p_var, path_ck, found, use_alt_array_tokens) |
| 66 | + end if |
| 67 | + if (json%failed()) then |
| 68 | + call json%print_error_message(error_unit) |
| 69 | + error_cnt = error_cnt + 1 |
| 70 | + else |
| 71 | + write(error_unit,'(A)') path_ck |
| 72 | + end if |
| 73 | + end do |
| 74 | + end do |
| 75 | + |
| 76 | + ! CDK version: |
| 77 | + do i=1,2 |
| 78 | + use_alt_array_tokens = i==1 |
| 79 | + do j=1,2 |
| 80 | + if (j==1) then |
| 81 | + call json%get_path(p_var, path_cdk, found, use_alt_array_tokens, path_sep_cdk) |
| 82 | + else |
| 83 | + call json%get_path(p_var, path_cdk, found, use_alt_array_tokens) |
| 84 | + end if |
| 85 | + if (json%failed()) then |
| 86 | + call json%print_error_message(error_unit) |
| 87 | + error_cnt = error_cnt + 1 |
| 88 | + else |
| 89 | + write(error_unit,'(A)') path_cdk |
| 90 | + end if |
| 91 | + end do |
| 92 | + end do |
| 93 | + |
| 94 | + end if |
| 95 | + |
| 96 | + end if |
| 97 | + |
| 98 | + if (.not. json%failed()) then |
| 99 | + write(error_unit,*) '' |
| 100 | + write(error_unit,*) 'Success!' |
| 101 | + end if |
| 102 | + |
| 103 | + call json%destroy(p) ! free memory |
| 104 | + |
| 105 | + end subroutine test_32 |
| 106 | + |
| 107 | +end module jf_test_32_mod |
| 108 | +!***************************************************************************************** |
| 109 | + |
| 110 | +#ifndef INTERGATED_TESTS |
| 111 | +!***************************************************************************************** |
| 112 | +program jf_test_32 |
| 113 | + |
| 114 | + !! 32nd unit test. |
| 115 | + |
| 116 | + use jf_test_32_mod , only: test_32 |
| 117 | + implicit none |
| 118 | + integer :: n_errors |
| 119 | + n_errors = 0 |
| 120 | + call test_32(n_errors) |
| 121 | + if (n_errors /= 0) stop 1 |
| 122 | + |
| 123 | +end program jf_test_32 |
| 124 | +!***************************************************************************************** |
| 125 | +#endif |
0 commit comments