mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-03-03 23:51:22 +00:00
Address review comments; Add a test
This commit is contained in:
parent
93b04bc214
commit
74396747a3
@ -678,8 +678,18 @@ import json_serialization
|
||||
export json_serialization
|
||||
export writeValue, readValue
|
||||
|
||||
const
|
||||
# http://facweb.cs.depaul.edu/sjost/it212/documents/ascii-pr.htm
|
||||
PrintableAsciiChars = {'!'..'~'}
|
||||
|
||||
func `$`*(value: GraffitiBytes): string =
|
||||
strip(string.fromBytes(distinctBase value), chars = Whitespace + {'\0'})
|
||||
result = strip(string.fromBytes(distinctBase value),
|
||||
leading = false,
|
||||
chars = Whitespace + {'\0'})
|
||||
|
||||
# TODO: Perhaps handle UTF-8 at some point
|
||||
if not allCharsInSet(result, PrintableAsciiChars):
|
||||
result = "0x" & toHex(distinctBase value)
|
||||
|
||||
func init*(T: type GraffitiBytes, input: string): GraffitiBytes
|
||||
{.raises: [ValueError, Defect].} =
|
||||
|
@ -17,6 +17,7 @@ import # Unit test
|
||||
./test_beaconstate,
|
||||
./test_bitseqs,
|
||||
./test_block_pool,
|
||||
./test_datatypes,
|
||||
./test_helpers,
|
||||
./test_keystore,
|
||||
./test_mocking,
|
||||
|
31
tests/test_datatypes.nim
Normal file
31
tests/test_datatypes.nim
Normal file
@ -0,0 +1,31 @@
|
||||
# beacon_chain
|
||||
# Copyright (c) 2018 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
{.used.}
|
||||
|
||||
import
|
||||
unittest, typetraits,
|
||||
../beacon_chain/spec/datatypes,
|
||||
./testutil
|
||||
|
||||
suiteReport "Spec datatypes":
|
||||
timedTest "Graffiti bytes":
|
||||
var
|
||||
g1 = GraffitiBytes.init "Hello"
|
||||
g2 = default(GraffitiBytes)
|
||||
g3 = g2
|
||||
|
||||
distinctBase(g3)[2] = byte(6)
|
||||
|
||||
check:
|
||||
$g1 == "Hello"
|
||||
$g2 == ""
|
||||
$g3 == "0x0000060000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
g2 == GraffitiBytes.init("")
|
||||
g3 == GraffitiBytes.init($g3)
|
||||
|
Loading…
x
Reference in New Issue
Block a user