@test(...) style works for test + cargo fmt pass

This commit is contained in:
gluaxspeed 2021-01-21 09:25:36 -05:00
parent 0318bb770a
commit 1d4b30422a
4 changed files with 47 additions and 2 deletions

View File

@ -36,7 +36,21 @@ pub fn load_annotation(
match ast_definition {
Definition::Import(_) => unimplemented!("annotated imports are not supported yet"),
Definition::Circuit(_) => unimplemented!("annotated circuits are not supported yet"),
Definition::Function(_) => unimplemented!("annotated functions are not supported yet"),
// TODO need someone to take functions annotated with @test to be moved from function to tests.
Definition::Function(function) => match ast_annotation.name {
AnnotationName::Test(_) | AnnotationName::TestWithContext(_) => {
println!("here?");
let ident = Identifier::from(function.identifier.clone());
_functions.remove(&ident.clone());
let test_function = leo_grammar::functions::TestFunction::from(function);
let test = TestFunction::from(test_function);
tests.insert(ident, test.clone());
load_annotated_test(test, ast_annotation, tests);
}
_ => unimplemented!("annotated functions are not supported yet"),
},
Definition::TestFunction(ast_test) => {
let test = TestFunction::from(ast_test);
load_annotated_test(test, ast_annotation, tests)
@ -50,6 +64,8 @@ pub fn load_annotated_test(test: TestFunction, annotation: Annotation, tests: &m
let ast_arguments = annotation.arguments;
match name {
AnnotationName::Test(_) => (),
AnnotationName::TestWithContext(_) => load_annotated_test_context(test, ast_arguments, tests),
AnnotationName::Context(_) => load_annotated_test_context(test, ast_arguments, tests),
}
}

View File

@ -20,10 +20,30 @@ use pest::Span;
use pest_ast::FromPest;
use serde::Serialize;
// TODO rename this to test for consistency?
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::annotation_name))]
pub enum AnnotationName<'ast> {
Context(Context<'ast>),
Test(Test<'ast>),
TestWithContext(TestWithContext<'ast>),
}
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::test))]
pub struct Test<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]
#[pest_ast(rule(Rule::test))]
pub struct TestWithContext<'ast> {
#[pest_ast(outer())]
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}
#[derive(Clone, Debug, FromPest, PartialEq, Serialize)]

View File

@ -28,3 +28,10 @@ pub struct TestFunction<'ast> {
#[serde(with = "SpanDef")]
pub span: Span<'ast>,
}
impl<'ast> From<Function<'ast>> for TestFunction<'ast> {
fn from(function: Function<'ast>) -> Self {
let span = function.span.clone();
TestFunction { function, span }
}
}

View File

@ -514,7 +514,7 @@ formatted_container = { "{" ~ "}"}
/// Annotations
// Declared in annotations/annotation.rs
annotation = ${annotation_symbol ~ annotation_name ~ annotation_arguments}
annotation = ${annotation_symbol ~ annotation_name ~ annotation_arguments? }
// Declared in annotations/annotation_symbol.rs
annotation_symbol = ${"@"}
@ -522,10 +522,12 @@ annotation_symbol = ${"@"}
// Declared in annotations/annotation_name.rs
annotation_name = {
context
| test
}
// Declared in annotations/context.rs
context = {"context"}
test = {"test"}
// Declared in annotations/annotation_argument.rs
annotation_arguments = !{"(" ~ annotation_argument ~ ("," ~ annotation_argument)* ~ ","? ~ NEWLINE* ~ ")"}