()
| 1303 | |
| 1304 | #[test] |
| 1305 | fn function_scope() { |
| 1306 | let TestCase { db, file } = test_case( |
| 1307 | " |
| 1308 | def func(): |
| 1309 | x = 1 |
| 1310 | y = 2 |
| 1311 | ", |
| 1312 | ); |
| 1313 | let module = parsed_module(&db, program_file(&db, file).python_file(&db)).load(&db); |
| 1314 | let index = semantic_index(&db, program_file(&db, file)); |
| 1315 | let global_table = index.place_table(FileScopeId::global()); |
| 1316 | |
| 1317 | assert_eq!(names(global_table), vec!["func", "y"]); |
| 1318 | |
| 1319 | let [(function_scope_id, function_scope)] = index |
| 1320 | .child_scopes(FileScopeId::global()) |
| 1321 | .collect::<Vec<_>>()[..] |
| 1322 | else { |
| 1323 | panic!("expected one child scope") |
| 1324 | }; |
| 1325 | assert_eq!(function_scope.kind(), ScopeKind::Function); |
| 1326 | assert_eq!( |
| 1327 | function_scope_id |
| 1328 | .to_scope_id(&db, program_file(&db, file)) |
| 1329 | .name(&db, &module), |
| 1330 | "func" |
| 1331 | ); |
| 1332 | |
| 1333 | let function_table = index.place_table(function_scope_id); |
| 1334 | assert_eq!(names(function_table), vec!["x"]); |
| 1335 | |
| 1336 | let use_def = index.use_def_map(function_scope_id); |
| 1337 | let binding = use_def |
| 1338 | .first_public_binding(function_table.symbol_id("x").expect("symbol exists")) |
| 1339 | .unwrap(); |
| 1340 | assert!(matches!(binding.kind(&db), DefinitionKind::Assignment(_))); |
| 1341 | } |
| 1342 | |
| 1343 | #[test] |
| 1344 | fn function_parameter_symbols() { |
nothing calls this directly
no test coverage detected