-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* js-sys: Fix `BigInt::from(usize)` and `BigInt::from(isize)` Fixes #3055 This changes `isize` and `usize` to be converted to `BigInt` in the same way as `i32`/`u32`, `BigInt(JsValue::from(n))`, rather than `JsValue::from(n).unchecked_into()`. The latter is now wrong since as of #2978 that `JsValue::from` returns a `Number`, not a `BigInt`. * Add a regression test * fmt
- Loading branch information
1 parent
c890dc3
commit f75a3f8
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use js_sys::BigInt; | ||
use wasm_bindgen::prelude::*; | ||
use wasm_bindgen_test::wasm_bindgen_test; | ||
|
||
/// `assert_eq!`, but the arguments are converted to `JsValue`s. | ||
#[track_caller] | ||
fn assert_jsvalue_eq(a: impl Into<JsValue>, b: impl Into<JsValue>) { | ||
assert_eq!(a.into(), b.into()); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
fn from() { | ||
// Test that all the `From` impls work properly. | ||
assert_jsvalue_eq(BigInt::from(1u8), 1u64); | ||
assert_jsvalue_eq(BigInt::from(1u16), 1u64); | ||
assert_jsvalue_eq(BigInt::from(1u32), 1u64); | ||
assert_jsvalue_eq(BigInt::from(1u64), 1u64); | ||
assert_jsvalue_eq(BigInt::from(1u128), 1u64); | ||
assert_jsvalue_eq(BigInt::from(1usize), 1u64); | ||
assert_jsvalue_eq(BigInt::from(-3i8), -3i64); | ||
assert_jsvalue_eq(BigInt::from(-3i16), -3i64); | ||
assert_jsvalue_eq(BigInt::from(-3i32), -3i64); | ||
assert_jsvalue_eq(BigInt::from(-3i64), -3i64); | ||
assert_jsvalue_eq(BigInt::from(-3i128), -3i64); | ||
assert_jsvalue_eq(BigInt::from(-3isize), -3i64); | ||
} | ||
|
||
#[wasm_bindgen_test] | ||
fn eq() { | ||
// Test that all the `Eq` impls work properly. | ||
assert_eq!(BigInt::from(1u64), 1u8); | ||
assert_eq!(BigInt::from(1u64), 1u16); | ||
assert_eq!(BigInt::from(1u64), 1u32); | ||
assert_eq!(BigInt::from(1u64), 1u64); | ||
assert_eq!(BigInt::from(1u64), 1u128); | ||
assert_eq!(BigInt::from(1u64), 1usize); | ||
assert_eq!(BigInt::from(-3i64), -3i8); | ||
assert_eq!(BigInt::from(-3i64), -3i16); | ||
assert_eq!(BigInt::from(-3i64), -3i32); | ||
assert_eq!(BigInt::from(-3i64), -3i64); | ||
assert_eq!(BigInt::from(-3i64), -3i128); | ||
assert_eq!(BigInt::from(-3i64), -3isize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters