builtin: add `.str` method for `i/usize` (#11441)
parent
e3b65092d6
commit
56ad5d72ef
|
@ -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()
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue