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.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 @("text.enum") 45 @safe @nogc unittest { 46 import std.algorithm: equal; 47 enum Enum { foo, bar, baz } 48 const actual = Enum.bar.text; 49 assert(equal(actual.range, "bar")); 50 } 51 52 @("text.struct") 53 @safe @nogc unittest { 54 static struct Struct { 55 int i; 56 double d; 57 } 58 59 const actual = Struct(2, 33.3).text; 60 debug actual.range.shouldEqual("Struct(2, 33.300000)"); 61 } 62 63 @("text.string") 64 @safe @nogc unittest { 65 const actual = "foobar".text; 66 debug actual.range.shouldEqual("foobar"); 67 } 68 69 70 @("text.inputrange") 71 @safe @nogc unittest { 72 import std.range: only; 73 const actual = only(0, 1, 2, 3).text; 74 debug actual.range.shouldEqual("[0, 1, 2, 3]"); 75 } 76 77 @("text.aa") 78 @safe unittest { 79 const aa = ["foo": 1, "bar": 2]; 80 const actual = () @nogc { return aa.text; }(); 81 try 82 debug actual.range.shouldEqual(`[foo: 1, bar: 2]`); 83 catch(UnitTestException _) 84 debug actual.range.shouldEqual(`[bar: 2, foo: 1]`); 85 } 86 87 88 @("toWtringz") 89 @safe unittest { 90 const wstr = "foobar".toWStringz; 91 wstr.range.shouldEqual("foobar"w ~ 0); 92 } 93 94 95 @("text.toWtringz") 96 @safe unittest { 97 const wstr = text("foo ", 42, " bar").toWStringz; 98 wstr.range.shouldEqual("foo 42 bar"w ~ 0); 99 }