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 = () @nogc nothrow { return text(1, " ", 2.0, " ", true); }();
10     actual[].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[].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     act[0 .. 7].shouldEqual("pokémon".to!wstring);
29 }
30 
31 @("text with at limit characters")
32 @safe unittest {
33     const actual = () @nogc nothrow { return text!4("foo"); }();
34     actual[].shouldEqual("foo");
35 }
36 
37 @("text with 1 fewer char than needed")
38 @safe unittest {
39     const actual = () @nogc nothrow { return text!3("foo"); }();
40     actual[].shouldEqual("fo");
41 }
42 
43 @("text.enum")
44 @safe @nogc unittest {
45     enum Enum { foo, bar, baz }
46     const actual = Enum.bar.text;
47     assert(actual[] == "bar", actual[]);
48 }
49 
50 @("text.struct")
51 @safe @nogc unittest {
52     static struct Struct {
53         int i;
54         double d;
55     }
56 
57     const actual = Struct(2, 33.3).text;
58     debug actual[].shouldEqual("Struct(2, 33.300000)");
59 }
60 
61 @("text.string")
62 @safe @nogc unittest {
63     const actual = "foobar".text;
64     debug actual[].shouldEqual("foobar");
65 }
66 
67 
68 @("text.inputrange")
69 @safe @nogc unittest {
70     import std.range: only;
71     const actual = only(0, 1, 2, 3).text;
72     debug actual[].shouldEqual("[0, 1, 2, 3]");
73 }
74 
75 @("text.aa")
76 @safe unittest {
77     const aa = ["foo": 1, "bar": 2];
78     const actual = () @nogc { return aa.text; }();
79     try
80         debug actual[].shouldEqual(`[foo: 1, bar: 2]`);
81     catch(UnitTestException _)
82         debug actual[].shouldEqual(`[bar: 2, foo: 1]`);
83 }
84 
85 
86 @("toWtringz")
87 @safe unittest {
88     const wstr = "foobar".toWStringz;
89     wstr[].shouldEqual("foobar"w ~ 0);
90 }
91 
92 
93 @("text.toWtringz")
94 @safe unittest {
95     const wstr = text("foo ", 42, " bar").toWStringz;
96     wstr[].shouldEqual("foo 42 bar"w ~ 0);
97 }