vlib: fix new_int for tests too (#25351)

This commit is contained in:
kbkpbot 2025-09-19 21:54:58 +08:00 committed by GitHub
parent 7b07f27774
commit dddbacb196
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 111 additions and 27 deletions

View File

@ -17,7 +17,11 @@ fn test_str_methods() {
assert int(1).str() == '1'
assert int(-1).str() == '-1'
assert int(2147483647).str() == '2147483647'
assert int(u32(2147483648)).str() == '-2147483648'
assert int(u32(2147483648)).str() == $if new_int ? && x64 {
'2147483648'
} $else {
'-2147483648'
}
assert int(-2147483648).str() == '-2147483648'
assert i64(1).str() == '1'
assert i64(-1).str() == '-1'

View File

@ -930,7 +930,11 @@ fn test_hash() {
s3 := 'Content-Type'
assert s3.hash() == 949037134
s4 := 'bad_key'
assert s4.hash() == -346636507
assert s4.hash() == $if new_int ? && x64 {
3948330789
} $else {
-346636507
}
s5 := '24640'
// From a map collision test
assert s5.hash() % ((1 << 20) - 1) == s.hash() % ((1 << 20) - 1)

View File

@ -1118,7 +1118,11 @@ fn test_min_max_int_str() {
fn test_maxof_minof() {
assert maxof[i8]() == 127
assert maxof[i16]() == 32767
assert maxof[int]() == 2147483647
assert maxof[int]() == $if new_int ? && x64 {
9223372036854775807
} $else {
2147483647
}
assert maxof[i32]() == 2147483647
assert maxof[i64]() == 9223372036854775807
assert maxof[u8]() == 255
@ -1130,7 +1134,11 @@ fn test_maxof_minof() {
assert minof[i8]() == -128
assert minof[i16]() == -32768
assert minof[int]() == -2147483648
assert minof[int]() == $if new_int ? && x64 {
-9223372036854775807 - 1
} $else {
-2147483648
}
assert minof[i32]() == -2147483648
assert minof[i64]() == -9223372036854775807 - 1
assert minof[u8]() == 0

View File

@ -83,8 +83,8 @@ fn test_atoi() {
StrInt{'123_456_789', 123456789},
StrInt{'00000006', 6},
StrInt{'0_0_0_0_0_0_0_6', 6},
StrInt{'2147483647', max_int},
StrInt{'-2147483648', min_int},
StrInt{'2147483647', max_i32},
StrInt{'-2147483648', min_i32},
]
// Check that extracted int value matches its string.

View File

@ -1,6 +1,6 @@
union Convertor {
su8_array_p [20]u8
sint_array_p [5]int
sint_array_p [5]i32
}
fn test_main() {
@ -13,9 +13,17 @@ fn test_main() {
assert a == [1, 2, 3, 4, 5]!
assert p != 0
$if little_endian {
assert c == [u8(1), 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0]!
$if new_int ? && x64 {
assert c == [u8(1), 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0]!
} $else {
assert c == [u8(1), 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0]!
}
}
$if big_endian {
assert c == [u8(0), 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5]!
$if new_int ? && x64 {
assert c == [u8(0), 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0]!
} $else {
assert c == [u8(0), 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5]!
}
}
}

View File

@ -46,5 +46,9 @@ fn test_main() {
path.add(b1)
path.add(b2)
assert sizeof(path) == 32772
assert sizeof(path) == $if new_int ? && x64 {
32776
} $else {
32772
}
}

View File

@ -3,13 +3,21 @@ const sbuffer_size = 10
fn test_hardcoded_static_arr() {
myints := [10]int{}
size := sizeof(myints)
assert size == 40
assert size == $if new_int ? && x64 {
80
} $else {
40
}
}
fn test_const_based_static_arr() {
myints := [sbuffer_size]int{}
size := sizeof(myints)
assert size == 40
assert size == $if new_int ? && x64 {
80
} $else {
40
}
}
fn test_const_based_static_arr_of_f64() {

View File

@ -17,7 +17,7 @@ fn test_carray_to_varray() {
}
c_int_array := C.gen_c_int_array(size)
v_int_array := unsafe { arrays.carray_to_varray[int](c_int_array, size) }
v_int_array := unsafe { arrays.carray_to_varray[i32](c_int_array, size) }
unsafe { C.free(c_int_array) }
assert v_int_array.len == size
for i, elem in v_int_array {

View File

@ -17,9 +17,17 @@ fn d(val Value) string {
}
fn test_main() {
assert d(Value(0)) == 'Value is number or byte array, size=4 0'
assert d(Value(0)) == $if new_int ? && x64 {
'Value is number or byte array, size=8 0'
} $else {
'Value is number or byte array, size=4 0'
}
assert d(Value(i64(1))) == 'Value is number or byte array, size=8 1'
assert d(Value(u64(2))) == 'Value is number or byte array, size=8 2'
assert d(Value([u8(1), 2])) == 'Value is number or byte array, size=32 [1, 2]'
assert d(Value([u8(1), 2])) == $if new_int ? && x64 {
'Value is number or byte array, size=48 [1, 2]'
} $else {
'Value is number or byte array, size=32 [1, 2]'
}
assert d(Value('')) == 'Value is string: '
}

View File

@ -2,7 +2,7 @@ fn test_main() {
mut b := [2]int{}
b[0] = 1
b[1] = 2
mut a := unsafe { memdup(b, 8) }
mut a := unsafe { memdup(b, $if new_int ? && x64 { 16 } $else { 8 }) }
x := &int(a)
unsafe {
assert x[0] == 1

View File

@ -10,12 +10,20 @@ fn f[T]() u32 {
fn test_generic_fn_variable() {
r1 := f[int]()
println(r1)
assert r1 == 4
assert r1 == $if new_int ? && x64 {
8
} $else {
4
}
r2 := f[string]()
println(r2)
assert r2 == $if x64 {
16
$if new_int ? {
24
} $else {
16
}
} $else {
12
}

View File

@ -4,5 +4,9 @@ fn getsize[P]() u32 {
fn test_sizeof_2() {
assert getsize[f64]() == 8
assert 4 == getsize[int]()
$if new_int ? && x64 {
assert 8 == getsize[int]()
} $else {
assert 4 == getsize[int]()
}
}

View File

@ -10,7 +10,7 @@ struct S2 {
}
fn test_math_sizeof() {
r := math.f32_from_bits(sizeof(int))
r := math.f32_from_bits(sizeof(i32))
assert f64(r) > 5.6e-45 && f64(r) < 5.7e-45
}
@ -21,17 +21,29 @@ fn test_sizeof() {
// depends on -m32/64
assert sizeof(S1) in [u32(4), 8]
s := S2{}
assert sizeof(s.i) == 4
assert sizeof(s.i) == $if new_int ? && x64 {
8
} $else {
4
}
assert sizeof(flag.Flag) > 4
assert sizeof(c'hello') == 6
assert sizeof(r'hello') == $if x64 {
16
$if new_int ? {
24
} $else {
16
}
} $else {
12
}
assert sizeof('hello') == $if x64 {
16
$if new_int ? {
24
} $else {
16
}
} $else {
12
}

View File

@ -8,10 +8,17 @@ mut:
fn test_main() {
x := PaddedSlot[int]{}
assert '${x}' == 'PaddedSlot[int]{
$if new_int ? && x64 {
assert '${x}' == 'PaddedSlot[int]{
data: 0
pad: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}'
} $else {
assert '${x}' == 'PaddedSlot[int]{
data: 0
pad: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
}'
}
x2 := PaddedSlot[u8]{}
assert '${x2}' == 'PaddedSlot[u8]{
data: 0

View File

@ -18,7 +18,11 @@ fn test_unsigned_right_shift_expr_isize_usize() {
fn test_unsigned_right_shift_expr() {
assert i64(-5) >>> 1 == answer_u64
assert -5 >>> 1 == answer_u32 // because int literal's size defaults to int's size, without an explicit cast
assert int(-5) >>> 1 == answer_u32
$if new_int ? && x64 {
assert int(-5) >>> 1 == answer_u64
} $else {
assert int(-5) >>> 1 == answer_u32
}
assert i16(-5) >>> 1 == answer_u16
assert i8(-5) >>> 1 == answer_u8
}
@ -29,6 +33,11 @@ fn test_unsigned_right_shift_assignment() {
y >>>= 1
z >>>= 1
assert x == answer_u64
assert y == answer_u32
assert z == answer_u32
$if new_int ? && x64 {
assert y == answer_u64
assert z == answer_u64
} $else {
assert y == answer_u32
assert z == answer_u32
}
}