pink_types/
js.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3
4#[derive(scale::Encode, scale::Decode, Debug, PartialEq, Eq, Clone)]
5#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
6pub enum JsCode {
7    Source(String),
8    Bytecode(Vec<u8>),
9}
10
11#[derive(scale::Encode, scale::Decode, Debug, PartialEq, Eq, Clone)]
12#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
13pub enum JsValue {
14    Undefined,
15    Null,
16    String(String),
17    Bytes(Vec<u8>),
18    Other(String),
19    Exception(String),
20}
21
22#[test]
23fn coverage() {
24    use alloc::string::ToString;
25
26    fn test<T: scale::Encode + scale::Decode + core::fmt::Debug + PartialEq + Eq + Clone>(
27        value: T,
28    ) {
29        let encoded = scale::Encode::encode(&value.clone());
30        let decoded = T::decode(&mut &encoded[..]).unwrap();
31        assert_eq!(value, decoded);
32        assert!(!alloc::format!("{value:?}").is_empty());
33    }
34    test(JsCode::Source("".to_string()));
35    test(JsCode::Bytecode(alloc::vec![]));
36    test(JsValue::Undefined);
37    test(JsValue::Null);
38    test(JsValue::String("".to_string()));
39    test(JsValue::Bytes(alloc::vec![]));
40    test(JsValue::Other("".to_string()));
41    test(JsValue::Exception("".to_string()));
42}