///|
test "basic int operations" {
// Get absolute value
inspect(Int::abs(-42), content="42")
inspect(Int::abs(42), content="42")
// Access min/max values
inspect(@int.MIN_VALUE, content="-2147483648")
inspect(@int.MAX_VALUE, content="2147483647")
}///|
test "byte conversions" {
let num = 258 // 0x0102 in hex
// Big-endian conversion (most significant byte first)
let buf = Buffer()
buf.write_int_be(num)
let be_bytes = buf.contents()
inspect(
be_bytes.to_string(),
content=(
#|b"\x00\x00\x01\x02"
),
)
// Little-endian conversion (least significant byte first)
buf.reset() // reset the position of the buffer
buf.write_int_le(num)
let le_bytes = buf.contents()
inspect(
le_bytes.to_string(),
content=(
#|b"\x02\x01\x00\x00"
),
)
}///|
test "method syntax" {
let n = -42
// Using method syntax
inspect(n.abs(), content="42")
// Byte conversions using method syntax
let buf = Buffer()
buf.write_int_be(n)
let be = buf.contents()
buf.reset()
buf.write_int_le(n)
let le = buf.contents()
inspect(
be.to_string(),
content=(
#|b"\xff\xff\xff\xd6"
),
)
inspect(
le.to_string(),
content=(
#|b"\xd6\xff\xff\xff"
),
)
}#deprecated("Use `MAX_VALUE` instead")
let max_value : Int#deprecated("Use `MIN_VALUE` instead")
let min_value : IntInstall
Installed by default