Crates.io | conformance |
lib.rs | conformance |
version | 0.2.0 |
source | src |
created_at | 2019-10-04 21:22:24.766678 |
updated_at | 2019-10-10 17:37:40.401696 |
description | Conformance testing for fn(&str) -> impl Serialize |
homepage | |
repository | https://github.com/CAD97/tinyc/tree/master/crates/conformance |
max_upload_size | |
id | 169986 |
size | 14,673 |
simple.yaml.test
:
1
===
a=b=c=2<3;
---
- Identifier: 1
- EqualsSign: 1
- Identifier: 1
- EqualsSign: 1
- Identifier: 1
- EqualsSign: 1
- Integer: 1
- LessThanSign: 1
- Integer: 1
- Semicolon: 1
...
test.rs
:
use {
conformance, serde_yaml,
tinyc_lexer::{tokenize, Token},
};
#[conformance::tests(exact, serde=serde_yaml, file="tests/simple.yaml.test")]
fn lex_tokens(s: &str) -> Vec<Token> {
tokenize(s).collect()
}
This grabs the input from between ===
and ---
,
passes it to the test function,
then serializes it with the ser
function.
The output is grabbed from between ---
and ...
,
then normalized by de
serializing and then reser
ializing.
The two serialized forms are compared with assert_eq!
.
The file path is relative to the Cargo manifest.
Any number of tests can be included in one conformance test file.
The file name and the test name (above the ===
) are combined
and used to name the test given to the standard Rust test runner.
The serde
argument stands in for three arguments
that may be provided, in order, in its place:
ser
: fn<T>(&T) -> String
(default serde::to_string
)de
: fn(&str) -> Result<value, impl Error>
(default serde::from_str
)value
: A type that be passed to ser
(default serde::Value
)You can also just supply ser
and de
,
and value
defaults to the produced type.
For more information, see the dev.to announcement post or @ me on Discord.