From bd805923d1b0e1891939261188afebe12ea05d5f Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 10 Nov 2023 10:05:52 +0100 Subject: [PATCH] Add correct accronym replacement test --- packages/go-gen/src/main.rs | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/packages/go-gen/src/main.rs b/packages/go-gen/src/main.rs index 84ff3932d9..1a4f8278f2 100644 --- a/packages/go-gen/src/main.rs +++ b/packages/go-gen/src/main.rs @@ -472,4 +472,56 @@ mod tests { }"#, ); } + + #[test] + fn accronym_replacement_works() { + #[cw_serde] + struct IbcStruct { + a: IbcSubStruct, + b: IbcSubEnum, + } + #[cw_serde] + enum IbcEnum { + A(IbcSubStruct), + B(IbcSubEnum), + } + #[cw_serde] + struct IbcSubStruct {} + #[cw_serde] + enum IbcSubEnum { + A(String), + } + + let code = generate_go(cosmwasm_schema::schema_for!(IbcStruct)).unwrap(); + assert_code_eq( + code, + r#" + type IBCStruct struct { + A IBCSubStruct `json:"a"` + B IBCSubEnum `json:"b"` + } + type IBCSubEnum struct { + A string `json:"a,omitempty"` + } + type IBCSubStruct struct { + } + "#, + ); + + let code = generate_go(cosmwasm_schema::schema_for!(IbcEnum)).unwrap(); + assert_code_eq( + code, + r#" + type IBCEnum struct { + A *IBCSubStruct `json:"a,omitempty"` + B *IBCSubEnum `json:"b,omitempty"` + } + type IBCSubEnum struct { + A string `json:"a,omitempty"` + } + type IBCSubStruct struct { + } + "#, + ); + } }