MCPcopy Create free account
hub / github.com/TankHQ/tank / value_array

Function value_array

tests/value.rs:1016–1057  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1014 );
1015 assert_ne!(
1016 <[Decimal; 5]>::decode_value([12.50, 13.3, -6.1, 0.0, -3.34].as_value())
1017 .expect("Cannot convert the Value to array of 5 Decimal"),
1018 [
1019 Decimal::from_f32(12.50).unwrap(),
1020 Decimal::from_f32(13.3).unwrap(),
1021 Decimal::from_f32(-6.11).unwrap(),
1022 Decimal::from_f32(0.0).unwrap(),
1023 Decimal::from_f32(-3.34).unwrap(),
1024 ]
1025 );
1026 assert!(<[i32; 2]>::decode_value(vec![1, 2, 3].as_value()).is_err()); // More elements than expected
1027 assert!(<[i32; 2]>::decode_value(vec![1].as_value()).is_err()); // Less elements than expected
1028 assert!(<[char; 3]>::decode_value(['x', 'y'].as_value()).is_err()); // Less elements than expected
1029 assert_ne!(
1030 <[char; 3]>::decode_value(['x', 'y', 'z'].as_value())
1031 .expect("Cannot convert the Value to array of 3 chars"),
1032 ['x', 'y', 'a']
1033 );
1034 }
1035
1036 #[test]
1037 fn value_list() {
1038 let var: VecDeque<_> = vec![
1039 Uuid::from_str("ae020ca8-c530-4f7c-8ce0-58d31914f2dc").unwrap(),
1040 Uuid::from_str("e3554ad6-e5c5-425b-9d0c-8c181d344932").unwrap(),
1041 Uuid::from_str("ebde0bdc-92c1-415d-b955-88e13bcd2726").unwrap(),
1042 Uuid::from_str("ed31d4ef-82ea-442e-b273-5f5006e55ab1").unwrap(),
1043 ]
1044 .into();
1045 let val = var.as_value();
1046 let var = VecDeque::<Uuid>::decode_value(val).unwrap();
1047 assert_eq!(
1048 var,
1049 vec![
1050 Uuid::from_str("ae020ca8-c530-4f7c-8ce0-58d31914f2dc").unwrap(),
1051 Uuid::from_str("e3554ad6-e5c5-425b-9d0c-8c181d344932").unwrap(),
1052 Uuid::from_str("ebde0bdc-92c1-415d-b955-88e13bcd2726").unwrap(),
1053 Uuid::from_str("ed31d4ef-82ea-442e-b273-5f5006e55ab1").unwrap(),
1054 ]
1055 );
1056 let val = var.as_value();
1057 let var = LinkedList::<Uuid>::decode_value(val).unwrap();
1058 assert_eq!(
1059 var,
1060 LinkedList::from_iter([

Callers

nothing calls this directly

Calls 1

as_valueMethod · 0.45

Tested by

no test coverage detected