|
| 1 | +use code_memory::git::decision_parser::DecisionParser; |
| 2 | +use code_memory::graph::analyzer::DependencyGraph; |
| 3 | +use code_memory::sessions::PatternLibrary; |
| 4 | + |
| 5 | +#[test] |
| 6 | +fn migration_keywords_are_case_insensitive_without_losing_technology_case() { |
| 7 | + let decisions = DecisionParser::new() |
| 8 | + .parse_message("Decided to Migrate FROM REST TO GraphQL\nKeep typed queries."); |
| 9 | + assert_eq!(decisions.len(), 1); |
| 10 | + assert_eq!(decisions[0].decision_type, "migration"); |
| 11 | + assert_eq!(decisions[0].from.as_deref(), Some("REST")); |
| 12 | + assert_eq!(decisions[0].to, "GraphQL"); |
| 13 | +} |
| 14 | + |
| 15 | +#[test] |
| 16 | +fn plain_observations_are_visible_to_pattern_queries() { |
| 17 | + let mut library = PatternLibrary::new(); |
| 18 | + for _ in 0..6 { |
| 19 | + library.observe("naming:rust:snake_case"); |
| 20 | + } |
| 21 | + let patterns = library.confident_patterns(0.5); |
| 22 | + assert_eq!(patterns.len(), 1); |
| 23 | + assert_eq!(patterns[0].observation_count, 6); |
| 24 | + assert!(patterns[0].examples.is_empty()); |
| 25 | + library.observe_with_example("naming:rust:snake_case", "fn hello_world()"); |
| 26 | + assert_eq!(library.all_patterns()[0].observation_count, 7); |
| 27 | + assert_eq!(library.all_patterns()[0].examples, ["fn hello_world()"]); |
| 28 | +} |
| 29 | + |
| 30 | +#[test] |
| 31 | +fn rust_child_modules_resolve_in_flat_and_directory_layouts() { |
| 32 | + for (parent, child) in [ |
| 33 | + ("src/foo.rs", "src/foo/child.rs"), |
| 34 | + ("src/foo/mod.rs", "src/foo/child.rs"), |
| 35 | + ("src/lib.rs", "src/child/mod.rs"), |
| 36 | + ] { |
| 37 | + for child_first in [false, true] { |
| 38 | + let mut graph = DependencyGraph::new(); |
| 39 | + if child_first { |
| 40 | + graph.add_file(child, "pub fn helper() {}\n"); |
| 41 | + } |
| 42 | + graph.add_file(parent, "mod child;\n"); |
| 43 | + if !child_first { |
| 44 | + graph.add_file(child, "pub fn helper() {}\n"); |
| 45 | + } |
| 46 | + assert_eq!(graph.depends_on(parent), [child], "{parent} -> {child}"); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments