File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ struct Loader
165165 void name (string name) pure @safe nothrow @nogc
166166 {
167167 name_ = name;
168+ scanner_.name = name;
168169 }
169170
170171 // / Specify custom Resolver to use.
@@ -392,3 +393,19 @@ struct Loader
392393 auto doc = Loader.fromString(yaml).load();
393394 assert (doc.isValid);
394395}
396+
397+ @safe unittest
398+ {
399+ import std.exception : collectException;
400+
401+ auto yaml = q" EOS
402+ value: invalid: string
403+ EOS" ;
404+ auto filename = " invalid.yml" ;
405+ auto loader = Loader.fromString(yaml);
406+ loader.name = filename;
407+
408+ Node unused;
409+ auto e = loader.load().collectException! ScannerException(unused);
410+ assert (e.mark.name == filename);
411+ }
Original file line number Diff line number Diff line change @@ -405,6 +405,9 @@ final class Reader
405405 // / Get file name.
406406 string name () const @safe pure nothrow @nogc { return name_; }
407407
408+ // / Set file name.
409+ void name (string name) pure @safe nothrow @nogc { name_ = name; }
410+
408411 // / Get current line number.
409412 uint line () const @safe pure nothrow @nogc { return line_; }
410413
Original file line number Diff line number Diff line change @@ -185,6 +185,12 @@ struct Scanner
185185 return tokens_.empty;
186186 }
187187
188+ // / Set file name.
189+ void name (string name) @safe pure nothrow @nogc
190+ {
191+ reader_.name = name;
192+ }
193+
188194 private :
189195 // / Most scanning error messages have the same format; so build them with this
190196 // / function.
You can’t perform that action at this time.
0 commit comments