summaryrefslogtreecommitdiff
path: root/libphobos/testsuite/libphobos.phobos/std_format_spec.d
blob: a24c4779b8b5c1ec5c35e13d834ed92d068762fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@safe pure unittest
{
    import std.format.spec;

    import std.array : appender;

    auto a = appender!(string)();
    auto fmt = "Number: %6.4e\nString: %s";
    auto f = FormatSpec!char(fmt);

    assert(f.writeUpToNextSpec(a));

    assert(a.data == "Number: ");
    assert(f.trailing == "\nString: %s");
    assert(f.spec == 'e');
    assert(f.width == 6);
    assert(f.precision == 4);

    assert(f.writeUpToNextSpec(a));

    assert(a.data == "Number: \nString: ");
    assert(f.trailing == "");
    assert(f.spec == 's');

    assert(!f.writeUpToNextSpec(a));

    assert(a.data == "Number: \nString: ");
}

@safe pure unittest
{
    import std.format.spec;

    import std.array : appender;
    import std.format.write : formatValue;

    auto spec = singleSpec("%10.3e");
    auto writer = appender!string();
    writer.formatValue(42.0, spec);

    assert(writer.data == " 4.200e+01");
}