-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #606
- Loading branch information
Showing
15 changed files
with
122 additions
and
51 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const std = @import("index.zig"); | ||
const io = std.io; | ||
const allocator = std.debug.global_allocator; | ||
const Rand = std.rand.Rand; | ||
const assert = std.debug.assert; | ||
const mem = std.mem; | ||
const os = std.os; | ||
|
||
test "write a file, read it, then delete it" { | ||
var data: [1024]u8 = undefined; | ||
var rng = Rand.init(1234); | ||
rng.fillBytes(data[0..]); | ||
const tmp_file_name = "temp_test_file.txt"; | ||
{ | ||
var file = %%io.File.openWrite(tmp_file_name, allocator); | ||
defer file.close(); | ||
|
||
var file_out_stream = io.FileOutStream.init(&file); | ||
var buf_stream = io.BufferedOutStream.init(&file_out_stream.stream); | ||
const st = &buf_stream.stream; | ||
%%st.print("begin"); | ||
%%st.write(data[0..]); | ||
%%st.print("end"); | ||
%%buf_stream.flush(); | ||
} | ||
{ | ||
var file = %%io.File.openRead(tmp_file_name, allocator); | ||
defer file.close(); | ||
|
||
const file_size = %%file.getEndPos(); | ||
const expected_file_size = "begin".len + data.len + "end".len; | ||
assert(file_size == expected_file_size); | ||
|
||
var file_in_stream = io.FileInStream.init(&file); | ||
var buf_stream = io.BufferedInStream.init(&file_in_stream.stream); | ||
const st = &buf_stream.stream; | ||
const contents = %%st.readAllAlloc(allocator, 2 * 1024); | ||
defer allocator.free(contents); | ||
|
||
assert(mem.eql(u8, contents[0.."begin".len], "begin")); | ||
assert(mem.eql(u8, contents["begin".len..contents.len - "end".len], data)); | ||
assert(mem.eql(u8, contents[contents.len - "end".len ..], "end")); | ||
} | ||
%%os.deleteFile(allocator, tmp_file_name); | ||
} |
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
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