1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#:include "common.fypp"
! SPDX-Identifier: MIT
module test_string_assignment
use testdrive, only : new_unittest, unittest_type, error_type, check
use stdlib_kinds, only : int8, int16, int32, int64, lk, c_bool
use stdlib_string_type, only : string_type, assignment(=), operator(==), len
implicit none
contains
!> Collect all exported unit tests
subroutine collect_string_assignment(testsuite)
!> Collection of tests
type(unittest_type), allocatable, intent(out) :: testsuite(:)
testsuite = [ &
new_unittest("assignment", test_assignment), &
new_unittest("constructor", test_constructor) &
]
end subroutine collect_string_assignment
subroutine test_assignment(error)
!> Error handling
type(error_type), allocatable, intent(out) :: error
type(string_type) :: string
call check(error, len(string) == 0)
if (allocated(error)) return
string = "Sequence"
call check(error, len(string) == 8)
end subroutine test_assignment
subroutine test_constructor(error)
!> Error handling
type(error_type), allocatable, intent(out) :: error
character(len=128) :: flc
write(flc, '(g0)') -1026191
call check(error, string_type(-1026191) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') 124787
call check(error, string_type(124787) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') -2_int8
call check(error, string_type(-2_int8) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') 5_int8
call check(error, string_type(5_int8) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') -72_int16
call check(error, string_type(-72_int16) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') -8924889_int32
call check(error, string_type(-8924889_int32) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') 2378405_int32
call check(error, string_type(2378405_int32) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') 921092378411_int64
call check(error, string_type(921092378411_int64) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') -1272835761_int64
call check(error, string_type(-1272835761_int64) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') .true.
call check(error, string_type(.true.) == trim(flc))
if (allocated(error)) return
write(flc, '(g0)') .false.
call check(error, string_type(.false.) == trim(flc))
if (allocated(error)) return
#:if WITH_CBOOL
write(flc, '(g0)') .false._c_bool
call check(error, string_type(.false._c_bool) == trim(flc))
if (allocated(error)) return
#:endif
write(flc, '(g0)') .true._lk
call check(error, string_type(.true._lk) == trim(flc))
end subroutine test_constructor
end module test_string_assignment
program tester
use, intrinsic :: iso_fortran_env, only : error_unit
use testdrive, only : run_testsuite, new_testsuite, testsuite_type
use test_string_assignment, only : collect_string_assignment
implicit none
integer :: stat, is
type(testsuite_type), allocatable :: testsuites(:)
character(len=*), parameter :: fmt = '("#", *(1x, a))'
stat = 0
testsuites = [ &
new_testsuite("string-assignment", collect_string_assignment) &
]
do is = 1, size(testsuites)
write(error_unit, fmt) "Testing:", testsuites(is)%name
call run_testsuite(testsuites(is)%collect, error_unit, stat)
end do
if (stat > 0) then
write(error_unit, '(i0, 1x, a)') stat, "test(s) failed!"
error stop
end if
end program
|