swc/common/tests/ast_serde.rs
강동윤 8222cc075d
feat(ast_node): Add #[ast_serde] (#1595)
ast_node:
 - Add `#[ast_serde]`.
2021-04-21 09:11:50 +00:00

25 lines
447 B
Rust

use serde_json::from_str;
use swc_common::ast_serde;
#[ast_serde]
#[derive(Debug, PartialEq)]
pub enum Ambiguous {
#[tag("A")]
A(A),
#[tag("B")]
B(B),
}
#[ast_serde("B")]
#[derive(Debug, PartialEq)]
pub struct A {}
#[ast_serde("B")]
#[derive(Debug, PartialEq)]
pub struct B {}
#[test]
fn deserialize() {
assert_eq!(A {}, from_str(r#"{"type": "A"}"#).unwrap());
assert_eq!(B {}, from_str(r#"{"type": "B"}"#).unwrap());
}