On Wednesday, 27 November 2024 at 02:43:21 UTC, Ali Çehreli wrote:
On 11/26/24 5:12 PM, Andy Valencia wrote:
Again and again for testing I run into how nice it would be to
have an open "File" which has its contents set by the unit
test code:
auto f = StringFile("my test data...", "r");
An earlier post by H. S. Teoh may be helpful:
https://forum.dlang.org/post/mailman.10192.1685482943.31357.digitalmar...@puremagic.com
Thank you. It's somewhat bemusing to, in essence, wrap the
entirety of an implementation around a #define just to slot in an
alternative to File. With my OO programming goggles on, I can't
help but notice that if Phobos had made File a class--or an
interface--then it would be possible through simple type
compatibility to have a FileFile instance which would satisfy the
File API using the filesystem, and as no special case have a
StringFile which did the same from the body of a string.
But I used your suggested approach, and it does indeed work
nicely. Thank you again.
Andy