Remove Num.bytesTo___ functions

These may be reintroduced in some form later,
but they don't handle endianness and it's not
clear builtins are the right place for them.
This commit is contained in:
Richard Feldman 2024-01-23 12:52:34 -05:00
parent ef634ba8e4
commit 9518d76cd8
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
13 changed files with 15 additions and 530 deletions

View file

@ -2565,334 +2565,6 @@ fn is_multiple_of_unsigned() {
assert_evals_to!("Num.isMultipleOf 0xFCu8 0xFE", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u16_clearly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU16 bytes 234 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u16
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u16_subtly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU16 bytes 4 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u16
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u32_clearly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU32 bytes 234 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u32
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u32_subtly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU32 bytes 2 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u32
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u64_clearly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU64 bytes 234 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u64_subtly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello world"
when Num.bytesToU64 bytes 4 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u128_clearly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU128 bytes 234 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u128
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u128_subtly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello world!!!!!!"
when Num.bytesToU128 bytes 2 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
1,
u128
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u16_max_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU16 [255, 255] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
65535,
u16
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u16_min_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU16 [0, 0] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
0,
u16
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u16_random_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU16 [164, 215] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
55_204,
u16
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u32_min_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU32 [0, 0, 0, 0] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
0,
u32
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u32_max_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU32 [255, 255, 255, 255] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
4_294_967_295,
u32
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u32_random_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU32 [252, 124, 128, 121] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
2_038_463_740,
u32
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u64_min_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU64 [0, 0, 0, 0, 0, 0, 0, 0] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
0,
u64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u64_max_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU64 [255, 255, 255, 255, 255, 255, 255, 255] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
18_446_744_073_709_551_615,
u64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u64_random_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU64 [252, 124, 128, 121, 1, 32, 177, 211] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
15_254_008_603_586_100_476,
u64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u128_min_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU128 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
0,
u128
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u128_max_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU128 [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
340_282_366_920_938_463_463_374_607_431_768_211_455,
u128
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bytes_to_u128_random_u8s() {
assert_evals_to!(
indoc!(
r"
when Num.bytesToU128 [252, 124, 128, 121, 1, 32, 177, 211, 3, 57, 203, 122, 95, 164, 23, 145] 0 is
Ok v -> v
Err OutOfBounds -> 1
"
),
192_860_816_096_412_392_720_639_456_393_488_792_828,
u128
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn when_on_i32() {