@@ -255,6 +255,8 @@ pure @safe nothrow @nogc unittest
255255 Hash gm1 = GMerkle_str;
256256 Hash gm2 = GMerkle_bin;
257257 assert (gm1.data == GMerkle_bin);
258+ // Test opIndex
259+ assert (gm1[] == GMerkle_bin);
258260 assert (gm1 == gm2);
259261
260262 Hash empty;
@@ -264,6 +266,11 @@ pure @safe nothrow @nogc unittest
264266 // Test opCmp
265267 assert (empty < gen1);
266268 assert (gm1 > gen2);
269+
270+ assert (! (gm1 > gm1));
271+ assert (! (gm1 < gm1));
272+ assert (gm1 >= gm1);
273+ assert (gm1 <= gm1);
267274}
268275
269276// / Test toString
@@ -274,6 +281,8 @@ unittest
274281 Hash gen1 = GenesisBlockHashStr;
275282 assert (format(" %s" , gen1) == GenesisBlockHashStr);
276283 assert (gen1.toString() == GenesisBlockHashStr);
284+ assert (Hash(gen1.toString()) == gen1);
285+ assert (Hash.fromString(gen1.toString()) == gen1);
277286}
278287
279288// / Make sure `toString` does not allocate even if it's not `@nogc`
@@ -302,6 +311,46 @@ unittest
302311 assert (h.toString() == GenesisBlockHashStr);
303312}
304313
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+
305354version (unittest )
306355{
307356private :
0 commit comments