()
| 1503 | |
| 1504 | #[test] |
| 1505 | fn function_scope() { |
| 1506 | let TestCase { db, file } = test_case( |
| 1507 | " |
| 1508 | def func(): |
| 1509 | x = 1 |
| 1510 | y = 2 |
| 1511 | ", |
| 1512 | ); |
| 1513 | let module = parsed_module(&db, program_file(&db, file).python_file(&db)).load(&db); |
| 1514 | let index = semantic_index(&db, program_file(&db, file)); |
| 1515 | let global_table = index.place_table(FileScopeId::global()); |
| 1516 | |
| 1517 | assert_eq!(names(global_table), vec!["func", "y"]); |
| 1518 | |
| 1519 | let [(function_scope_id, function_scope)] = index |
| 1520 | .child_scopes(FileScopeId::global()) |
| 1521 | .collect::<Vec<_>>()[..] |
| 1522 | else { |
| 1523 | panic!("expected one child scope") |
| 1524 | }; |
| 1525 | assert_eq!(function_scope.kind(), ScopeKind::Function); |
| 1526 | assert_eq!( |
| 1527 | function_scope_id |
| 1528 | .to_scope_id(&db, program_file(&db, file)) |
| 1529 | .name(&db, &module), |
| 1530 | "func" |
| 1531 | ); |
| 1532 | |
| 1533 | let function_table = index.place_table(function_scope_id); |
| 1534 | assert_eq!(names(function_table), vec!["x"]); |
| 1535 | |
| 1536 | let use_def = index.use_def_map(function_scope_id); |
| 1537 | let binding = use_def |
| 1538 | .first_public_binding(function_table.symbol_id("x").expect("symbol exists")) |
| 1539 | .unwrap(); |
| 1540 | assert_matches!(binding.kind(&db), DefinitionKind::Assignment(_)); |
| 1541 | } |
| 1542 | |
| 1543 | #[test] |
| 1544 | fn function_parameter_symbols() { |
nothing calls this directly
no test coverage detected