mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-31 17:17:26 +00:00
Merge remote-tracking branch 'origin/main' into remove-nat
This commit is contained in:
commit
aabd95404f
104 changed files with 1031 additions and 651 deletions
|
@ -910,6 +910,25 @@ fn list_prepend_big_list() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn list_prepend_record() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
payment1 : { amount: Dec, date: [RD I32] }
|
||||
payment1 = { amount: 1dec, date: (RD 1000) }
|
||||
payment2 : { amount: Dec, date: [RD I32] }
|
||||
payment2 = { amount: 2dec, date: (RD 1001) }
|
||||
|
||||
List.prepend [payment2] payment1
|
||||
"
|
||||
),
|
||||
RocList::from_slice(&[(RocDec::from(1), 1000i32), (RocDec::from(2), 1001i32),]),
|
||||
RocList<(RocDec, i32)>
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn list_walk_backwards_empty_all_inline() {
|
||||
|
|
|
@ -1154,19 +1154,20 @@ fn gen_div_u64() {
|
|||
assert_evals_to!("1000u64 // 10", 100, u64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
#[should_panic(expected = r#"User crash with message: "Integer division by 0!"#)]
|
||||
fn gen_div_by_zero_i64() {
|
||||
assert_evals_to!("1i64 // 0", 100, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn gen_div_checked_i64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
when Num.divTruncChecked 1000 10 is
|
||||
Ok val -> val
|
||||
Err _ -> -1
|
||||
"
|
||||
),
|
||||
100,
|
||||
i64
|
||||
"Num.divTruncChecked 1000 10",
|
||||
RocResult::ok(100),
|
||||
RocResult<i64, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1174,15 +1175,9 @@ fn gen_div_checked_i64() {
|
|||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn gen_div_checked_by_zero_i64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
when Num.divTruncChecked 1000 0 is
|
||||
Err DivByZero -> 99
|
||||
_ -> -24
|
||||
"
|
||||
),
|
||||
99,
|
||||
i64
|
||||
"Num.divTruncChecked 1000 0",
|
||||
RocResult::err(()),
|
||||
RocResult<i64, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1192,19 +1187,30 @@ fn gen_rem_i64() {
|
|||
assert_evals_to!("Num.rem 8 3", 2, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
#[should_panic(expected = r#"User crash with message: "Integer division by 0!"#)]
|
||||
fn gen_rem_div_by_zero_i64() {
|
||||
assert_evals_to!("Num.rem 42 0", 100, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn gen_rem_checked_i64() {
|
||||
assert_evals_to!(
|
||||
"Num.remChecked 42 40",
|
||||
RocResult::ok(2),
|
||||
RocResult<i64, ()>
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn gen_rem_checked_div_by_zero_i64() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r"
|
||||
when Num.remChecked 8 0 is
|
||||
Err DivByZero -> 4
|
||||
Ok _ -> -23
|
||||
"
|
||||
),
|
||||
4,
|
||||
i64
|
||||
"Num.remChecked 8 0",
|
||||
RocResult::err(()),
|
||||
RocResult<i64, ()>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1825,15 +1831,56 @@ fn pow() {
|
|||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn ceiling() {
|
||||
assert_evals_to!("Num.ceiling 1.1f64", 2, i64);
|
||||
fn round_f64() {
|
||||
assert_evals_to!("Num.round 1.9f64", 2, i64);
|
||||
assert_evals_to!("Num.round -1.9f64", -2, i64);
|
||||
assert_evals_to!("Num.round 0.5f64", 1, i64);
|
||||
assert_evals_to!("Num.round -0.5f64", -1, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn floor() {
|
||||
fn round_dec() {
|
||||
assert_evals_to!("Num.round 1.9dec", 2, i64);
|
||||
assert_evals_to!("Num.round -1.9dec", -2, i64);
|
||||
assert_evals_to!("Num.round 0.5dec", 1, i64);
|
||||
assert_evals_to!("Num.round -0.5dec", -1, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn ceiling_f64() {
|
||||
assert_evals_to!("Num.ceiling 1.9f64", 2, i64);
|
||||
assert_evals_to!("Num.ceiling -1.9f64", -1, i64);
|
||||
assert_evals_to!("Num.ceiling 0.5f64", 1, i64);
|
||||
assert_evals_to!("Num.ceiling -0.5f64", 0, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn ceiling_dec() {
|
||||
assert_evals_to!("Num.ceiling 1.9dec", 2, i64);
|
||||
assert_evals_to!("Num.ceiling -1.9dec", -1, i64);
|
||||
assert_evals_to!("Num.ceiling 0.5dec", 1, i64);
|
||||
assert_evals_to!("Num.ceiling -0.5dec", 0, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn floor_f64() {
|
||||
assert_evals_to!("Num.floor 1.9f64", 1, i64);
|
||||
assert_evals_to!("Num.floor -1.9f64", -2, i64);
|
||||
assert_evals_to!("Num.floor 0.5f64", 0, i64);
|
||||
assert_evals_to!("Num.floor -0.5f64", -1, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
||||
fn floor_dec() {
|
||||
assert_evals_to!("Num.floor 1.9dec", 1, i64);
|
||||
assert_evals_to!("Num.floor -1.9dec", -2, i64);
|
||||
assert_evals_to!("Num.floor 0.5dec", 0, i64);
|
||||
assert_evals_to!("Num.floor -0.5dec", -1, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -91,15 +91,11 @@ impl<T: FromWasm32Memory + Clone> FromWasm32Memory for RocList<T> {
|
|||
let capacity =
|
||||
<u32 as FromWasm32Memory>::decode(memory, offset + 4 * Builtin::WRAPPER_CAPACITY);
|
||||
|
||||
let mut items = Vec::with_capacity(length as usize);
|
||||
let step = <T as Wasm32Sized>::SIZE_OF_WASM;
|
||||
|
||||
for i in 0..length {
|
||||
let item = <T as FromWasm32Memory>::decode(
|
||||
memory,
|
||||
elements + i * <T as Wasm32Sized>::SIZE_OF_WASM as u32,
|
||||
);
|
||||
items.push(item);
|
||||
}
|
||||
let items: Vec<_> = (0..length)
|
||||
.map(|i| <T as FromWasm32Memory>::decode(memory, elements + i * step as u32))
|
||||
.collect();
|
||||
|
||||
let mut list = RocList::with_capacity(capacity as usize);
|
||||
list.extend_from_slice(&items);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue