mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
builtin: string interpolation: binary format support (#11421)
This commit is contained in:
parent
fae0f8d821
commit
bd10a63839
4 changed files with 52 additions and 5 deletions
|
@ -219,3 +219,38 @@ fn test_signed_cast() {
|
|||
assert '${u.f:G}' == '-INF'
|
||||
}
|
||||
}
|
||||
|
||||
fn test_binary() {
|
||||
i := i8(127)
|
||||
u := u8(127)
|
||||
assert '${i:08b}' == '01111111'
|
||||
assert '${u:08b}' == '01111111'
|
||||
assert '${i16(i):08b}' == '01111111'
|
||||
assert '${u16(u):08b}' == '01111111'
|
||||
assert '${int(i):08b}' == '01111111'
|
||||
assert '${u32(u):08b}' == '01111111'
|
||||
assert '${i64(i):08b}' == '01111111'
|
||||
assert '${u64(u):08b}' == '01111111'
|
||||
|
||||
n := i8(-1)
|
||||
assert '${u8(-1):08b}' == '11111111'
|
||||
assert '${u16(n):08b}' == '1111111111111111'
|
||||
assert '${u32(n):08b}' == '11111111111111111111111111111111'
|
||||
assert '${u64(n):08b}' == '1111111111111111111111111111111111111111111111111111111111111111'
|
||||
}
|
||||
|
||||
fn test_binary32() {
|
||||
i := int(0x7fff_ffff)
|
||||
u := u32(0x7fff_ffff)
|
||||
assert '${i:032b}' == '01111111111111111111111111111111'
|
||||
assert '${u:032b}' == '01111111111111111111111111111111'
|
||||
assert '${i64(i):032b}' == '01111111111111111111111111111111'
|
||||
assert '${u64(u):032b}' == '01111111111111111111111111111111'
|
||||
}
|
||||
|
||||
fn test_binary64() {
|
||||
i := i64(0x7fff_ffff_ffff_ffff)
|
||||
u := u64(0x7fff_ffff_ffff_ffff)
|
||||
assert '${i:064b}' == '0111111111111111111111111111111111111111111111111111111111111111'
|
||||
assert '${u:064b}' == '0111111111111111111111111111111111111111111111111111111111111111'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue