mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
@test(...) style works for test + cargo fmt pass
This commit is contained in:
parent
0318bb770a
commit
1d4b30422a
@ -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),
|
||||
}
|
||||
}
|
||||
|
@ -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)]
|
||||
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
@ -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* ~ ")"}
|
||||
|
Loading…
Reference in New Issue
Block a user