From 75cbbef0ab3fefecab29bfbde5bbfd9b59eb2bbd Mon Sep 17 00:00:00 2001 From: Dragos Carp Date: Mon, 16 Nov 2015 03:04:07 +0100 Subject: [PATCH] Add asserts for the "compiles" tests --- std/algorithm/iteration.d | 4 ++-- std/algorithm/mutation.d | 18 +++++++++++++++--- std/array.d | 4 ++-- std/datetime.d | 8 ++++++++ std/meta.d | 4 ++++ std/path.d | 6 +++--- std/range/package.d | 8 ++------ std/range/primitives.d | 4 ++++ std/typecons.d | 13 ++++++++++++- 9 files changed, 52 insertions(+), 17 deletions(-) diff --git a/std/algorithm/iteration.d b/std/algorithm/iteration.d index 2147352b9..65954b8a3 100644 --- a/std/algorithm/iteration.d +++ b/std/algorithm/iteration.d @@ -765,14 +765,14 @@ unittest // Issue #10130 - map of iota with const step. const step = 2; - map!(i => i)(iota(0, 10, step)); + assert(map!(i => i)(iota(0, 10, step)).walkLength == 5); // Need these to all by const to repro the float case, due to the // CommonType template used in the float specialization of iota. const floatBegin = 0.0; const floatEnd = 1.0; const floatStep = 0.02; - map!(i => i)(iota(floatBegin, floatEnd, floatStep)); + assert(map!(i => i)(iota(floatBegin, floatEnd, floatStep)).walkLength == 50); } @safe unittest diff --git a/std/algorithm/mutation.d b/std/algorithm/mutation.d index b1eedf6e9..96ac98c6c 100644 --- a/std/algorithm/mutation.d +++ b/std/algorithm/mutation.d @@ -574,11 +574,13 @@ void fill(Range, Value)(Range range, Value value) int[] a = [1, 2, 3]; immutable(int) b = 0; a.fill(b); + assert(a == [0, 0, 0]); } { double[] a = [1, 2, 3]; immutable(int) b = 0; a.fill(b); + assert(a == [0, 0, 0]); } } @@ -982,7 +984,10 @@ unittest class S5; S5 s51; - move(s51, s51); + S5 s52 = s51; + S5 s53; + move(s52, s53); + assert(s53 is s51); } /// Ditto @@ -1092,17 +1097,24 @@ unittest class S5; S5 s51; - s51 = move(s51); + S5 s52 = s51; + S5 s53; + s53 = move(s52); + assert(s53 is s51); } unittest { - static struct S { ~this() @system { } } + static struct S { int n = 0; ~this() @system { n = 0; } } S a, b; static assert(!__traits(compiles, () @safe { move(a, b); })); static assert(!__traits(compiles, () @safe { move(a); })); + a.n = 1; () @trusted { move(a, b); }(); + assert(a.n == 0); + a.n = 1; () @trusted { move(a); }(); + assert(a.n == 0); } unittest//Issue 6217 diff --git a/std/array.d b/std/array.d index 834bc1c34..468cd7c1f 100644 --- a/std/array.d +++ b/std/array.d @@ -377,7 +377,7 @@ unittest import std.typecons; static assert(!__traits(compiles, [ tuple("foo", "bar", "baz") ].assocArray())); static assert(!__traits(compiles, [ tuple("foo") ].assocArray())); - [ tuple("foo", "bar") ].assocArray(); + assert([ tuple("foo", "bar") ].assocArray() == ["foo": "bar"]); } // Issue 13909 @@ -386,7 +386,7 @@ unittest import std.typecons; auto a = [tuple!(const string, string)("foo", "bar")]; auto b = [tuple!(string, const string)("foo", "bar")]; - assocArray(a); + assert(assocArray(a) == [cast(const(string)) "foo": "bar"]); static assert(!__traits(compiles, assocArray(b))); } diff --git a/std/datetime.d b/std/datetime.d index a4c0529e3..d256c7f97 100644 --- a/std/datetime.d +++ b/std/datetime.d @@ -1186,6 +1186,7 @@ public: const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33)); //immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33)); st.year = 12; + assert(st.year == 12); static assert(!__traits(compiles, cst.year = 12)); //static assert(!__traits(compiles, ist.year = 12)); } @@ -1282,6 +1283,7 @@ public: const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33)); //immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33)); st.yearBC = 12; + assert(st.yearBC == 12); static assert(!__traits(compiles, cst.yearBC = 12)); //static assert(!__traits(compiles, ist.yearBC = 12)); } @@ -6839,6 +6841,7 @@ public: const cst = SysTime(DateTime(1999, 7, 6, 12, 30, 33)); //immutable ist = SysTime(DateTime(1999, 7, 6, 12, 30, 33)); st.dayOfYear = 12; + assert(st.dayOfYear == 12); static assert(!__traits(compiles, cst.dayOfYear = 12)); //static assert(!__traits(compiles, ist.dayOfYear = 12)); } @@ -9567,6 +9570,7 @@ public: const cdate = Date(0, 7, 6); immutable idate = Date(0, 7, 6); date.yearBC = 7; + assert(date.yearBC == 7); static assert(!__traits(compiles, cdate.yearBC = 7)); static assert(!__traits(compiles, idate.yearBC = 7)); } @@ -12210,6 +12214,7 @@ public: const cdate = Date(1999, 7, 6); immutable idate = Date(1999, 7, 6); date.dayOfGregorianCal = 187; + assert(date.dayOfGregorianCal == 187); static assert(!__traits(compiles, cdate.dayOfGregorianCal = 187)); static assert(!__traits(compiles, idate.dayOfGregorianCal = 187)); } @@ -15039,6 +15044,7 @@ public: const cdt = DateTime(1999, 7, 6, 12, 30, 33); immutable idt = DateTime(1999, 7, 6, 12, 30, 33); dt.yearBC = 12; + assert(dt.yearBC == 12); static assert(!__traits(compiles, cdt.yearBC = 12)); static assert(!__traits(compiles, idt.yearBC = 12)); } @@ -15077,6 +15083,7 @@ public: const cdt = DateTime(1999, 7, 6, 12, 30, 33); immutable idt = DateTime(1999, 7, 6, 12, 30, 33); dt.yearBC = 12; + assert(dt.yearBC == 12); static assert(!__traits(compiles, cdt.yearBC = 12)); static assert(!__traits(compiles, idt.yearBC = 12)); } @@ -16542,6 +16549,7 @@ public: const cdt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)); immutable idt = DateTime(Date(1999, 7, 6), TimeOfDay(12, 30, 33)); dt.dayOfYear = 12; + assert(dt.dayOfYear == 12); static assert(!__traits(compiles, cdt.dayOfYear = 12)); static assert(!__traits(compiles, idt.dayOfYear = 12)); } diff --git a/std/meta.d b/std/meta.d index 8cee47be4..1072c2bb9 100644 --- a/std/meta.d +++ b/std/meta.d @@ -983,9 +983,13 @@ unittest { enum abc = 1; alias a = Alias!(123); + static assert(a == 123); alias b = Alias!(abc); + static assert(b == 1); alias c = Alias!(int); + static assert(c.stringof == "(int)"); alias d = Alias!(1, abc, int); + static assert(d[0] == 1 && d[1] == 1 && d[2].stringof == "int"); } diff --git a/std/path.d b/std/path.d index 600da667d..1b83fd7ce 100644 --- a/std/path.d +++ b/std/path.d @@ -1554,9 +1554,9 @@ auto chainPath(Ranges...)(auto ref Ranges ranges) unittest { - chainPath(TestAliasedString(null), TestAliasedString(null), TestAliasedString(null)); - chainPath(TestAliasedString(null), TestAliasedString(null), ""); - chainPath(TestAliasedString(null), "", TestAliasedString(null)); + assert(chainPath(TestAliasedString(null), TestAliasedString(null), TestAliasedString(null)).empty); + assert(chainPath(TestAliasedString(null), TestAliasedString(null), "").empty); + assert(chainPath(TestAliasedString(null), "", TestAliasedString(null)).empty); static struct S { string s; } static assert(!__traits(compiles, chainPath(TestAliasedString(null), S(""), TestAliasedString(null)))); } diff --git a/std/range/package.d b/std/range/package.d index 5ad2469bc..01405e51f 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -3944,8 +3944,8 @@ pure unittest import std.exception : assertThrown; static struct S { @disable this(); } - zip((S[5]).init[]); - auto z = zip(StoppingPolicy.longest, cast(S[]) null, new int[1]); + assert(zip((S[5]).init[]).length == 5); + assert(zip(StoppingPolicy.longest, cast(S[]) null, new int[1]).length == 1); assertThrown(zip(StoppingPolicy.longest, cast(S[]) null, new int[1]).front); } @@ -4212,10 +4212,6 @@ unittest static assert(!__traits(compiles, { foreach (ref a, ref b; lockstep(r1, r2)) { a++; } })); - foreach (a, ref b; lockstep(r1, r2)) - { - a++; - } } /** diff --git a/std/range/primitives.d b/std/range/primitives.d index dcadd7ca6..28a0f35f0 100644 --- a/std/range/primitives.d +++ b/std/range/primitives.d @@ -445,6 +445,7 @@ unittest int[] a = new int[10]; static assert(!__traits(compiles, put(a, 1.0L))); put(a, 1); + assert(a.length == 9); /* * a[0] = 65; // OK * a[0] = 'A'; // OK @@ -452,6 +453,7 @@ unittest * put(a, "ABC"); // OK */ put(a, "ABC"); + assert(a.length == 6); } unittest @@ -470,7 +472,9 @@ unittest int[] b = new int[10]; int c; put(b, c); + assert(b.length == 9); put(a, b); + assert(a.length == 9); static assert(!__traits(compiles, put(a, c))); } diff --git a/std/typecons.d b/std/typecons.d index 01096a8d9..cb2485dc4 100644 --- a/std/typecons.d +++ b/std/typecons.d @@ -1161,7 +1161,7 @@ unittest foreach (v1; AliasSeq!(mv, cv, iv, wv, wcv)) foreach (v2; AliasSeq!(mv, cv, iv, wv, wcv)) { - cast(void) (v1 < v2); + assert(!(v1 < v2)); } } { @@ -2179,6 +2179,10 @@ unittest auto x2 = immutable Nullable!S1(sm); auto x3 = Nullable!S1(si); auto x4 = immutable Nullable!S1(si); + assert(x1.val == 1); + assert(x2.val == 1); + assert(x3.val == 1); + assert(x4.val == 1); } auto nm = 10; @@ -2191,6 +2195,8 @@ unittest static assert(!__traits(compiles, { auto x2 = immutable Nullable!S2(sm); })); static assert(!__traits(compiles, { auto x3 = Nullable!S2(si); })); auto x4 = immutable Nullable!S2(si); + assert(*x1.val == 10); + assert(*x4.val == 10); } { @@ -2200,6 +2206,10 @@ unittest auto x2 = immutable Nullable!S3(sm); auto x3 = Nullable!S3(si); auto x4 = immutable Nullable!S3(si); + assert(*x1.val == 10); + assert(*x2.val == 10); + assert(*x3.val == 10); + assert(*x4.val == 10); } } unittest @@ -6553,6 +6563,7 @@ public: C = 1<<2 } BitFlags!Enum flags1; + assert(!(flags1 & (Enum.A | Enum.B | Enum.C))); // You need to specify the $(D unsafe) parameter for enum with custom values enum UnsafeEnum