summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen/tests/wasm/truthy_falsy.rs
blob: 83657ca0adbc89edfb76b338e9874f0a24478325 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;

#[wasm_bindgen_test]
fn test_is_truthy() {
    assert!(!JsValue::from(0).is_truthy());
    assert!(!JsValue::from("".to_string()).is_truthy());
    assert!(!JsValue::from(false).is_truthy());
    assert!(!JsValue::NULL.is_truthy());
    assert!(!JsValue::UNDEFINED.is_truthy());

    assert!(JsValue::from(10).is_truthy());
    assert!(JsValue::from("null".to_string()).is_truthy());
    assert!(JsValue::from(true).is_truthy());
}

#[wasm_bindgen_test]
fn test_is_falsy() {
    assert!(JsValue::from(0).is_falsy());
    assert!(JsValue::from("".to_string()).is_falsy());
    assert!(JsValue::from(false).is_falsy());
    assert!(JsValue::NULL.is_falsy());
    assert!(JsValue::UNDEFINED.is_falsy());

    assert!(!JsValue::from(10).is_falsy());
    assert!(!JsValue::from("null".to_string()).is_falsy());
    assert!(!JsValue::from(true).is_falsy());
}