Test_WriteYaml.pf Source File


This file depends on

sourcefile~~test_writeyaml.pf~~EfferentGraph sourcefile~test_writeyaml.pf Test_WriteYaml.pf sourcefile~esmf_hconfigutilities.f90 ESMF_HConfigUtilities.F90 sourcefile~test_writeyaml.pf->sourcefile~esmf_hconfigutilities.f90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~esmf_hconfigutilities.f90->sourcefile~errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~errorhandling.f90->sourcefile~mapl_throw.f90

Source Code

#include "MAPL_TestErr.h"
module Test_WriteYaml
   use funit
   use esmf
   use mapl3g_ESMF_HConfigUtilities, only: write(formatted)
   implicit none
   private

! Gfortran 12.3 cannot write DTIO to an interfal file apparently.
#ifndef __GFORTRAN__
   public :: test_write_scalar
   public :: test_write_sequence
   public :: test_write_mapping
   public :: test_write_kitchen_sink
#endif

contains

   @test(ifndef=__GFORTRAN__)
   subroutine test_write_scalar()
      type(ESMF_HConfig) :: hconfig
      character(10) :: buffer
      integer :: status
      character(:), allocatable :: content

      content = 'a'
      hconfig = ESMF_HConfigCreate(content=content, _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected=content, found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)

      content = 'aBc'
      hconfig = ESMF_HConfigCreate(content=content, _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected=content, found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)

      content = '3.14'
      hconfig = ESMF_HConfigCreate(content=content, _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected=content, found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)

   end subroutine test_write_scalar

   @test(ifndef=__GFORTRAN__)
   subroutine test_write_sequence()
      type(ESMF_HConfig) :: hconfig
      character(100) :: buffer
      integer :: status
      character(:), allocatable :: content

      content = '[]'
      hconfig = ESMF_HConfigCreate(content=content, _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected=content, found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)
      
      content = '[1, a, 3.14]'
      hconfig = ESMF_HConfigCreate(content=content, _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected=content, found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)

   end subroutine test_write_sequence

   @test(ifndef=__GFORTRAN__)
   subroutine test_write_mapping()
      type(ESMF_HConfig) :: hconfig
      character(100) :: buffer
      integer :: status
      
      hconfig = ESMF_HConfigCreate(content='{}', _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected='{}', found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)
      
      hconfig = ESMF_HConfigCreate(content='{a: b}', _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected='{a: b}', found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)

      hconfig = ESMF_HConfigCreate(content='{a: b, c: 1, d: 3.14, e: true}', _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected='{a: b, c: 1, d: 3.14, e: true}', found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)

   end subroutine test_write_mapping

   @test(ifndef=__GFORTRAN__)
   subroutine test_write_kitchen_sink()
      type(ESMF_HConfig) :: hconfig
      character(100) :: buffer
      integer :: status
      character(*), parameter :: CONTENT = '{a: [{b: 1, c: 2, d: [3, 4, e]}]}'
      hconfig = ESMF_HConfigCreate(content=CONTENT, _RC)
      write(buffer, *, iostat=status) hconfig
      _VERIFY(status)
      @assertEqual(expected=CONTENT, found=trim(buffer))
      call ESMF_HConfigDestroy(hconfig)
   end subroutine test_write_kitchen_sink

end module Test_WriteYaml