Skip to content

Commit

Permalink
schema-derive: add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uint committed Jun 29, 2022
1 parent e279d8a commit 1a66e17
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/schema-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn parse_query(v: Variant) -> TokenStream {
}

fn to_snake_case(input: &str) -> String {
// this was stolen from serde for consistent behavior
let mut snake = String::new();
for (i, ch) in input.char_indices() {
if i > 0 && ch.is_uppercase() {
Expand Down Expand Up @@ -52,3 +53,39 @@ pub fn query_responses_derive(input: proc_macro::TokenStream) -> proc_macro::Tok

proc_macro::TokenStream::from(expanded)
}

#[cfg(tests)]
mod tests {
use syn::parse_quote;

use super::*;

#[test]
fn parse_query() {
let variant = parse_quote! {
#[returns(Foo)]
GetFoo {},
};

assert_eq!(
parse_query(variant),
quote! { ("get_foo", cosmwasm_schema::schema_for!(Foo)) }
);

let variant = parse_quote! {
#[returns(some_crate::Foo)]
GetFoo {},
};

assert_eq!(
parse_query(variant),
quote! { ("get_foo", cosmwasm_schema::schema_for!(some_crate::Foo)) }
);
}

#[test]
fn to_snake_case() {
assert_eq!(to_snake_case("SnakeCase"), "snake_case");
assert_eq!(to_snake_case("Wasm123AndCo"), "wasm123_and_co");
}
}

0 comments on commit 1a66e17

Please sign in to comment.