1
0
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:
Enzo 2020-12-14 11:01:11 +01:00 committed by GitHub
parent 069d77d1c5
commit 78fb84c4dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 84 additions and 1 deletions

View File

@ -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 {

View 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))
}