Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 40f6906

Browse files
committed
Add unittests for improving coverage
1 parent d0d891f commit 40f6906

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

src/rt/util/typeinfo.d

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ private class TypeInfoGeneric(T) : TypeInfo
342342

343343
override void swap(void *p1, void *p2)
344344
{
345-
T t;
346-
347-
t = *cast(T *)p1;
345+
auto t = *cast(T *) p1;
348346
*cast(T *)p1 = *cast(T *)p2;
349347
*cast(T *)p2 = t;
350348
}
@@ -360,6 +358,30 @@ private class TypeInfoGeneric(T) : TypeInfo
360358
override @property uint flags() const { return 2; }
361359
}
362360

361+
unittest
362+
{
363+
assert(typeid(int).toString == "int");
364+
double a = 42, b = 43;
365+
assert(typeid(double).equals(&a, &a));
366+
assert(!typeid(double).equals(&a, &b));
367+
assert(typeid(double).compare(&a, &a) == 0);
368+
assert(typeid(double).compare(&a, &b) == -1);
369+
assert(typeid(double).compare(&b, &a) == 1);
370+
371+
short c = 42, d = 43;
372+
assert(typeid(short).equals(&c, &c));
373+
assert(!typeid(short).equals(&c, &b));
374+
assert(typeid(short).compare(&c, &c) == 0);
375+
assert(typeid(short).compare(&c, &d) == -1);
376+
assert(typeid(short).compare(&d, &c) == 1);
377+
378+
assert(typeid(int).initializer.ptr is null);
379+
assert(typeid(int).initializer.length == int.sizeof);
380+
381+
typeid(short).swap(&d, &c);
382+
assert(c == 43 && d == 42);
383+
}
384+
363385
private class TypeInfoArrayGeneric(T) : TypeInfo_Array
364386
{
365387
static if (is(T == ifloat)) private alias Real = float;
@@ -426,6 +448,22 @@ private class TypeInfoArrayGeneric(T) : TypeInfo_Array
426448
}
427449
}
428450

451+
unittest
452+
{
453+
assert(typeid(int[]) == typeid(int[]));
454+
assert(typeid(int[]) != typeid(uint[]));
455+
assert(typeid(int[]).toString == "int[]");
456+
457+
double[] a = [ 1, 2, 3 ], b = [ 2, 3 ];
458+
459+
assert(typeid(double[]).equals(&a, &a));
460+
assert(!typeid(double[]).equals(&a, &b));
461+
462+
assert(typeid(double[]).compare(&a, &a) == 0);
463+
assert(typeid(double[]).compare(&a, &b) == -1);
464+
assert(typeid(double[]).compare(&b, &a) == 1);
465+
}
466+
429467
////////////////////////////////////////////////////////////////////////////////
430468
// Predefined TypeInfos
431469
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)