MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / test_parse_function

Function test_parse_function

aiscript-vm/src/parser/stmt_test.rs:13–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12 #[test]
13 fn test_parse_function() {
14 rootless_mutate(|mutation| {
15 let context = Context {
16 mutation,
17 strings: InternedStringSet::new(mutation),
18 };
19 let source = r#"
20 fn test1() {
21 """
22 test1 doc
23 """
24 print("Hello, world!");
25 }
26
27 fn test2(a: int, b: int) -> int {
28 return a + b;
29 }
30
31 fn test3(a, b,) -> int {
32 return a + b;
33 }
34 "#;
35 let mut parser = Parser::new(context, source);
36 let result = parser.parse().unwrap();
37 let Stmt::Function(FunctionDecl {
38 name,
39 mangled_name,
40 doc,
41 params,
42 return_type,
43 body,
44 line,
45 ..
46 }) = &result.statements[0]
47 else {
48 panic!("Unexpected statement type");
49 };
50 assert_eq!(name.lexeme, "test1");
51 assert_eq!(mangled_name, "script$test1");
52 assert_eq!(doc.unwrap().lexeme, "test1 doc");
53 assert_eq!(params.len(), 0);
54 assert!(return_type.is_none());
55 assert_eq!(body.len(), 1);
56 assert_eq!(line, &2);
57
58 let Stmt::Function(FunctionDecl {
59 name,
60 mangled_name,
61 doc,
62 params,
63 return_type,
64 ..
65 }) = &result.statements[1]
66 else {
67 panic!("Unexpected statement type");
68 };
69 assert_eq!(name.lexeme, "test2");
70 assert_eq!(mangled_name, "script$test2");

Callers

nothing calls this directly

Calls 2

rootless_mutateFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected