#[macro_use] extern crate prom_attire; #[macro_use] extern crate quote; extern crate syn; #[test] fn literal_string() { #[derive(PromAttire)] struct A<'a> { b: Option<&'a str>, } let input = quote! { #[b = "test"] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some("test")); } #[test] fn literal_byte_str() { #[derive(PromAttire)] struct A<'a> { b: Option<&'a [u8]>, } let input = quote! { #[b = b"test"] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(&b"test"[..])); } #[test] fn literal_char() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 'b'] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some('b')); } #[test] fn literal_u8() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_i8() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_u16() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_i16() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_u32() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_i32() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_u64() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_i64() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_usize() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_isize() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10)); } #[test] fn literal_f32() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10.01] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10.01)); } #[test] fn literal_f64() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = 10.01] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(10.01)); } #[test] fn literal_bool() { #[derive(PromAttire)] struct A { b: Option, } let input = quote! { #[b = true] struct C {} }; let ast = syn::parse_derive_input(input.as_str()).unwrap(); let attrs = A::from(ast.attrs.as_slice()); assert_eq!(attrs.b, Some(true)); }