it compiles at the tests run without segfault

I call this a first step
This commit is contained in:
Robert burner Schadek 2016-03-17 00:55:57 +01:00
parent daf1a0064f
commit 41133e3b0d
5 changed files with 47 additions and 6 deletions

View file

@ -253,7 +253,7 @@ struct Emitter
stream_.writeExact(buffer.ptr, buffer.length * dchar.sizeof); stream_.writeExact(buffer.ptr, buffer.length * dchar.sizeof);
break; break;
} }
catch(WriteException e) catch(Exception e)
{ {
throw new Error("Unable to write to stream: " ~ e.msg); throw new Error("Unable to write to stream: " ~ e.msg);
} }

View file

@ -993,7 +993,7 @@ void testEndian(R)()
void testPeekPrefixForward(R)() void testPeekPrefixForward(R)()
{ {
import std.stream; import dyaml.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(data); auto reader = new R(data);
@ -1011,7 +1011,7 @@ void testPeekPrefixForward(R)()
void testUTF(R)() void testUTF(R)()
{ {
import std.stream; import dyaml.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)

View file

@ -1,8 +1,35 @@
module dyaml.stream; module dyaml.stream;
enum BOM {
UTF8, /// UTF-8
UTF16LE, /// UTF-16 Little Endian
UTF16BE, /// UTF-16 Big Endian
UTF32LE, /// UTF-32 Little Endian
UTF32BE, /// UTF-32 Big Endian
}
import std.system;
private enum int NBOMS = 5;
immutable Endian[NBOMS] BOMEndian =
[ std.system.endian,
Endian.littleEndian, Endian.bigEndian,
Endian.littleEndian, Endian.bigEndian
];
immutable ubyte[][NBOMS] ByteOrderMarks =
[ [0xEF, 0xBB, 0xBF],
[0xFF, 0xFE],
[0xFE, 0xFF],
[0xFF, 0xFE, 0x00, 0x00],
[0x00, 0x00, 0xFE, 0xFF]
];
interface YStream { interface YStream {
void writeExact(const void* buffer, size_t size); void writeExact(const void* buffer, size_t size);
size_t write(const(ubyte)[] buffer); size_t write(const(ubyte)[] buffer);
void flush();
@property bool writeable();
} }
class YMemoryStream : YStream { class YMemoryStream : YStream {
@ -16,6 +43,10 @@ class YMemoryStream : YStream {
data ~= buffer; data ~= buffer;
return buffer.length; return buffer.length;
} }
void flush() {}
@property bool writeable() { return true; }
} }
class YFile : YStream { class YFile : YStream {
@ -27,10 +58,17 @@ class YFile : YStream {
} }
void writeExact(const void* buffer, size_t size) { void writeExact(const void* buffer, size_t size) {
this.file.write(buffer[0 .. size]); this.file.write(cast(const ubyte[])buffer[0 .. size]);
} }
size_t write(const(ubyte)[] buffer) { size_t write(const(ubyte)[] buffer) {
this.file.write(buffer[0 .. size]); this.file.write(buffer);
return buffer.length;
} }
void flush() {
this.file.flush();
}
@property bool writeable() { return true; }
} }

View file

@ -15,6 +15,7 @@ import std.file;
import std.range; import std.range;
import std.typecons; import std.typecons;
import dyaml.stream;
import dyaml.dumper; import dyaml.dumper;
import dyaml.event; import dyaml.event;
import dyaml.testcommon; import dyaml.testcommon;

View file

@ -48,7 +48,9 @@ void testRepresenterTypes(bool verbose, string codeFilename)
} }
} }
auto emitStream = new MemoryStream; import dyaml.stream;
auto emitStream = new YMemoryStream;
auto representer = new Representer; auto representer = new Representer;
representer.addRepresenter!TestClass(&representClass); representer.addRepresenter!TestClass(&representClass);
representer.addRepresenter!TestStruct(&representStruct); representer.addRepresenter!TestStruct(&representStruct);