remove Dumper.emit() and Loader.scan() (#239)

remove Dumper.emit() and Loader.scan()
merged-on-behalf-of: Basile-z <Basile-z@users.noreply.github.com>
This commit is contained in:
Cameron Ross 2019-03-18 03:40:47 -02:30 committed by The Dlang Bot
parent dcb4dcb93a
commit 8a31826124
4 changed files with 37 additions and 58 deletions

View file

@ -166,33 +166,6 @@ struct Dumper
~ name ~ " : " ~ e.msg, e.file, e.line);
}
}
package:
/*
* Emit specified events. Used for debugging/testing.
*
* Params: events = Events to emit.
*
* Throws: YAMLException if unable to emit.
*/
void emit(CharacterType = char, Range, T)(Range range, T events) @safe
if (isInputRange!T && is(ElementType!T == Event) &&
isOutputRange!(Range, char) || isOutputRange!(Range, wchar) || isOutputRange!(Range, dchar))
{
try
{
auto emitter = Emitter!(Range, CharacterType)(range, canonical, indent_, textWidth, lineBreak);
foreach(ref event; events)
{
emitter.emit(event);
}
}
catch(YAMLException e)
{
throw new YAMLException("Unable to emit YAML to stream "
~ name ~ " : " ~ e.msg, e.file, e.line);
}
}
}
///Write to a file
@safe unittest

View file

@ -246,24 +246,6 @@ struct Loader
}
return currentNode;
}
// Scan and return all tokens. Used for debugging.
const(Token)[] scan() @safe
{
try
{
const(Token)[] result;
foreach (token; scanner_)
{
result ~= token;
}
return result;
}
catch(YAMLException e)
{
throw new YAMLException("Unable to scan YAML from stream " ~
name_ ~ " : " ~ e.msg, e.file, e.line);
}
}
// Scan all tokens, throwing them away. Used for benchmarking.
void scanBench() @safe

View file

@ -15,11 +15,21 @@ import std.file;
import std.range;
import std.typecons;
import dyaml.dumper;
import dyaml.emitter;
import dyaml.event;
import dyaml.test.common;
import dyaml.token;
// Try to emit an event range.
void emitTestCommon(T)(ref Appender!string emitStream, T events, bool canonical = false) @safe
if (isInputRange!T && is(ElementType!T == Event))
{
auto emitter = Emitter!(typeof(emitStream), char)(emitStream, canonical, 2, 80, LineBreak.unix);
foreach(ref event; events)
{
emitter.emit(event);
}
}
/// Determine if events in events1 are equivalent to events in events2.
///
@ -78,8 +88,8 @@ void testEmitterOnData(string dataFilename, string canonicalFilename) @safe
//Must exist due to Anchor, Tags reference counts.
auto loader = Loader.fromFile(dataFilename);
auto events = loader.parse();
auto emitStream = new Appender!string;
dumper().emit(emitStream, events);
auto emitStream = Appender!string();
emitTestCommon(emitStream, events);
static if(verbose)
{
@ -106,10 +116,8 @@ void testEmitterOnCanonical(string canonicalFilename) @safe
auto events = loader.parse();
foreach(canonical; [false, true])
{
auto emitStream = new Appender!string;
auto dumper = dumper();
dumper.canonical = canonical;
dumper.emit(emitStream, events);
auto emitStream = Appender!string();
emitTestCommon(emitStream, events, canonical);
static if(verbose)
{
writeln("OUTPUT (canonical=", canonical, "):\n",
@ -163,8 +171,8 @@ void testEmitterStyles(string dataFilename, string canonicalFilename) @safe
}
styledEvents ~= event;
}
auto emitStream = new Appender!string;
dumper().emit(emitStream, styledEvents);
auto emitStream = Appender!string();
emitTestCommon(emitStream, styledEvents);
static if(verbose)
{
writeln("OUTPUT (", filename, ", ", to!string(flowStyle), ", ",

View file

@ -14,8 +14,23 @@ import std.array;
import std.file;
import dyaml.test.common;
import dyaml.reader;
import dyaml.scanner;
import dyaml.token;
// Read and scan a YAML doc, returning the tokens.
const(Token)[] scanTestCommon(string filename) @safe
{
ubyte[] yamlData;
() @trusted { yamlData = cast(ubyte[])std.file.read(filename); }();
auto scanner = Scanner(new Reader(yamlData));
const(Token)[] result;
foreach (token; scanner)
{
result ~= token;
}
return result;
}
/**
* Test tokens output by scanner.
@ -54,8 +69,7 @@ void testTokens(string dataFilename, string tokensFilename) @safe
static if(verbose){writeln("tokens1: ", tokens1, "\ntokens2: ", tokens2);}
}
auto loader = Loader.fromFile(dataFilename);
foreach(token; loader.scan())
foreach(token; scanTestCommon(dataFilename))
{
if(token.id != TokenID.streamStart && token.id != TokenID.streamEnd)
{
@ -81,8 +95,10 @@ void testScanner(string dataFilename, string canonicalFilename) @safe
{
static if(verbose){writeln(tokens);}
}
auto loader = Loader.fromFile(filename);
foreach(ref token; loader.scan()){tokens ~= to!string(token.id);}
foreach(ref token; scanTestCommon(filename))
{
tokens ~= to!string(token.id);
}
}
}