1use super::language_trait::LanguageImpl;
2use tree_sitter::{Language as TSLanguage, Node};
3
4pub struct CLanguage;
6
7impl Default for CLanguage {
8 fn default() -> Self {
9 Self::new()
10 }
11}
12
13impl CLanguage {
14 pub fn new() -> Self {
15 CLanguage
16 }
17}
18
19impl LanguageImpl for CLanguage {
20 fn get_tree_sitter_language(&self) -> TSLanguage {
21 tree_sitter_c::LANGUAGE.into()
22 }
23
24 fn get_extension(&self) -> &'static str {
25 "c"
26 }
27
28 fn is_acceptable_parent(&self, node: &Node) -> bool {
29 matches!(
30 node.kind(),
31 "function_definition" | "declaration" | "struct_specifier" | "enum_specifier"
32 )
33 }
34
35 fn is_test_node(&self, node: &Node, source: &[u8]) -> bool {
36 let debug_mode = std::env::var("DEBUG").unwrap_or_default() == "1";
37 let node_type = node.kind();
38
39 if node_type == "function_definition" {
41 let mut cursor = node.walk();
42 for child in node.children(&mut cursor) {
43 if child.kind() == "function_declarator" {
44 let mut subcursor = child.walk();
45 for subchild in child.children(&mut subcursor) {
46 if subchild.kind() == "identifier" {
47 let name = subchild.utf8_text(source).unwrap_or("");
48 if name.contains("test") || name.contains("Test") {
49 if debug_mode {
50 println!("DEBUG: Test node detected (C): test function");
51 }
52 return true;
53 }
54 }
55 }
56 }
57 }
58 }
59
60 false
61 }
62}