-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcomments.rs
More file actions
49 lines (44 loc) · 1.26 KB
/
comments.rs
File metadata and controls
49 lines (44 loc) · 1.26 KB
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
use fkl_mir::Step;
pub fn ai_comments(steps: &Vec<Step>) -> Vec<String> {
steps.iter().enumerate().map(|(index, step)| {
match step {
Step::MethodCall(call) => {
format!("// {}. {}", index + 1, call)
}
Step::Message(msg) => {
format!("// {}. {}", index + 1, msg)
}
Step::RpcCall(_) => {
"".to_string()
}
}
}).collect()
}
#[cfg(test)]
mod tests {
use fkl_mir::{Message, MethodCall, Step, VariableDefinition};
use crate::comments::ai_comments;
#[test]
fn format_ai_comments() {
let comments = ai_comments(&vec![
Step::MethodCall(MethodCall {
name: "all".to_string(),
object: "UserRepository".to_string(),
method: "save".to_string(),
parameters: vec![VariableDefinition {
name: "user".to_string(),
type_type: "User".to_string(),
initializer: None,
}],
return_type: None,
}),
Step::Message(Message {
from: "Content".to_string(),
to: "".to_string(),
topic: "sample:blabla".to_string(),
message: "hello".to_string(),
}),
]);
assert_eq!(comments.join(" "), "// 1. call UserRepository.save with (user:User) // 2. send hello from Content to sample:blabla");
}
}