builtin: add `.str` method for `i/usize` (#11441)

pull/11444/head
Enzo 2021-09-08 12:41:08 +02:00 committed by GitHub
parent e3b65092d6
commit 56ad5d72ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 28 deletions

View File

@ -15,14 +15,13 @@ pub fn ptr_str(ptr voidptr) string {
return buf1
}
// TODO uncomment to have string representation of i/usize
// pub fn (x isize) str() string {
// return u64(x).str()
// }
//
// pub fn (x usize) str() string {
// return u64(x).str()
// }
pub fn (x isize) str() string {
return i64(x).str()
}
pub fn (x usize) str() string {
return u64(x).str()
}
pub fn (x size_t) str() string {
return u64(x).str()

View File

@ -1,36 +1,22 @@
fn f(u usize) usize
fn g(i isize) isize
// TODO refactor once `str` method is implemented
fn test_usize() {
mut u := usize(3)
u += u32(1)
// assert u == 4
if u != 4 {
assert false
}
assert u == 4
u = 4
u++
// assert u == 5
if u != 5 {
assert false
}
// assert u.str() == '5'
assert u == 5
assert u.str() == '5'
}
fn test_isize() {
mut i := isize(-3)
i -= int(1)
// assert i == -4
if i != -4 {
assert false
}
assert i == -4
i = -5
i += 2
// assert i == -3
if i != -3 {
assert false
}
// assert i.str() == '-2'
assert i == -3
assert i.str() == '-3'
}