Skip to content

Commit

Permalink
Test JSON serialization before types
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeckwith committed Aug 5, 2023
1 parent 4aba06d commit 3e239dc
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,6 @@ export type Test10=({"type":"A";"value":(types.Parent&{"a":string;"b":types.Usiz
D,
}

assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=(({"type":"A";}&{"a":types.Inner;})|({"type":"B";}&types.Inner)|{"type":"D";});
}
"#
);
assert_eq_str!(
serde_json::to_string(&Test::A { a: INNER }).unwrap(),
r#"{"type":"A","a":{"x":true}}"#
Expand All @@ -269,6 +260,15 @@ export type Test=(({"type":"A";}&{"a":types.Inner;})|({"type":"B";}&types.Inner)
serde_json::to_string(&Test::D).unwrap(),
r#"{"type":"D"}"#
);
assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=(({"type":"A";}&{"a":types.Inner;})|({"type":"B";}&types.Inner)|{"type":"D";});
}
"#
);
}

#[test]
Expand All @@ -282,15 +282,6 @@ export type Test=(({"type":"A";}&{"a":types.Inner;})|({"type":"B";}&types.Inner)
D,
}

assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=({"type":"A";"value":{"a":types.Inner;};}|{"type":"B";"value":types.Inner;}|{"type":"C";"value":[types.Inner,types.Inner];}|{"type":"D";});
}
"#
);
assert_eq_str!(
serde_json::to_string(&Test::A { a: INNER }).unwrap(),
r#"{"type":"A","value":{"a":{"x":true}}}"#
Expand All @@ -307,6 +298,15 @@ export type Test=({"type":"A";"value":{"a":types.Inner;};}|{"type":"B";"value":t
serde_json::to_string(&Test::D).unwrap(),
r#"{"type":"D"}"#
);
assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=({"type":"A";"value":{"a":types.Inner;};}|{"type":"B";"value":types.Inner;}|{"type":"C";"value":[types.Inner,types.Inner];}|{"type":"D";});
}
"#
);
}

#[test]
Expand All @@ -320,15 +320,6 @@ export type Test=({"type":"A";"value":{"a":types.Inner;};}|{"type":"B";"value":t
D,
}

assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=({"a":types.Inner;}|types.Inner|[types.Inner,types.Inner]|null);
}
"#
);
assert_eq_str!(
serde_json::to_string(&Test::A { a: INNER }).unwrap(),
r#"{"a":{"x":true}}"#
Expand All @@ -342,6 +333,15 @@ export type Test=({"a":types.Inner;}|types.Inner|[types.Inner,types.Inner]|null)
r#"[{"x":true},{"x":true}]"#
);
assert_eq_str!(serde_json::to_string(&Test::D).unwrap(), r#"null"#);
assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=({"a":types.Inner;}|types.Inner|[types.Inner,types.Inner]|null);
}
"#
);
}

#[test]
Expand All @@ -354,15 +354,6 @@ export type Test=({"a":types.Inner;}|types.Inner|[types.Inner,types.Inner]|null)
D,
}

assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=({"A":{"a":types.Inner;};}|{"B":types.Inner;}|{"C":[types.Inner,types.Inner];}|"D");
}
"#
);
assert_eq_str!(
serde_json::to_string(&Test::A { a: INNER }).unwrap(),
r#"{"A":{"a":{"x":true}}}"#
Expand All @@ -376,6 +367,15 @@ export type Test=({"A":{"a":types.Inner;};}|{"B":types.Inner;}|{"C":[types.Inner
r#"{"C":[{"x":true},{"x":true}]}"#
);
assert_eq_str!(serde_json::to_string(&Test::D).unwrap(), r#""D""#);
assert_eq_str!(
test_emit::<Test>(),
r#"export default types;
export namespace types{
export type Inner={"x":boolean;};
export type Test=({"A":{"a":types.Inner;};}|{"B":types.Inner;}|{"C":[types.Inner,types.Inner];}|"D");
}
"#
);
}
}

Expand Down Expand Up @@ -488,15 +488,6 @@ export type Test=({
r#variant2 { r#field: r#struct },
}

assert_eq_str!(
test_emit::<r#enum>(),
r#"export default types;
export namespace types{
export type struct={"field":string;};
export type enum=("variant1"|{"variant2":{"field":types.struct;};});
}
"#
);
assert_eq_str!(
serde_json::to_string(&r#enum::r#variant1).unwrap(),
r#""variant1""#
Expand All @@ -510,6 +501,15 @@ export type enum=("variant1"|{"variant2":{"field":types.struct;};});
.unwrap(),
r#"{"variant2":{"field":{"field":"foo"}}}"#
);
assert_eq_str!(
test_emit::<r#enum>(),
r#"export default types;
export namespace types{
export type struct={"field":string;};
export type enum=("variant1"|{"variant2":{"field":types.struct;};});
}
"#
);
}

#[test]
Expand Down

0 comments on commit 3e239dc

Please sign in to comment.