1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::{Circuit, Function, FunctionInput, Identifier, ImportStatement, TestFunction};
use leo_grammar::{
annotations::{Annotation, AnnotationArguments, AnnotationName},
definitions::{AnnotatedDefinition, Definition},
};
use indexmap::IndexMap;
pub fn load_annotation(
annotated_definition: AnnotatedDefinition,
_imports: &mut Vec<ImportStatement>,
_circuits: &mut IndexMap<Identifier, Circuit>,
_functions: &mut IndexMap<Identifier, Function>,
tests: &mut IndexMap<Identifier, TestFunction>,
_expected: &mut Vec<FunctionInput>,
) {
let ast_annotation = annotated_definition.annotation;
let ast_definition = *annotated_definition.definition;
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"),
Definition::TestFunction(ast_test) => {
let test = TestFunction::from(ast_test);
load_annotated_test(test, ast_annotation, tests)
}
Definition::Annotated(_) => unimplemented!("nested annotations are not supported yet"),
}
}
pub fn load_annotated_test(test: TestFunction, annotation: Annotation, tests: &mut IndexMap<Identifier, TestFunction>) {
let name = annotation.name;
let ast_arguments = annotation.arguments;
match name {
AnnotationName::Context(_) => load_annotated_test_context(test, ast_arguments, tests),
}
}
pub fn load_annotated_test_context(
mut test: TestFunction,
ast_arguments: AnnotationArguments,
tests: &mut IndexMap<Identifier, TestFunction>,
) {
let arguments = ast_arguments.arguments;
if arguments.len() != 1 {
panic!("text context annotation must have one argument identifier")
}
let ast_input_file = arguments[0].to_owned();
let input_file = Identifier::from(ast_input_file);
test.input_file = Some(input_file);
tests.insert(test.function.identifier.clone(), test);
}