mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Improve documented example
This commit is contained in:
parent
e826c82e32
commit
65fcbbf16f
1 changed files with 3 additions and 8 deletions
11
std/base64.d
11
std/base64.d
|
@ -454,20 +454,15 @@ template Base64Impl(char Map62th, char Map63th, char Padding = '=')
|
|||
///
|
||||
@safe pure nothrow unittest
|
||||
{
|
||||
// @system because encode for OutputRange is @system
|
||||
struct OutputRange
|
||||
{
|
||||
char[] result;
|
||||
void put(const(char) ch) @safe { result ~= ch; }
|
||||
}
|
||||
import std.array : appender;
|
||||
|
||||
auto output = appender!string();
|
||||
ubyte[] data = [0x1a, 0x2b, 0x3c, 0x4d, 0x5d, 0x6e];
|
||||
|
||||
// This overload of encode() returns the number of calls to the output
|
||||
// range's put method.
|
||||
OutputRange output;
|
||||
assert(Base64.encode(data, output) == 8);
|
||||
assert(output.result == "Gis8TV1u");
|
||||
assert(output.data == "Gis8TV1u");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue