From f943c584c7bbcacf607f98b9064cc50c4643eed3 Mon Sep 17 00:00:00 2001 From: coffeepots Date: Mon, 9 Jul 2018 09:43:23 +0100 Subject: [PATCH] Add check for empty string --- tests/ethhexstrings.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/ethhexstrings.nim b/tests/ethhexstrings.nim index 50529bf..f711689 100644 --- a/tests/ethhexstrings.nim +++ b/tests/ethhexstrings.nim @@ -17,7 +17,7 @@ proc encodeQuantity*(value: SomeUnsignedInt): string = template hasHexHeader*(value: string | HexDataStr | HexQuantityStr): bool = template strVal: untyped = value.string - if strVal[0] == '0' and strVal[1] in {'x', 'X'} and strVal.len > 2: true + if strVal != "" and strVal[0] == '0' and strVal[1] in {'x', 'X'} and strVal.len > 2: true else: false template isHexChar*(c: char): bool = @@ -94,6 +94,12 @@ proc fromJson*(n: JsonNode, argName: string, result: var HexQuantityStr) = when isMainModule: import unittest suite "Hex quantity": + test "Empty string": + expect ValueError: + let + source = "" + x = hexQuantityStr source + check %x == %source test "Even length": let source = "0x123"