Unverified Commit a3de7a27 authored by Robin Freyler's avatar Robin Freyler
Browse files

[lang] Apply rustfmt

parent 9c8a7fc6
......@@ -83,10 +83,10 @@ fn codegen_for_instantiate(tokens: &mut TokenStream, contract: &hir::Contract) {
deploy_call_args
};
let deploy_fn_args_toks = match deploy_fn_args.iter().count() {
0 => quote!{()},
0 => quote! {()},
1 => deploy_fn_args.into_token_stream(),
_ => {
let mut toks = quote!{};
let mut toks = quote! {};
syn::token::Paren::default().surround(&mut toks, |surrounded_toks| {
deploy_call_args.to_tokens(surrounded_toks)
});
......@@ -138,10 +138,10 @@ fn codegen_for_instantiate(tokens: &mut TokenStream, contract: &hir::Contract) {
};
let msg_fn_args_toks = match msg_fn_args.iter().count() {
0 => quote!{_},
0 => quote! {_},
1 => msg_fn_args.into_token_stream(),
_ => {
let mut toks = quote!{};
let mut toks = quote! {};
syn::token::Paren::default().surround(&mut toks, |surrounded_toks| {
msg_call_args.to_tokens(surrounded_toks)
});
......@@ -232,7 +232,7 @@ fn codegen_for_message_impls(tokens: &mut TokenStream, contract: &hir::Contract)
fn codegen_for_method_impls(tokens: &mut TokenStream, contract: &hir::Contract) {
let state_name = &contract.name;
let methods_impls = {
let mut content = quote!{};
let mut content = quote! {};
for method in contract.methods.iter() {
for attr in &method.attrs {
attr.to_tokens(&mut content)
......
......@@ -129,14 +129,16 @@ impl Contract {
"contract messages must operate on `&self` or `&mut self`"
)
}
Some(self_ty) => match self_ty {
ast::FnArg::SelfValue(_) | ast::FnArg::Captured(_) => {
bail!(
Some(self_ty) => {
match self_ty {
ast::FnArg::SelfValue(_) | ast::FnArg::Captured(_) => {
bail!(
self_ty,
"contract messages must operate on `&self` or `&mut self`"
)
}
_ => (),
}
_ => (),
}
}
}
......
......@@ -55,7 +55,9 @@ fn contract_gen_impl(input: proc_macro::TokenStream) -> Result<proc_macro::Token
/// Parses the given token stream as pDSL contract, performs some checks and returns
/// the corresponding contract as token stream.
pub(crate) fn contract_gen_impl2(input: proc_macro2::TokenStream) -> Result<proc_macro2::TokenStream> {
pub(crate) fn contract_gen_impl2(
input: proc_macro2::TokenStream,
) -> Result<proc_macro2::TokenStream> {
let ast_contract = parser::parse_contract(input.clone())?;
let hir_contract = hir::Contract::from_ast(&ast_contract)?;
// gen::gir::generate(&hir_program)?;
......
......@@ -3,7 +3,7 @@ use super::*;
#[test]
fn incrementer_contract() {
assert_eq_tokenstreams(
quote!{
quote! {
/// A simple contract that has a value that can be
/// incremented, returned and compared.
struct Incrementer {
......@@ -35,7 +35,7 @@ fn incrementer_contract() {
}
}
},
quote!{
quote! {
pdsl_model::state! {
/// A simple contract that has a value that can be
/// incremented, returned and compared.
......@@ -104,6 +104,6 @@ fn incrementer_contract() {
#[no_mangle] fn deploy() { instantiate().deploy() }
#[no_mangle] fn call() { instantiate().dispatch() }
}
},
)
}
mod utils;
mod noop;
mod incrementer;
mod noop;
mod utils;
pub(crate) use crate::contract_gen_impl2;
pub(crate) use quote::quote;
pub(crate) use utils::{
assert_eq_tokenstreams,
assert_failure,
};
pub(crate) use crate::contract_gen_impl2;
#[test]
fn empty_contract_input() {
assert!(contract_gen_impl2(quote!{}).is_err());
assert!(contract_gen_impl2(quote! {}).is_err());
}
#[test]
fn using_self_val_in_message() {
assert_failure(
quote!{
quote! {
struct TestContract {}
impl Deploy for TestContract {
fn deploy(&mut self) {}
......@@ -26,14 +26,14 @@ fn using_self_val_in_message() {
pub(external) fn with_self_value(self) {}
}
},
"contract messages must operate on `&self` or `&mut self`"
"contract messages must operate on `&self` or `&mut self`",
)
}
#[test]
fn using_non_self_in_message() {
assert_failure(
quote!{
quote! {
struct TestContract {}
impl Deploy for TestContract {
fn deploy(&mut self) {}
......@@ -42,14 +42,14 @@ fn using_non_self_in_message() {
pub(external) fn with_self_value(not_self: u32) {}
}
},
"contract messages must operate on `&self` or `&mut self`"
"contract messages must operate on `&self` or `&mut self`",
)
}
#[test]
fn using_empty_message_args() {
assert_failure(
quote!{
quote! {
struct TestContract {}
impl Deploy for TestContract {
fn deploy(&mut self) {}
......@@ -58,48 +58,48 @@ fn using_empty_message_args() {
pub(external) fn with_self_value() {}
}
},
"contract messages must operate on `&self` or `&mut self`"
"contract messages must operate on `&self` or `&mut self`",
)
}
#[test]
fn using_self_val_in_deploy() {
assert_failure(
quote!{
quote! {
struct TestContract {}
impl Deploy for TestContract {
fn deploy(self) {}
}
impl TestContract {}
},
"the deploy implementation must operate on `&mut self`"
"the deploy implementation must operate on `&mut self`",
)
}
#[test]
fn using_self_ref_in_deploy() {
assert_failure(
quote!{
quote! {
struct TestContract {}
impl Deploy for TestContract {
fn deploy(&self) {}
}
impl TestContract {}
},
"the deploy implementation must operate on `&mut self`"
"the deploy implementation must operate on `&mut self`",
)
}
#[test]
fn missing_state_in_contract() {
assert_failure(
quote!{
quote! {
impl Deploy for TestContract {
fn deploy(self) {}
}
impl TestContract {}
},
"couldn't find a contract state `struct`"
"couldn't find a contract state `struct`",
)
}
......@@ -110,7 +110,7 @@ fn missing_deploy_impl_block() {
struct TestContract {}
impl TestContract {}
},
"couldn't find a contract deploy implementation; requires exactly one"
"couldn't find a contract deploy implementation; requires exactly one",
)
}
......@@ -123,7 +123,7 @@ fn env_as_deploy_handler_arg() {
fn deploy(&mut self, env: u32) {}
}
},
"the deploy implementation must not contain an argument named `env`"
"the deploy implementation must not contain an argument named `env`",
)
}
......@@ -136,7 +136,7 @@ fn generic_deploy_handler() {
fn deploy<T>(&mut self, generic_param: T) {}
}
},
"expected parentheses" // The check for this is built into the parser.
"expected parentheses", // The check for this is built into the parser.
)
}
......@@ -149,7 +149,7 @@ fn deploy_handler_with_return_type() {
fn deploy(&mut self) -> u32 {}
}
},
"the deploy implementation must not have a return type"
"the deploy implementation must not have a return type",
)
}
......@@ -165,7 +165,7 @@ fn env_as_message_arg() {
pub(external) fn test_message(&self, env: u32) {}
}
},
"contract messages must not contain an argument called `env`"
"contract messages must not contain an argument called `env`",
)
}
......@@ -181,7 +181,7 @@ fn message_called_deploy() {
pub(external) fn deploy(&mut self) {}
}
},
"contract messages must not be named `deploy`"
"contract messages must not be named `deploy`",
)
}
......@@ -197,7 +197,7 @@ fn method_called_deploy() {
fn deploy(&mut self) {}
}
},
"contract methods must not be named `deploy`"
"contract methods must not be named `deploy`",
)
}
......@@ -214,7 +214,7 @@ fn multiple_states() {
fn deploy(&mut self) {}
}
},
"requires exactly one contract state `struct`; found 2"
"requires exactly one contract state `struct`; found 2",
)
}
......@@ -230,6 +230,6 @@ fn multiple_deploy_handlers() {
fn deploy(&mut self) {}
}
},
"found more than one contract deploy implementation for TestContract"
"found more than one contract deploy implementation for TestContract",
)
}
......@@ -3,7 +3,7 @@ use super::*;
#[test]
fn noop_contract() {
assert_eq_tokenstreams(
quote!{
quote! {
/// The contract that does nothing.
///
/// # Note
......@@ -19,7 +19,7 @@ fn noop_contract() {
/// Provides no way to call it as extrinsic.
impl Noop {}
},
quote!{
quote! {
pdsl_model::state! {
/// The contract that does nothing.
///
......@@ -51,6 +51,6 @@ fn noop_contract() {
#[no_mangle] fn deploy() { instantiate().deploy() }
#[no_mangle] fn call() { instantiate().dispatch() }
}
},
)
}
......@@ -12,10 +12,7 @@ pub fn assert_eq_tokenstreams(
)
}
pub fn assert_failure(
input: proc_macro2::TokenStream,
err_str: &'static str,
) {
pub fn assert_failure(input: proc_macro2::TokenStream, err_str: &'static str) {
assert_eq!(
contract_gen_impl2(input)
.map(|result| result.to_string())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment