Fix wiggle tests
This commit is contained in:
committed by
Andrew Brown
parent
df9c725fa0
commit
fa98f0bc91
@@ -6,8 +6,9 @@ mod module_trait;
|
||||
mod names;
|
||||
mod types;
|
||||
|
||||
use heck::ShoutySnakeCase;
|
||||
use lifetimes::anon_lifetime;
|
||||
use proc_macro2::TokenStream;
|
||||
use proc_macro2::{Literal, TokenStream};
|
||||
use quote::quote;
|
||||
|
||||
pub use config::Config;
|
||||
@@ -24,6 +25,19 @@ pub fn generate(doc: &witx::Document, names: &Names, errs: &ErrorTransform) -> T
|
||||
|
||||
let types = doc.typenames().map(|t| define_datatype(&names, &t));
|
||||
|
||||
let constants = doc.constants().map(|c| {
|
||||
let name = quote::format_ident!(
|
||||
"{}_{}",
|
||||
c.ty.as_str().to_shouty_snake_case(),
|
||||
c.name.as_str().to_shouty_snake_case()
|
||||
);
|
||||
let ty = names.type_(&c.ty);
|
||||
let value = Literal::u64_unsuffixed(c.value);
|
||||
quote! {
|
||||
pub const #name: #ty = #value;
|
||||
}
|
||||
});
|
||||
|
||||
let guest_error_methods = doc.error_types().map(|t| {
|
||||
let typename = names.type_ref(&t, anon_lifetime());
|
||||
let err_method = names.guest_error_conversion_method(&t);
|
||||
@@ -69,6 +83,7 @@ pub fn generate(doc: &witx::Document, names: &Names, errs: &ErrorTransform) -> T
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#(#types)*
|
||||
#(#constants)*
|
||||
#guest_error_conversion
|
||||
#user_error_conversion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user