Extract a test declaration: `test "name" { ... }`.
(state: &mut ExtractionState, node: TsNode<'_>)
| 722 | |
| 723 | /// Extract a test declaration: `test "name" { ... }`. |
| 724 | fn visit_test(state: &mut ExtractionState, node: TsNode<'_>) { |
| 725 | // The test name is in a string child. |
| 726 | let name = find_direct_child_by_kind(node, "string") |
| 727 | .and_then(|s| find_direct_child_by_kind(s, "string_content")) |
| 728 | .map_or_else(|| "<anonymous test>".to_string(), |n| state.node_text(n)); |
| 729 | |
| 730 | let start_line = node.start_position().row as u32; |
| 731 | let end_line = node.end_position().row as u32; |
| 732 | let start_column = node.start_position().column as u32; |
| 733 | let end_column = node.end_position().column as u32; |
| 734 | let qualified_name = format!("{}::test::{}", state.qualified_prefix(), name); |
| 735 | let id = generate_node_id(&state.file_path, &NodeKind::Function, &name, start_line); |
| 736 | let metrics = count_complexity(node, &ZIG_COMPLEXITY, &state.source); |
| 737 | |
| 738 | let graph_node = Node { |
| 739 | id: id.clone(), |
| 740 | kind: NodeKind::Function, |
| 741 | name, |
| 742 | qualified_name, |
| 743 | file_path: state.file_path.clone(), |
| 744 | start_line, |
| 745 | attrs_start_line: start_line, |
| 746 | end_line, |
| 747 | start_column, |
| 748 | end_column, |
| 749 | signature: Some( |
| 750 | state |
| 751 | .node_text(node) |
| 752 | .lines() |
| 753 | .next() |
| 754 | .unwrap_or("") |
| 755 | .trim() |
| 756 | .to_string(), |
| 757 | ), |
| 758 | docstring: None, |
| 759 | visibility: Visibility::Private, |
| 760 | is_async: false, |
| 761 | branches: metrics.branches, |
| 762 | loops: metrics.loops, |
| 763 | returns: metrics.returns, |
| 764 | max_nesting: metrics.max_nesting, |
| 765 | unsafe_blocks: metrics.unsafe_blocks, |
| 766 | unchecked_calls: metrics.unchecked_calls, |
| 767 | assertions: metrics.assertions, |
| 768 | updated_at: state.timestamp, |
| 769 | parent_id: None, |
| 770 | }; |
| 771 | state.nodes.push(graph_node); |
| 772 | |
| 773 | // Contains edge from parent. |
| 774 | if let Some(parent_id) = state.parent_node_id() { |
| 775 | state.edges.push(Edge { |
| 776 | source: parent_id.to_string(), |
| 777 | target: id.clone(), |
| 778 | kind: EdgeKind::Contains, |
| 779 | line: Some(start_line), |
| 780 | }); |
| 781 | } |
nothing calls this directly
no test coverage detected