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

Commit aabda1c

Browse files
authored
Merge pull request #2463 from wilzbach/assert-in
Add support for the in operator in dassert merged-on-behalf-of: Petar Kirov <ZombineDev@users.noreply.github.com>
2 parents 01507d7 + 12eb53d commit aabda1c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/core/internal/dassert.d

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ auto miniFormat(V)(auto ref V v)
4141
{
4242
import core.stdc.stdio : sprintf;
4343
import core.stdc.string : strlen;
44-
static if (__traits(isIntegral, V))
44+
static if (is(V : bool))
45+
{
46+
return v ? "true" : "false";
47+
}
48+
else static if (__traits(isIntegral, V))
4549
{
4650
enum printfFormat = getPrintfFormat!V;
4751
char[20] val;
@@ -140,6 +144,10 @@ string invertCompToken(string comp)
140144
return "!is";
141145
case "!is":
142146
return "is";
147+
case "in":
148+
return "!in";
149+
case "!in":
150+
return "in";
143151
default:
144152
assert(0, "Invalid comparison operator: " ~ comp);
145153
}

test/exceptions/src/assert_fail.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void testStruct()()
108108
void testAA()()
109109
{
110110
test([1:"one"], [2: "two"], `[1: "one"] != [2: "two"]`);
111+
test!"in"(1, [2: 3], "1 !in [2: 3]");
112+
test!"in"("foo", ["bar": true], `"foo" !in ["bar": true]`);
111113
}
112114

113115
void main()

0 commit comments

Comments
 (0)