mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 22:21:09 +03:00
Add asserts for the "compiles" tests
This commit is contained in:
parent
c17a621bf2
commit
75cbbef0ab
9 changed files with 52 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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))));
|
||||
}
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue