1+ #[ path = "matching/required.rs" ]
2+ mod required;
3+ #[ path = "matching/rules.rs" ]
4+ mod rules;
5+ #[ path = "matching/unexpected.rs" ]
6+ mod unexpected;
7+
18use std:: collections:: HashSet ;
29
310use crate :: core;
411
5- use super :: super :: metrics:: { compute_rule_metrics, summarize_rule_metrics} ;
6- use super :: super :: pattern:: summarize_for_eval;
712use super :: super :: { EvalExpectations , EvalRuleMetrics , EvalRuleScoreSummary } ;
13+ use required:: collect_required_matches;
14+ use rules:: build_rule_match_metrics;
15+ use unexpected:: collect_unexpected_matches;
816
917pub ( super ) struct FixtureMatchSummary {
1018 pub ( super ) failures : Vec < String > ,
@@ -20,57 +28,23 @@ pub(super) fn evaluate_fixture_expectations(
2028 expectations : & EvalExpectations ,
2129 comments : & [ core:: Comment ] ,
2230) -> FixtureMatchSummary {
23- let mut failures = Vec :: new ( ) ;
24- let mut required_matches = 0usize ;
2531 let required_total = expectations. must_find . len ( ) ;
26- let mut used_comment_indices = HashSet :: new ( ) ;
27- let mut unexpected_comment_indices = HashSet :: new ( ) ;
28- let mut matched_pairs = Vec :: new ( ) ;
29-
30- for ( expected_idx, expected) in expectations. must_find . iter ( ) . enumerate ( ) {
31- let found = comments
32- . iter ( )
33- . enumerate ( )
34- . find ( |( comment_idx, comment) | {
35- !used_comment_indices. contains ( comment_idx) && expected. matches ( comment)
36- } )
37- . map ( |( comment_idx, _) | comment_idx) ;
38-
39- if let Some ( comment_idx) = found {
40- used_comment_indices. insert ( comment_idx) ;
41- matched_pairs. push ( ( expected_idx, comment_idx) ) ;
42- required_matches = required_matches. saturating_add ( 1 ) ;
43- } else {
44- failures. push ( format ! ( "Missing expected finding: {}" , expected. describe( ) ) ) ;
45- }
46- }
47-
48- for unexpected in & expectations. must_not_find {
49- if let Some ( ( comment_idx, comment) ) = comments
50- . iter ( )
51- . enumerate ( )
52- . find ( |( _, comment) | unexpected. matches ( comment) )
53- {
54- unexpected_comment_indices. insert ( comment_idx) ;
55- failures. push ( format ! (
56- "Unexpected finding matched {}:{} '{}'" ,
57- comment. file_path. display( ) ,
58- comment. line_number,
59- summarize_for_eval( & comment. content)
60- ) ) ;
61- }
62- }
63-
64- let rule_metrics = compute_rule_metrics ( & expectations. must_find , comments, & matched_pairs) ;
65- let rule_summary = summarize_rule_metrics ( & rule_metrics) ;
32+ let required = collect_required_matches ( expectations, comments) ;
33+ let unexpected = collect_unexpected_matches ( expectations, comments) ;
34+ let ( rule_metrics, rule_summary) =
35+ build_rule_match_metrics ( expectations, comments, & required. matched_pairs ) ;
6636
6737 FixtureMatchSummary {
68- failures,
69- required_matches,
38+ failures : required
39+ . failures
40+ . into_iter ( )
41+ . chain ( unexpected. failures )
42+ . collect ( ) ,
43+ required_matches : required. required_matches ,
7044 required_total,
7145 rule_metrics,
7246 rule_summary,
73- used_comment_indices,
74- unexpected_comment_indices,
47+ used_comment_indices : required . used_comment_indices ,
48+ unexpected_comment_indices : unexpected . unexpected_comment_indices ,
7549 }
7650}
0 commit comments