1pub mod model;
2pub mod parser;
3
4pub use model::*;
5pub use parser::Parser;
6
7#[cfg(test)]
8mod tests {
9 use std::path::Path;
10
11 use super::Parser;
12
13 #[test]
14 fn test_includes_simple() {
15 let mut parser = Parser::new().unwrap();
16 let project = parser
17 .parse_file(Path::new("tests/fixtures/includes_simple.c"))
18 .unwrap();
19
20 assert_eq!(project.files.len(), 1);
21 let file = project.files.values().next().unwrap();
22
23 let include_data: Vec<(&str, bool, _)> = file.iter_all_includes().collect();
24
25 assert_eq!(
27 include_data.len(),
28 7,
29 "Expected 7 includes, got {}",
30 include_data.len()
31 );
32
33 assert_eq!(include_data[0].0, "config.h");
34 assert!(!include_data[0].1, "config.h should not be system");
35
36 assert_eq!(include_data[1].0, "math.h");
37 assert!(include_data[1].1, "math.h should be system");
38
39 assert_eq!(include_data[2].0, "stdio.h");
40 assert!(include_data[2].1, "stdio.h should be system");
41
42 assert_eq!(include_data[3].0, "glib.h");
43 assert!(include_data[3].1, "glib.h should be system");
44
45 assert_eq!(include_data[4].0, "gtk/gtk.h");
46 assert!(include_data[4].1, "gtk/gtk.h should be system");
47
48 assert_eq!(include_data[5].0, "foo.h");
49 assert!(!include_data[5].1, "foo.h should not be system");
50
51 assert_eq!(include_data[6].0, "bar/baz.h");
52 assert!(!include_data[6].1, "bar/baz.h should not be system");
53 }
54
55 #[test]
56 fn test_includes_with_conditionals() {
57 let mut parser = Parser::new().unwrap();
58 let project = parser
59 .parse_file(Path::new("tests/fixtures/includes_with_conditionals.c"))
60 .unwrap();
61
62 assert_eq!(project.files.len(), 1);
63 let file = project.files.values().next().unwrap();
64
65 let include_data: Vec<(&str, bool, _)> = file.iter_all_includes().collect();
66
67 assert_eq!(
72 include_data.len(),
73 9,
74 "Expected 9 includes (including those in #ifdef), got {}",
75 include_data.len()
76 );
77
78 let paths: Vec<&str> = include_data.iter().map(|(path, ..)| *path).collect();
80 assert!(
81 paths.contains(&"pango/pangocairo.h"),
82 "Missing include from first #ifdef"
83 );
84 assert!(
85 paths.contains(&"clutter/pango/clutter-actor-pango.h"),
86 "Missing include from second #ifdef"
87 );
88 assert!(
89 paths.contains(&"clutter/pango/clutter-pango-private.h"),
90 "Missing include from second #ifdef"
91 );
92 }
93}