-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement open(filename, mode) and use it #71
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ac61bf4
Implement open(filename, mode) and use it
certik c8a3fca
Implement mode="a"
certik d2d3bfa
Rename loadtxt test directory to io
certik 6a263ff
Add a test for "open"
certik ab5c469
Apply suggestions from code review
certik 13a668e
stdlib_experimental_io: addition of a parser and characters "+" and "…
jvdp1 2f1a0e8
test_open: addition of a test for stream files
jvdp1 576b4f7
Merge pull request #1 from jvdp1/opencertik
certik b5c14b4
Merge branch 'master' into open
certik 041a4e1
Clean test files
certik b0b3dbf
Add tests for parse_mode()
certik 08dc86b
Allow any order of characters in the mode
certik 5128458
Fix an out of bounds error
certik 48cbf24
Let parse_mode() set the default value
certik a98832c
Manual Makefiles: add a new dependency
certik 3ed454b
Merge branch 'master' into open
certik a8416a1
Use optval
certik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/tests/loadtxt/Makefile.manual → src/tests/io/Makefile.manual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
PROGS_SRC = test_loadtxt.f90 \ | ||
test_savetxt.f90 \ | ||
test_loadtxt_qp.f90 \ | ||
test_savetxt_qp.f90 | ||
test_savetxt_qp.f90 \ | ||
test_open.f90 | ||
|
||
CLEAN_FILES = tmp.dat tmp_qp.dat | ||
CLEAN_FILES = tmp.dat tmp_qp.dat io_open.dat io_open.stream | ||
|
||
|
||
include ../Makefile.manual.test.mk |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
program test_open | ||
use stdlib_experimental_io, only: open, parse_mode | ||
use stdlib_experimental_error, only: assert | ||
implicit none | ||
|
||
character(:), allocatable :: filename | ||
integer :: u, a(3) | ||
|
||
call test_parse_mode() | ||
|
||
! Text file | ||
filename = get_outpath() // "/io_open.dat" | ||
|
||
! Test mode "w" | ||
u = open(filename, "w") | ||
write(u, *) 1, 2, 3 | ||
close(u) | ||
|
||
! Test mode "r" | ||
u = open(filename, "r") | ||
read(u, *) a | ||
call assert(all(a == [1, 2, 3])) | ||
close(u) | ||
|
||
! Test mode "a" | ||
u = open(filename, "a") | ||
write(u, *) 4, 5, 6 | ||
close(u) | ||
u = open(filename, "r") | ||
read(u, *) a | ||
call assert(all(a == [1, 2, 3])) | ||
read(u, *) a | ||
call assert(all(a == [4, 5, 6])) | ||
close(u) | ||
|
||
|
||
|
||
! Stream file | ||
filename = get_outpath() // "/io_open.stream" | ||
|
||
! Test mode "w" | ||
u = open(filename, "wb") | ||
write(u) 1, 2, 3 | ||
close(u) | ||
|
||
! Test mode "r" | ||
u = open(filename, "rb") | ||
read(u) a | ||
call assert(all(a == [1, 2, 3])) | ||
close(u) | ||
|
||
! Test mode "a" | ||
u = open(filename, "ab") | ||
write(u) 4, 5, 6 | ||
close(u) | ||
u = open(filename, "rb") | ||
read(u) a | ||
call assert(all(a == [1, 2, 3])) | ||
read(u) a | ||
call assert(all(a == [4, 5, 6])) | ||
close(u) | ||
|
||
contains | ||
|
||
function get_outpath() result(outpath) | ||
integer :: ierr | ||
character(256) :: argv | ||
character(:), allocatable :: outpath | ||
|
||
call get_command_argument(1, argv, status=ierr) | ||
if (ierr==0) then | ||
outpath = trim(argv) | ||
else | ||
outpath = '.' | ||
endif | ||
end function get_outpath | ||
|
||
subroutine test_parse_mode() | ||
character(3) :: m | ||
m = parse_mode("") | ||
call assert(m == "r t") | ||
|
||
m = parse_mode("r") | ||
call assert(m == "r t") | ||
m = parse_mode("w") | ||
call assert(m == "w t") | ||
m = parse_mode("a") | ||
call assert(m == "a t") | ||
|
||
m = parse_mode("rb") | ||
call assert(m == "r b") | ||
m = parse_mode("wb") | ||
call assert(m == "w b") | ||
m = parse_mode("ab") | ||
call assert(m == "a b") | ||
|
||
m = parse_mode("br") | ||
call assert(m == "r b") | ||
m = parse_mode("bw") | ||
call assert(m == "w b") | ||
m = parse_mode("ba") | ||
call assert(m == "a b") | ||
|
||
m = parse_mode("r+") | ||
call assert(m == "r+t") | ||
m = parse_mode("w+") | ||
call assert(m == "w+t") | ||
m = parse_mode("a+") | ||
call assert(m == "a+t") | ||
|
||
m = parse_mode("r+b") | ||
call assert(m == "r+b") | ||
m = parse_mode("w+b") | ||
call assert(m == "w+b") | ||
m = parse_mode("a+b") | ||
call assert(m == "a+b") | ||
end subroutine | ||
|
||
end program |
File renamed without changes.
File renamed without changes.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is possible with CMake, but would it be possible to use some preprocessing (cpp?) for setting
parse_mode
public only for the tests?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. See also #75.