Skip to content

Commit b0b3dbf

Browse files
committed
Add tests for parse_mode()
1 parent 041a4e1 commit b0b3dbf

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/stdlib_experimental_io.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@ module stdlib_experimental_io
33
use stdlib_experimental_error, only: error_stop
44
implicit none
55
private
6+
! Public API
67
public :: loadtxt, savetxt, open
78

9+
! Private API that is exposed so that we can test it in tests
10+
public :: parse_mode
11+
12+
813
interface loadtxt
914
module procedure sloadtxt
1015
module procedure dloadtxt

src/tests/io/test_open.f90

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
program test_open
2-
use stdlib_experimental_io, only: open
2+
use stdlib_experimental_io, only: open, parse_mode
33
use stdlib_experimental_error, only: assert
44
implicit none
55

66
character(:), allocatable :: filename
77
integer :: u, a(3)
88

9+
call test_parse_mode()
10+
911
! Text file
1012
filename = get_outpath() // "/io_open.dat"
1113

@@ -73,4 +75,45 @@ function get_outpath() result(outpath)
7375
endif
7476
end function get_outpath
7577

78+
subroutine test_parse_mode()
79+
character(3) :: m
80+
m = parse_mode("")
81+
call assert(m == "r t")
82+
83+
m = parse_mode("r")
84+
call assert(m == "r t")
85+
m = parse_mode("w")
86+
call assert(m == "w t")
87+
m = parse_mode("a")
88+
call assert(m == "a t")
89+
90+
m = parse_mode("rb")
91+
call assert(m == "r b")
92+
m = parse_mode("wb")
93+
call assert(m == "w b")
94+
m = parse_mode("ab")
95+
call assert(m == "a b")
96+
97+
m = parse_mode("br")
98+
!call assert(m == "r b")
99+
m = parse_mode("bw")
100+
!call assert(m == "w b")
101+
m = parse_mode("ba")
102+
!call assert(m == "a b")
103+
104+
m = parse_mode("r+")
105+
call assert(m == "r+t")
106+
m = parse_mode("w+")
107+
call assert(m == "w+t")
108+
m = parse_mode("a+")
109+
call assert(m == "a+t")
110+
111+
m = parse_mode("r+b")
112+
call assert(m == "r+b")
113+
m = parse_mode("w+b")
114+
call assert(m == "w+b")
115+
m = parse_mode("a+b")
116+
call assert(m == "a+b")
117+
end subroutine
118+
76119
end program

0 commit comments

Comments
 (0)