|  | 
|  | 1 | +!***************************************************************************************** | 
|  | 2 | +!> | 
|  | 3 | +! Module for the 42nd unit test | 
|  | 4 | + | 
|  | 5 | +module jf_test_42_mod | 
|  | 6 | + | 
|  | 7 | +    use json_module, CK => json_CK, IK => json_IK, RK => json_RK, LK => json_LK | 
|  | 8 | +    use, intrinsic :: iso_fortran_env , only: error_unit, output_unit | 
|  | 9 | + | 
|  | 10 | +    implicit none | 
|  | 11 | + | 
|  | 12 | +    private | 
|  | 13 | +    public :: test_42 | 
|  | 14 | + | 
|  | 15 | +contains | 
|  | 16 | + | 
|  | 17 | +    subroutine test_42(error_cnt) | 
|  | 18 | + | 
|  | 19 | +    !! Test of NaN and Infinity | 
|  | 20 | + | 
|  | 21 | +    implicit none | 
|  | 22 | + | 
|  | 23 | +    type(json_file) :: json          !! the JSON structure read from the file | 
|  | 24 | +    integer,intent(out) :: error_cnt !! error counter | 
|  | 25 | + | 
|  | 26 | +    character(kind=CK,len=*),parameter :: str = CK_'{"bad_reals": [1.0, "NaN", "+Infinity", "-Infinity", 4.0]}' | 
|  | 27 | + | 
|  | 28 | +    real(rk),dimension(:),allocatable :: bad_reals | 
|  | 29 | +    logical(lk) :: found | 
|  | 30 | + | 
|  | 31 | +    write(error_unit,'(A)') '' | 
|  | 32 | +    write(error_unit,'(A)') '=================================' | 
|  | 33 | +    write(error_unit,'(A)') '   TEST 42' | 
|  | 34 | +    write(error_unit,'(A)') '=================================' | 
|  | 35 | +    write(error_unit,'(A)') '' | 
|  | 36 | + | 
|  | 37 | +    error_cnt = 0 | 
|  | 38 | + | 
|  | 39 | +    ! parse the json string: | 
|  | 40 | +    write(error_unit,'(A)') '' | 
|  | 41 | +    write(error_unit,'(A)') 'parsing string... ' | 
|  | 42 | +    call json%load_from_string(str) | 
|  | 43 | +    if (json%failed()) then | 
|  | 44 | +        call json%print_error_message(error_unit) | 
|  | 45 | +        error_cnt = error_cnt + 1 | 
|  | 46 | +    end if | 
|  | 47 | +    write(error_unit,'(A)') '' | 
|  | 48 | +    write(error_unit,'(A)') 'printing...' | 
|  | 49 | +    call json%print_file(int(error_unit,IK)) | 
|  | 50 | + | 
|  | 51 | +    write(error_unit,'(A)') '' | 
|  | 52 | +    write(error_unit,'(A)') 'get values as real...' | 
|  | 53 | +    call json%get('bad_reals',bad_reals,found) | 
|  | 54 | + | 
|  | 55 | +    if (json%failed()) then    !if there was an error reading the file | 
|  | 56 | + | 
|  | 57 | +        call json%print_error_message(error_unit) | 
|  | 58 | +        error_cnt = error_cnt + 1 | 
|  | 59 | + | 
|  | 60 | +    else | 
|  | 61 | + | 
|  | 62 | +        write(error_unit,'(A)') 'printing...' | 
|  | 63 | +        write(error_unit,*) bad_reals | 
|  | 64 | +        write(error_unit,'(A)') '' | 
|  | 65 | + | 
|  | 66 | +    end if | 
|  | 67 | + | 
|  | 68 | +    call json%destroy() | 
|  | 69 | + | 
|  | 70 | +    write(error_unit,'(A)') '' | 
|  | 71 | +    write(error_unit,'(A)') 'now add back as a real...' | 
|  | 72 | +    call json%add('bad_reals', bad_reals) | 
|  | 73 | +    call json%print_file(int(error_unit,IK)) | 
|  | 74 | +    write(error_unit,'(A)') '' | 
|  | 75 | + | 
|  | 76 | +    if (json%failed()) then | 
|  | 77 | +        call json%print_error_message(error_unit) | 
|  | 78 | +        error_cnt = error_cnt + 1 | 
|  | 79 | +    end if | 
|  | 80 | + | 
|  | 81 | +    if (error_cnt==0) then | 
|  | 82 | +        write(error_unit,'(A)') 'Success!' | 
|  | 83 | +    else | 
|  | 84 | +        write(error_unit,'(A)') 'Failed!' | 
|  | 85 | +    end if | 
|  | 86 | + | 
|  | 87 | +    end subroutine test_42 | 
|  | 88 | + | 
|  | 89 | +end module jf_test_42_mod | 
|  | 90 | +!***************************************************************************************** | 
|  | 91 | + | 
|  | 92 | +#ifndef INTEGRATED_TESTS | 
|  | 93 | +!***************************************************************************************** | 
|  | 94 | +program jf_test_42 | 
|  | 95 | + | 
|  | 96 | +    !! 42nd unit test. | 
|  | 97 | + | 
|  | 98 | +    use jf_test_42_mod , only: test_42 | 
|  | 99 | +    implicit none | 
|  | 100 | +    integer :: n_errors | 
|  | 101 | +    n_errors = 0 | 
|  | 102 | +    call test_42(n_errors) | 
|  | 103 | +    if (n_errors /= 0) stop 1 | 
|  | 104 | + | 
|  | 105 | +end program jf_test_42 | 
|  | 106 | +!***************************************************************************************** | 
|  | 107 | +#endif | 
0 commit comments