Skip to content

Commit

Permalink
std.stdio: add unittest examples to doc output
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Mar 13, 2016
1 parent 35a2a56 commit afe493d
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions std/stdio.d
Expand Up @@ -832,21 +832,19 @@ $(D rawRead) always reads in binary mode on Windows.
return buffer;
}

///
unittest
{
static import std.file;

auto deleteme = testFilename();
std.file.write(deleteme, "\r\n\n\r\n");
scope(exit) std.file.remove(deleteme);
auto f = File(deleteme, "r");
auto testFile = testFilename();
std.file.write(testFile, "\r\n\n\r\n");
scope(exit) std.file.remove(testFile);

auto f = File(testFile, "r");
auto buf = f.rawRead(new char[5]);
f.close();
assert(buf == "\r\n\n\r\n");
/+
buf = stdin.rawRead(new char[5]);
assert(buf == "\r\n\n\r\n");
+/
}

/**
Expand Down Expand Up @@ -890,16 +888,18 @@ Throws: $(D ErrnoException) if the file is not opened or if the call to $(D fwri
_name, "'"));
}

///
unittest
{
static import std.file;

auto deleteme = testFilename();
auto f = File(deleteme, "w");
scope(exit) std.file.remove(deleteme);
auto testFile = testFilename();
auto f = File(testFile, "w");
scope(exit) std.file.remove(testFile);

f.rawWrite("\r\n\n\r\n");
f.close();
assert(std.file.read(deleteme) == "\r\n\n\r\n");
assert(std.file.read(testFile) == "\r\n\n\r\n");
}

/**
Expand Down Expand Up @@ -987,15 +987,17 @@ Throws: $(D Exception) if the file is not opened.
return result;
}

///
unittest
{
static import std.file;
import std.conv : text;

auto deleteme = testFilename();
std.file.write(deleteme, "abcdefghijklmnopqrstuvwqxyz");
scope(exit) { std.file.remove(deleteme); }
auto f = File(deleteme);
auto testFile = testFilename();
std.file.write(testFile, "abcdefghijklmnopqrstuvwqxyz");
scope(exit) { std.file.remove(testFile); }

auto f = File(testFile);
auto a = new ubyte[4];
f.rawRead(a);
assert(f.tell == 4, text(f.tell));
Expand Down Expand Up @@ -1661,6 +1663,7 @@ is recommended if you want to process a complete file.
return formattedRead(input, format, data);
}

///
unittest
{
static import std.file;
Expand Down

0 comments on commit afe493d

Please sign in to comment.