MCPcopy Create free account
hub / github.com/cel-rust/cel-rust / test_json_data_conversion

Function test_json_data_conversion

cel/src/ser.rs:1010–1085  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1008
1009 #[test]
1010 fn test_json_data_conversion() {
1011 #[derive(Serialize)]
1012 struct TestPrimitives {
1013 bool: bool,
1014 u8: u8,
1015 u16: u16,
1016 u32: u32,
1017 u64: u64,
1018 int8: i8,
1019 int16: i16,
1020 int32: i32,
1021 int64: i64,
1022 f32: f32,
1023 f64: f64,
1024 char: char,
1025 string: String,
1026 bytes: &'static Bytes,
1027 }
1028
1029 let test = TestPrimitives {
1030 bool: true,
1031 int8: 8_i8,
1032 int16: 16_i16,
1033 int32: 32_i32,
1034 int64: 64_i64,
1035 u8: 8_u8,
1036 u16: 16_u16,
1037 u32: 32_u32,
1038 u64: 64_u64,
1039 f32: 0.32_f32,
1040 f64: 0.64_f64,
1041 char: 'a',
1042 string: "string".to_string(),
1043 bytes: Bytes::new(&[1_u8, 1_u8, 1_u8, 1_u8]),
1044 };
1045
1046 let serialized = to_value(test).unwrap();
1047 let expected: Value = HashMap::from_iter([
1048 (Key::String(Arc::new("bool".to_string())), Value::Bool(true)),
1049 (Key::String(Arc::new("int8".to_string())), Value::Int(8)),
1050 (Key::String(Arc::new("int16".to_string())), Value::Int(16)),
1051 (Key::String(Arc::new("int32".to_string())), Value::Int(32)),
1052 (Key::String(Arc::new("int64".to_string())), Value::Int(64)),
1053 (Key::String(Arc::new("u8".to_string())), Value::UInt(8)),
1054 (Key::String(Arc::new("u16".to_string())), Value::UInt(16)),
1055 (Key::String(Arc::new("u32".to_string())), Value::UInt(32)),
1056 (Key::String(Arc::new("u64".to_string())), Value::UInt(64)),
1057 (
1058 Key::String(Arc::new("f32".to_string())),
1059 Value::Float(f64::from(0.32_f32)),
1060 ),
1061 (Key::String(Arc::new("f64".to_string())), Value::Float(0.64)),
1062 (
1063 Key::String(Arc::new("char".to_string())),
1064 Value::String(Arc::new("a".to_string())),
1065 ),
1066 (
1067 Key::String(Arc::new("string".to_string())),

Callers

nothing calls this directly

Calls 8

to_valueFunction · 0.85
StringClass · 0.85
BoolClass · 0.85
IntClass · 0.85
UIntClass · 0.85
BytesClass · 0.85
add_variableMethod · 0.80
executeMethod · 0.80

Tested by

no test coverage detected