Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
ink
Commits
f08d790b
Unverified
Commit
f08d790b
authored
Mar 14, 2019
by
Robin Freyler
Browse files
[lang] Add test framework and add noop contract test
parent
2aca9167
Changes
4
Hide whitespace changes
Inline
Side-by-side
lang/src/lib.rs
View file @
f08d790b
...
...
@@ -37,6 +37,9 @@ mod hir;
mod
ident_ext
;
mod
parser
;
#[cfg(test)]
mod
tests
;
use
errors
::
Result
;
/// Simple wrapper from `proc_macro` to `proc_macro2` and back again.
...
...
@@ -52,16 +55,10 @@ 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.
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)?;
let
tokens
=
gen
::
codegen
(
&
hir_contract
);
Ok
(
tokens
.into
())
}
#[test]
fn
empty_contract_input
()
{
use
quote
::
quote
;
assert!
(
contract_gen_impl2
(
quote!
{})
.is_err
());
}
lang/src/tests/mod.rs
0 → 100644
View file @
f08d790b
mod
utils
;
mod
noop
;
pub
(
crate
)
use
quote
::
quote
;
pub
(
crate
)
use
utils
::
assert_eq_tokenstreams
;
pub
(
crate
)
use
crate
::
contract_gen_impl2
;
#[test]
fn
empty_contract_input
()
{
assert!
(
contract_gen_impl2
(
quote!
{})
.is_err
());
}
lang/src/tests/noop.rs
0 → 100644
View file @
f08d790b
use
super
::
*
;
#[test]
fn
noop_contract
()
{
assert_eq_tokenstreams
(
quote!
{
/// The contract that does nothing.
///
/// # Note
///
/// Can be deployed, cannot be called.
struct
Noop
{}
impl
Deploy
for
Noop
{
/// Does nothing to initialize itself.
fn
deploy
(
&
mut
self
)
{}
}
/// Provides no way to call it as extrinsic.
impl
Noop
{}
},
quote!
{
pdsl_model
::
state!
{
/// The contract that does nothing.
///
/// # Note
///
/// Can be deployed, cannot be called.
struct
Noop
{}
}
use
pdsl_model
::
messages
;
pdsl_model
::
messages!
{}
impl
Noop
{
/// Does nothing to initialize itself.
pub
fn
deploy
(
&
mut
self
,
env
:
&
mut
pdsl_model
::
EnvHandler
)
{
}
}
impl
Noop
{}
use
pdsl_model
::
Contract
;
fn
instantiate
()
->
impl
pdsl_model
::
Contract
{
pdsl_model
::
ContractDecl
::
using
::
<
Noop
>
()
.on_deploy
(|
env
,
()|
{
let
(
handler
,
state
)
=
env
.split_mut
();
state
.deploy
(
handler
,)
})
.instantiate
()
}
#[no_mangle]
fn
deploy
()
{
instantiate
()
.deploy
()
}
#[no_mangle]
fn
call
()
{
instantiate
()
.dispatch
()
}
}
)
}
lang/src/tests/utils.rs
0 → 100644
View file @
f08d790b
use
crate
::
contract_gen_impl2
;
pub
fn
assert_eq_tokenstreams
(
input
:
proc_macro2
::
TokenStream
,
expected
:
proc_macro2
::
TokenStream
,
)
{
assert_eq!
(
contract_gen_impl2
(
input
)
.map
(|
result
|
result
.to_string
())
.map_err
(|
err
|
err
.to_string
()),
Ok
(
expected
.to_string
())
)
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment