Reader unittests now construct Reader from a buffer.

This commit is contained in:
Ferdinand Majerech 2014-07-31 02:28:42 +02:00
parent e100047572
commit a74bc8cf3b

View file

@ -768,13 +768,12 @@ bool isPrintableValidUTF8(const char[] chars) @safe pure nothrow @nogc
// Unittests. // Unittests.
import std.stream;
void testEndian(R)() void testEndian(R)()
{ {
writeln(typeid(R).toString() ~ ": endian unittest"); writeln(typeid(R).toString() ~ ": endian unittest");
void endian_test(ubyte[] data, Encoding encoding_expected, Endian endian_expected) void endian_test(ubyte[] data, Encoding encoding_expected, Endian endian_expected)
{ {
auto reader = new R(new MemoryStream(data)); auto reader = new R(data);
assert(reader.encoding == encoding_expected); assert(reader.encoding == encoding_expected);
assert(reader.endian_ == endian_expected); assert(reader.endian_ == endian_expected);
} }
@ -786,9 +785,10 @@ void testEndian(R)()
void testPeekPrefixForward(R)() void testPeekPrefixForward(R)()
{ {
import std.stream;
writeln(typeid(R).toString() ~ ": peek/prefix/forward unittest"); writeln(typeid(R).toString() ~ ": peek/prefix/forward unittest");
ubyte[] data = ByteOrderMarks[BOM.UTF8] ~ cast(ubyte[])"data"; ubyte[] data = ByteOrderMarks[BOM.UTF8] ~ cast(ubyte[])"data";
auto reader = new R(new MemoryStream(data)); auto reader = new R(data);
assert(reader.peek() == 'd'); assert(reader.peek() == 'd');
assert(reader.peek(1) == 'a'); assert(reader.peek(1) == 'a');
assert(reader.peek(2) == 't'); assert(reader.peek(2) == 't');
@ -803,13 +803,14 @@ void testPeekPrefixForward(R)()
void testUTF(R)() void testUTF(R)()
{ {
import std.stream;
writeln(typeid(R).toString() ~ ": UTF formats unittest"); writeln(typeid(R).toString() ~ ": UTF formats unittest");
dchar[] data = cast(dchar[])"data"; dchar[] data = cast(dchar[])"data";
void utf_test(T)(T[] data, BOM bom) void utf_test(T)(T[] data, BOM bom)
{ {
ubyte[] bytes = ByteOrderMarks[bom] ~ ubyte[] bytes = ByteOrderMarks[bom] ~
(cast(ubyte*)data.ptr)[0 .. data.length * T.sizeof]; (cast(ubyte[])data)[0 .. data.length * T.sizeof];
auto reader = new R(new MemoryStream(bytes)); auto reader = new R(bytes);
assert(reader.peek() == 'd'); assert(reader.peek() == 'd');
assert(reader.peek(1) == 'a'); assert(reader.peek(1) == 'a');
assert(reader.peek(2) == 't'); assert(reader.peek(2) == 't');
@ -825,7 +826,7 @@ void test1Byte(R)()
writeln(typeid(R).toString() ~ ": 1 byte file unittest"); writeln(typeid(R).toString() ~ ": 1 byte file unittest");
ubyte[] data = [97]; ubyte[] data = [97];
auto reader = new R(new MemoryStream(data)); auto reader = new R(data);
assert(reader.peek() == 'a'); assert(reader.peek() == 'a');
assert(reader.peek(1) == '\0'); assert(reader.peek(1) == '\0');
// assert(collectException(reader.peek(2))); // assert(collectException(reader.peek(2)));