MCPcopy Create free account
hub / github.com/apache/fory / basic

Function basic

rust/tests/tests/test_enum.rs:25–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23
24#[test]
25fn basic() {
26 #[derive(ForyUnion, Debug, PartialEq)]
27 enum Token {
28 #[fory(default)]
29 Plus,
30 Number(i64),
31 Ident(String),
32 Assign {
33 target: String,
34 value: i32,
35 },
36 Other(Option<i64>),
37 Child(Box<Token>),
38 Map(HashMap<String, Token>),
39 }
40
41 let mut fory = Fory::builder().xlang(false).compatible(false).build();
42 fory.register::<Token>(1000).unwrap();
43
44 let mut map = HashMap::new();
45 map.insert("one".to_string(), Token::Number(1));
46 map.insert("plus".to_string(), Token::Plus);
47 map.insert(
48 "nested".to_string(),
49 Token::Child(Box::new(Token::Ident("deep".to_string()))),
50 );
51
52 let tokens = vec![
53 Token::Plus,
54 Token::Number(1),
55 Token::Ident("foo".to_string()),
56 Token::Assign {
57 target: "bar".to_string(),
58 value: 42,
59 },
60 Token::Other(Some(42)),
61 Token::Other(None),
62 Token::Child(Box::from(Token::Child(Box::from(Token::Other(None))))),
63 Token::Map(map),
64 ];
65 let bin = fory.serialize(&tokens).unwrap();
66 let new_tokens = fory.deserialize::<Vec<Token>>(&bin).unwrap();
67 assert_eq!(tokens, new_tokens);
68}
69
70#[test]
71fn named_enum() {

Callers

nothing calls this directly

Calls 8

NumberClass · 0.85
ChildClass · 0.85
serializeMethod · 0.65
buildMethod · 0.45
compatibleMethod · 0.45
xlangMethod · 0.45
unwrapMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected