Skip to content

Commit

Permalink
Merge pull request #697 from 9rnsr/fix8386
Browse files Browse the repository at this point in the history
Issue 8386 - writeln stopped working with wstring
  • Loading branch information
andralex committed Jul 16, 2012
2 parents 534d44c + 07ec7ce commit 2a51ae0
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions std/stdio.d
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ void writeln(T...)(T args)
enforce(fputc('\n', .stdout.p.handle) == '\n');
}
else static if (T.length == 1 &&
isSomeString!(typeof(args[0])) &&
isSomeString!(typeof(args[0])) && is(typeof(args[0]) : const(char)[]) &&
!isAggregateType!(typeof(args[0])))
{
// Specialization for strings - a very frequent case
Expand Down Expand Up @@ -1610,8 +1610,9 @@ unittest

unittest
{
//printf("Entering test at line %d\n", __LINE__);
//printf("Entering test at line %d\n", __LINE__);
scope(failure) printf("Failed test at line %d\n", __LINE__);

// test writeln
auto deleteme = testFilename();
auto f = File(deleteme, "w");
Expand All @@ -1624,6 +1625,7 @@ unittest
else
assert(cast(char[]) std.file.read(deleteme) ==
"Hello, world number 42!\n");

// test writeln on stdout
auto saveStdout = stdout;
scope(exit) stdout = saveStdout;
Expand All @@ -1636,6 +1638,18 @@ unittest
else
assert(cast(char[]) std.file.read(deleteme) ==
"Hello, world number 42!\n");

stdout.open(deleteme, "w");
writeln("Hello!"c);
writeln("Hello!"w); // bug 8386
writeln("Hello!"d); // bug 8386
stdout.close();
version (Windows)
assert(cast(char[]) std.file.read(deleteme) ==
"Hello!\r\nHello!\r\nHello!\r\n");
else
assert(cast(char[]) std.file.read(deleteme) ==
"Hello!\nHello!\nHello!\n");
}

unittest
Expand Down

0 comments on commit 2a51ae0

Please sign in to comment.