Skip to content

Commit

Permalink
Merge pull request #2711 from 9il/format
Browse files Browse the repository at this point in the history
std.format: clean imports
  • Loading branch information
H. S. Teoh committed Nov 14, 2014
2 parents 6dde55f + 4725f89 commit 0e4966b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion std/format.d
Expand Up @@ -25,7 +25,10 @@ module std.format;
//debug=format; // uncomment to turn on debugging printf's

import core.vararg;
import std.exception, std.range, std.traits, std.typetuple;
import std.exception;
import std.range.constraints;
import std.traits;
import std.typetuple;

version(unittest)
{
Expand Down Expand Up @@ -530,6 +533,7 @@ uint formattedWrite(Writer, Char, A...)(Writer w, in Char[] fmt, A args)

@safe pure unittest
{
import std.array;
auto w = appender!string();
formattedWrite(w, "%s %d", "@safe/pure", 42);
assert(w.data == "@safe/pure 42");
Expand Down Expand Up @@ -827,6 +831,7 @@ struct FormatSpec(Char)

unittest
{
import std.array;
auto w = appender!(char[])();
auto f = FormatSpec("abc%sdef%sghi");
f.writeUpToNextSpec(w);
Expand Down Expand Up @@ -1114,6 +1119,7 @@ struct FormatSpec(Char)

private string getCurFmtStr() const
{
import std.array : appender;
auto w = appender!string();
auto f = FormatSpec!Char("%s"); // for stringnize

Expand Down Expand Up @@ -1142,6 +1148,7 @@ struct FormatSpec(Char)
unittest
{
// issue 5237
import std.array;
auto w = appender!string();
auto f = FormatSpec!char("%.16f");
f.writeUpToNextSpec(w); // dummy eating
Expand All @@ -1152,6 +1159,7 @@ struct FormatSpec(Char)

private const(Char)[] headUpToNextSpec()
{
import std.array : appender;
auto w = appender!(typeof(return))();
auto tr = trailing;

Expand Down Expand Up @@ -1196,6 +1204,7 @@ struct FormatSpec(Char)
@safe pure unittest
{
//Test the example
import std.array;
auto a = appender!(string)();
auto fmt = "Number: %2.4e\nString: %s";
auto f = FormatSpec!char(fmt);
Expand Down Expand Up @@ -1931,6 +1940,7 @@ if (is(StaticArrayTypeOf!T) && !is(T == enum) && !hasToString!(T, Char))

unittest // Test for issue 8310
{
import std.array : appender;
FormatSpec!char f;
auto w = appender!string();

Expand Down Expand Up @@ -2356,6 +2366,7 @@ void formatElement(Writer, T, Char)(Writer w, T val, ref FormatSpec!Char f)
if (is(StringTypeOf!T) && !is(T == enum))
{
import std.utf : UTFException;
import std.array : appender;

StringTypeOf!T str = val; // bug 8015

Expand Down Expand Up @@ -2768,6 +2779,8 @@ unittest

unittest
{
import std.array : appender;
import std.range.interfaces;
// class range (issue 5154)
auto c = inputRangeObject([1,2,3,4]);
formatTest( c, "[1, 2, 3, 4]" );
Expand Down Expand Up @@ -2868,6 +2881,7 @@ if (is(T == interface) && (hasToString!(T, Char) || !is(BuiltinTypeOf!T)) && !is
unittest
{
// interface
import std.range.interfaces;
InputRange!int i = inputRangeObject([1,2,3,4]);
formatTest( i, "[1, 2, 3, 4]" );
assert(i.empty);
Expand Down Expand Up @@ -2999,6 +3013,7 @@ unittest

unittest
{
import std.array;
// 7230
static struct Bug7230
{
Expand All @@ -3022,6 +3037,7 @@ unittest

unittest
{
import std.array;
static struct S{ @disable this(this); }
S s;

Expand Down Expand Up @@ -3130,6 +3146,7 @@ if (isPointer!T && !is(T == enum) && !hasToString!(T, Char))
@safe pure unittest
{
// pointer
import std.range;
auto r = retro([1,2,3,4]);
auto p = ()@trusted{ auto p = &r; return p; }();
formatTest( p, "[4, 3, 2, 1]" );
Expand Down Expand Up @@ -3294,6 +3311,7 @@ private int getNthInt(A...)(uint index, A args)
version(unittest)
void formatTest(T)(T val, string expected, size_t ln = __LINE__, string fn = __FILE__)
{
import std.array : appender;
import std.conv : text;
FormatSpec!char f;
auto w = appender!string();
Expand All @@ -3306,6 +3324,7 @@ void formatTest(T)(T val, string expected, size_t ln = __LINE__, string fn = __F
version(unittest)
void formatTest(T)(string fmt, T val, string expected, size_t ln = __LINE__, string fn = __FILE__)
{
import std.array : appender;
import std.conv : text;
auto w = appender!string();
formattedWrite(w, fmt, val);
Expand All @@ -3318,6 +3337,7 @@ version(unittest)
void formatTest(T)(T val, string[] expected, size_t ln = __LINE__, string fn = __FILE__)
{
import std.conv : text;
import std.array : appender;
FormatSpec!char f;
auto w = appender!string();
formatValue(w, val, f);
Expand All @@ -3334,6 +3354,7 @@ version(unittest)
void formatTest(T)(string fmt, T val, string[] expected, size_t ln = __LINE__, string fn = __FILE__)
{
import std.conv : text;
import std.array : appender;
auto w = appender!string();
formattedWrite(w, fmt, val);
foreach(cur; expected)
Expand All @@ -3348,6 +3369,7 @@ void formatTest(T)(string fmt, T val, string[] expected, size_t ln = __LINE__, s
unittest
{
import std.algorithm;
import std.array;
auto stream = appender!string();
formattedWrite(stream, "%s", 1.1);
assert(stream.data == "1.1", stream.data);
Expand All @@ -3365,6 +3387,7 @@ unittest

unittest
{
import std.array;
auto stream = appender!string();
formattedWrite(stream, "%u", 42);
assert(stream.data == "42", stream.data);
Expand All @@ -3373,6 +3396,7 @@ unittest
unittest
{
// testing raw writes
import std.array;
auto w = appender!(char[])();
uint a = 0x02030405;
formattedWrite(w, "%+r", a);
Expand All @@ -3387,6 +3411,7 @@ unittest
unittest
{
// testing positional parameters
import std.array;
auto w = appender!(char[])();
formattedWrite(w,
"Numbers %2$s and %1$s are reversed and %1$s%2$s repeated",
Expand All @@ -3404,6 +3429,7 @@ unittest
unittest
{
import std.conv : text, octal;
import std.array;

debug(format) printf("std.format.format.unittest\n");

Expand Down Expand Up @@ -3872,6 +3898,8 @@ here:

unittest
{
import std.array;

immutable(char[5])[int] aa = ([3:"hello", 4:"betty"]);
if (false) writeln(aa.keys);
assert(aa[3] == "hello");
Expand Down Expand Up @@ -3923,6 +3951,7 @@ unittest
version(unittest)
void formatReflectTest(T)(ref T val, string fmt, string formatted, string fn = __FILE__, size_t ln = __LINE__)
{
import std.array : appender;
auto w = appender!string();
formattedWrite(w, fmt, val);

Expand Down Expand Up @@ -3963,6 +3992,7 @@ void formatReflectTest(T)(ref T val, string fmt, string formatted, string fn = _
version(unittest)
void formatReflectTest(T)(ref T val, string fmt, string[] formatted, string fn = __FILE__, size_t ln = __LINE__)
{
import std.array : appender;
auto w = appender!string();
formattedWrite(w, fmt, val);

Expand Down Expand Up @@ -4362,7 +4392,10 @@ T unformatValue(T, Range, Char)(ref Range input, ref FormatSpec!Char spec)
auto app = result[];
}
else
{
import std.array : appender;
auto app = appender!T();
}
if (spec.trailing.empty)
{
for (; !input.empty; input.popFront())
Expand Down Expand Up @@ -6290,6 +6323,7 @@ unittest
unittest
{
// bugzilla 3479
import std.array;
auto stream = appender!(char[])();
formattedWrite(stream, "%2$.*1$d", 12, 10);
assert(stream.data == "000000000010", stream.data);
Expand All @@ -6298,6 +6332,7 @@ unittest
unittest
{
// bug 6893
import std.array;
enum E : ulong { A, B, C }
auto stream = appender!(char[])();
formattedWrite(stream, "%s", E.C);
Expand Down

0 comments on commit 0e4966b

Please sign in to comment.