mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gen: fix comparing signed int to u32/u64 (#7312)
This commit is contained in:
parent
069d77d1c5
commit
78fb84c4dd
@ -20,7 +20,7 @@ const (
|
||||
// same order as in token.Kind
|
||||
cmp_str = ['eq', 'ne', 'gt', 'lt', 'ge', 'le']
|
||||
// when operands are switched
|
||||
cmp_rev = ['eq', 'ne', 'le', 'ge', 'lt', 'gt']
|
||||
cmp_rev = ['eq', 'ne', 'lt', 'gt', 'le', 'ge']
|
||||
)
|
||||
|
||||
struct Gen {
|
||||
|
83
vlib/v/tests/infix_expr_test.v
Normal file
83
vlib/v/tests/infix_expr_test.v
Normal file
@ -0,0 +1,83 @@
|
||||
fn test_cmp_signed_and_u32() {
|
||||
// ==
|
||||
assert int(1) == u32(1)
|
||||
// !=
|
||||
assert int(1) != u32(2)
|
||||
// >
|
||||
assert !(int(1) > u32(1))
|
||||
assert int(1) > u32(0)
|
||||
// >=
|
||||
assert !(int(0) >= u32(1))
|
||||
assert int(1) >= u32(1)
|
||||
assert int(1) >= u32(0)
|
||||
// <
|
||||
assert !(int(1) < u32(1))
|
||||
assert int(0) < u32(1)
|
||||
// <=
|
||||
assert int(0) <= u32(1)
|
||||
assert int(1) <= u32(1)
|
||||
assert !(int(1) <= u32(0))
|
||||
}
|
||||
|
||||
fn test_cmp_u32_and_signed() {
|
||||
// ==
|
||||
assert u32(1) == int(1)
|
||||
// !=
|
||||
assert u32(2) != int(1)
|
||||
// >
|
||||
assert !(u32(1) > int(1))
|
||||
assert u32(1) > int(0)
|
||||
// >=
|
||||
assert u32(1) >= int(0)
|
||||
assert u32(1) >= int(1)
|
||||
assert !(u32(0) >= int(1))
|
||||
// <
|
||||
assert !(u32(1) < int(1))
|
||||
assert u32(0) < int(1)
|
||||
// <=
|
||||
assert u32(0) <= int(1)
|
||||
assert u32(1) <= int(1)
|
||||
assert !(u32(1) <= int(0))
|
||||
}
|
||||
|
||||
fn test_cmp_signed_and_u64() {
|
||||
// ==
|
||||
assert int(1) == u64(1)
|
||||
// !=
|
||||
assert int(1) != u64(2)
|
||||
// >
|
||||
assert !(int(1) > u64(1))
|
||||
assert int(1) > u64(0)
|
||||
// >=
|
||||
assert !(int(0) >= u64(1))
|
||||
assert int(1) >= u64(1)
|
||||
assert int(1) >= u64(0)
|
||||
// <
|
||||
assert !(int(1) < u64(1))
|
||||
assert int(0) < u64(1)
|
||||
// <=
|
||||
assert int(0) <= u64(1)
|
||||
assert int(1) <= u64(1)
|
||||
assert !(int(1) <= u64(0))
|
||||
}
|
||||
|
||||
fn test_cmp_u64_and_signed() {
|
||||
// ==
|
||||
assert u64(1) == int(1)
|
||||
// !=
|
||||
assert u64(2) != int(1)
|
||||
// >
|
||||
assert !(u64(1) > int(1))
|
||||
assert u64(1) > int(0)
|
||||
// >=
|
||||
assert u64(1) >= int(0)
|
||||
assert u64(1) >= int(1)
|
||||
assert !(u64(0) >= int(1))
|
||||
// <
|
||||
assert !(u64(1) < int(1))
|
||||
assert u64(0) < int(1)
|
||||
// <=
|
||||
assert u64(0) <= int(1)
|
||||
assert u64(1) <= int(1)
|
||||
assert !(u64(1) <= int(0))
|
||||
}
|
Loading…
Reference in New Issue
Block a user