@@ -255,6 +255,8 @@ pure @safe nothrow @nogc unittest
255
255
Hash gm1 = GMerkle_str;
256
256
Hash gm2 = GMerkle_bin;
257
257
assert (gm1.data == GMerkle_bin);
258
+ // Test opIndex
259
+ assert (gm1[] == GMerkle_bin);
258
260
assert (gm1 == gm2);
259
261
260
262
Hash empty;
@@ -264,6 +266,11 @@ pure @safe nothrow @nogc unittest
264
266
// Test opCmp
265
267
assert (empty < gen1);
266
268
assert (gm1 > gen2);
269
+
270
+ assert (! (gm1 > gm1));
271
+ assert (! (gm1 < gm1));
272
+ assert (gm1 >= gm1);
273
+ assert (gm1 <= gm1);
267
274
}
268
275
269
276
// / Test toString
@@ -274,6 +281,8 @@ unittest
274
281
Hash gen1 = GenesisBlockHashStr;
275
282
assert (format(" %s" , gen1) == GenesisBlockHashStr);
276
283
assert (gen1.toString() == GenesisBlockHashStr);
284
+ assert (Hash(gen1.toString()) == gen1);
285
+ assert (Hash.fromString(gen1.toString()) == gen1);
277
286
}
278
287
279
288
// / Make sure `toString` does not allocate even if it's not `@nogc`
@@ -302,6 +311,46 @@ unittest
302
311
assert (h.toString() == GenesisBlockHashStr);
303
312
}
304
313
314
+ // Test assertion failure to raise code coverage
315
+ unittest
316
+ {
317
+ import core.exception : AssertError ;
318
+ import std.algorithm.mutation : reverse;
319
+ import std.exception ;
320
+ alias Hash = BitBlob! (256 );
321
+ ubyte [32 ] genesis = GenesisBlockHash;
322
+ genesis[].reverse;
323
+ Hash result;
324
+ assert (collectException! AssertError (Hash(genesis[0 .. $ - 1 ], false )) ! is null );
325
+ }
326
+
327
+ // Ditto
328
+ unittest
329
+ {
330
+ import core.exception : AssertError ;
331
+ import std.algorithm.mutation : reverse;
332
+ import std.exception ;
333
+ alias Hash = BitBlob! (256 );
334
+ ubyte [32 ] genesis = GenesisBlockHash;
335
+ genesis[].reverse;
336
+ Hash h = Hash(genesis, false );
337
+ Hash h1 = Hash(h.toString());
338
+ assert (h == h1);
339
+ assert (collectException! AssertError (Hash(h.toString()[0 .. $ - 1 ])) ! is null );
340
+ }
341
+
342
+ // Ditto
343
+ unittest
344
+ {
345
+ alias Hash = BitBlob! (256 );
346
+ import core.exception : AssertError ;
347
+ import std.exception ;
348
+ char [GenesisBlockHashStr.length] buff = GenesisBlockHashStr;
349
+ Hash h = Hash(buff);
350
+ buff[5 ] = ' _' ; // Invalid char
351
+ assert (collectException! AssertError (Hash(buff)) ! is null );
352
+ }
353
+
305
354
version (unittest )
306
355
{
307
356
private :
0 commit comments