1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: more precise error handling of large binary literals like 0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 (#16775)

This commit is contained in:
Delyan Angelov
2022-12-27 15:13:15 +02:00
committed by GitHub
parent 508bfbf892
commit a8f6f9ed60
2 changed files with 54 additions and 8 deletions

View File

@ -333,3 +333,20 @@ fn test_parse() {
assert u64(1) == '1'.parse_uint(10, 8) or { 0 }
assert u64(1) == '1'.parse_uint(16, 8) or { 0 }
}
fn test_interpolate_binary_literals() {
assert ' 1 ${i64(0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000)}' == ' 1 -9223372036854775808'
assert ' 2 ${i64(0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111)}' == ' 2 -1'
assert ' 3 ${i64(0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111)}' == ' 3 9223372036854775807'
assert ' 4 ${u64(0b1000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000)}' == ' 4 9223372036854775808'
assert ' 5 ${u64(0b1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111)}' == ' 5 18446744073709551615'
assert ' 6 ${u64(0b0111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111)}' == ' 6 9223372036854775807'
assert ' 7 ${u32(0b111_1111_1111_1111_1111)}' == ' 7 524287'
}
fn test_interpolate_literal_limits() {
assert ' 8 ${u32(2147483648)}' == ' 8 2147483648'
assert ' 9 ${u64(0xFF_FF_FF_FF_FF_FF_FF_FF)}' == ' 9 18446744073709551615'
assert '10 ${u32(0o377777_77777)}' == '10 4294967295'
assert '11 ${i64(-2147483647)}' == '11 -2147483647'
}