Is there a File-like object for unit tests?
Amit
a at a.a
Tue Jan 4 17:01:41 UTC 2022
Hi!
I wrote a text parser that takes a File argument and parses that
file's contents. Now I would like to write a unit-test for that
parser. I need a File (or a general IO interface) that reads from
an in-memory buffer, similar to python's `StringIO` or go's
`strings.Reader`.
How can I achieve that?
Example of what I have in mind:
```d
unittest {
string fakeContents = "foo\nbar\nbaz";
File f = createFileFromString(fakeContents);
assert(myParse(f) == MyParsedObject(...));
}
```
More information about the Digitalmars-d-learn
mailing list