1 module ut.conv;
2 
3 import ut;
4 import nogc.conv;
5 
6 
7 @("text with multiple arguments")
8 @safe unittest {
9     const actual = () @safe @nogc nothrow { return text(1, " ", 2.0, " ", true); }();
10     actual.range.shouldEqual("1 2.000000 true");
11 }
12 
13 @("text with void[]")
14 @safe unittest {
15     void[] arg;
16     const actual = () @nogc nothrow { return text(arg); }();
17     actual.range.shouldEqual("[void]");
18 }
19 
20 @("toWStringz")
21 @safe unittest {
22     import std.conv: to;
23 
24     const str = "pokémon";
25     const exp = "pokémon".to!wstring;
26 
27     const act = () @nogc nothrow { return str.toWStringz(); }();
28     const slice = () @trusted @nogc { return act[0 .. 7]; }();
29     slice.shouldEqual("pokémon".to!wstring);
30 }
31 
32 @("text with at limit characters")
33 @safe unittest {
34     const actual = () @nogc nothrow { return text!4("foo"); }();
35     actual.range.shouldEqual("foo");
36 }
37 
38 @("text with 1 fewer char than needed")
39 @safe unittest {
40     const actual = () @nogc nothrow { return text!3("foo"); }();
41     actual.range.shouldEqual("fo");
42 }
43 
44 version(unitThreadedLight) {}
45 else {
46     @("text.bool")
47     @safe unittest {
48         text(false).range.should == "false";
49         text(true).range.should == "true";
50     }
51 }
52 
53 @("text.enum")
54 @safe @nogc unittest {
55     import std.algorithm: equal;
56     enum Enum { foo, bar, baz }
57     const actual = Enum.bar.text;
58     assert(equal(actual.range, "bar"));
59 }
60 
61 @("text.struct")
62 @safe @nogc unittest {
63     static struct Struct {
64         int i;
65         double d;
66     }
67 
68     const actual = Struct(2, 33.3).text;
69     debug actual.range.shouldEqual("Struct(2, 33.300000)");
70 }
71 
72 @("text.string")
73 @safe @nogc unittest {
74     const actual = "foobar".text;
75     debug actual.range.shouldEqual("foobar");
76 }
77 
78 
79 @("text.inputrange")
80 @safe @nogc unittest {
81     import std.range: only;
82     const actual = only(0, 1, 2, 3).text;
83     debug actual.range.shouldEqual("[0, 1, 2, 3]");
84 }
85 
86 @("text.aa")
87 @safe unittest {
88     const aa = ["foo": 1, "bar": 2];
89     const actual = () @nogc { return aa.text; }();
90     try
91         debug actual.range.shouldEqual(`[foo: 1, bar: 2]`);
92     catch(UnitTestException _)
93         debug actual.range.shouldEqual(`[bar: 2, foo: 1]`);
94 }
95 
96 
97 @("toWtringz")
98 @safe unittest {
99     const wstr = "foobar".toWStringz;
100     wstr.range.shouldEqual("foobar"w ~ 0);
101 }
102 
103 
104 @("text.toWtringz")
105 @safe unittest {
106     const wstr = text("foo ", 42, " bar").toWStringz;
107     wstr.range.shouldEqual("foo 42 bar"w ~ 0);
108 }