mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
encoding: add a hex sub-module (#11193)
This commit is contained in:
41
vlib/encoding/hex/hex_test.v
Normal file
41
vlib/encoding/hex/hex_test.v
Normal file
@ -0,0 +1,41 @@
|
||||
module hex
|
||||
|
||||
fn test_decode() ? {
|
||||
assert decode('') ? == []
|
||||
assert decode('0') ? == [byte(0x0)]
|
||||
assert decode('f') ? == [byte(0xf)]
|
||||
assert decode('0f') ? == [byte(0x0f)]
|
||||
assert decode('ff') ? == [byte(0xff)]
|
||||
assert decode('123') ? == [byte(0x1), 0x23]
|
||||
assert decode('1234') ? == [byte(0x12), 0x34]
|
||||
assert decode('12345') ? == [byte(0x1), 0x23, 0x45]
|
||||
}
|
||||
|
||||
fn test_decode_fails() ? {
|
||||
if x := decode('foo') {
|
||||
return error('expected decode to fail, got $x')
|
||||
}
|
||||
if x := decode('g') {
|
||||
return error('expected decode to fail, got $x')
|
||||
}
|
||||
if x := decode('000000000g') {
|
||||
return error('expected decode to fail, got $x')
|
||||
}
|
||||
if x := decode('_') {
|
||||
return error('expected decode to fail, got $x')
|
||||
}
|
||||
if x := decode('!') {
|
||||
return error('expected decode to fail, got $x')
|
||||
}
|
||||
}
|
||||
|
||||
fn test_encode() ? {
|
||||
assert encode(decode('') ?) == ''
|
||||
assert encode(decode('0') ?) == '00'
|
||||
assert encode(decode('f') ?) == '0f'
|
||||
assert encode(decode('0f') ?) == '0f'
|
||||
assert encode(decode('ff') ?) == 'ff'
|
||||
assert encode(decode('123') ?) == '0123'
|
||||
assert encode(decode('1234') ?) == '1234'
|
||||
assert encode(decode('12345') ?) == '012345'
|
||||
}
|
Reference in New Issue
Block a user