MCPcopy Create free account
hub / github.com/Doctave/dossier / parse_function_params

Function parse_function_params

dossier-py/src/function.rs:151–193  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

149
150 #[test]
151 fn parse_function_params() {
152 let source = indoc! {r#"
153 def foo(bar, baz: int) -> bool:
154 pass
155 "#};
156
157 let mut ctx = ParserContext::new(Path::new("test.py"), source);
158 let tree = crate::init_parser().parse(source, None).unwrap();
159 let mut cursor = tree.root_node().walk();
160 cursor.goto_first_child();
161
162 let symbol = Function::parse_symbol(cursor.node(), &mut ctx).unwrap();
163 assert_eq!(symbol.fqn.as_deref(), Some("test.py::foo"));
164
165 let function = symbol.as_function().unwrap();
166 assert_eq!(function.title, "foo");
167
168 let params = function.parameters().collect::<Vec<_>>();
169 assert_eq!(params.len(), 2);
170
171 let param = params[0].as_parameter().unwrap();
172 assert_eq!(params[0].context, Some(SymbolContext::Parameter));
173 assert_eq!(params[0].fqn.as_deref(), Some("test.py::foo::bar"));
174 assert_eq!(param.title, "bar");
175 assert_eq!(param.the_type(), None);
176
177 let param = params[1].as_parameter().unwrap();
178 assert_eq!(params[1].context, Some(SymbolContext::Parameter));
179 assert_eq!(params[1].fqn.as_deref(), Some("test.py::foo::baz"));
180 assert_eq!(param.title, "baz");
181 let the_type = param.the_type();
182 assert_eq!(
183 the_type.unwrap().as_type().unwrap(),
184 &Type::BuiltIn("int".to_owned())
185 );
186
187 let return_type = function.return_type().unwrap();
188 assert_eq!(return_type.context, Some(SymbolContext::ReturnType));
189 assert_eq!(
190 return_type.as_type().unwrap(),
191 &Type::BuiltIn("bool".to_owned())
192 );
193 }
194}

Callers

nothing calls this directly

Calls 7

init_parserFunction · 0.70
parseMethod · 0.45
as_functionMethod · 0.45
parametersMethod · 0.45
as_parameterMethod · 0.45
the_typeMethod · 0.45
return_typeMethod · 0.45

Tested by

no test coverage detected