From a121599b8f43576aceaf33eb374ac9f3d3137926 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 7 May 2026 10:07:39 +0200 Subject: [PATCH 1/2] Slim down test helpers in config.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop make_table_config (only two callers, easier to inline) and collapse make_field down to (name, primary_key) — value_kind and null_sentinel were never load-bearing for the ordered_field_names tests, and four positional args made call sites hard to scan. Signed-off-by: Lars Erik Wik --- src/config.rs | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/config.rs b/src/config.rs index cdb3356..c7daab7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -574,46 +574,39 @@ impl Config { mod tests { use super::*; - fn make_field( - name: &str, - value_kind: ValueKind, - primary_key: bool, - null_sentinel: Option<&str>, - ) -> FieldConfig { + fn make_field(name: &str, primary_key: bool) -> FieldConfig { FieldConfig { name: name.to_string(), - value_kind, primary_key, - null_sentinel: null_sentinel.map(|s| s.to_string()), ..Default::default() } } - fn make_table_config(fields: Vec) -> TableConfig { - TableConfig { - source: "test.csv".to_string(), - header: false, - fields, - } - } - #[test] fn test_ordered_field_names() { - let config = make_table_config(vec![ - make_field("name", ValueKind::Text, false, None), - make_field("id", ValueKind::Number, true, None), - make_field("email", ValueKind::Text, false, None), - ]); + let config = TableConfig { + source: "test.csv".to_string(), + header: false, + fields: vec![ + make_field("name", false), + make_field("id", true), + make_field("email", false), + ], + }; assert_eq!(config.ordered_field_names(), vec!["id", "name", "email"]); } #[test] fn test_ordered_field_names_multiple_primary_keys() { - let config = make_table_config(vec![ - make_field("value", ValueKind::Text, false, None), - make_field("pk_b", ValueKind::Text, true, None), - make_field("pk_a", ValueKind::Text, true, None), - ]); + let config = TableConfig { + source: "test.csv".to_string(), + header: false, + fields: vec![ + make_field("value", false), + make_field("pk_b", true), + make_field("pk_a", true), + ], + }; // PKs in declaration order, then subsidiaries assert_eq!(config.ordered_field_names(), vec!["pk_b", "pk_a", "value"]); } From bad81f164379bd55328d4450b477167b184b117c Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 7 May 2026 10:16:07 +0200 Subject: [PATCH 2/2] Use Default::default() for FilterConfig literals in tests Replace explicit max_field_length/include/exclude defaults with struct update syntax so each test shows only the fields it exercises. Signed-off-by: Lars Erik Wik --- src/config.rs | 44 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/config.rs b/src/config.rs index c7daab7..b1c0ba5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -699,8 +699,7 @@ mod tests { fn test_should_filter_max_field_length() { let filter = FilterConfig { max_field_length: Some(5), - include: vec![], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "name".to_string()]; @@ -719,9 +718,8 @@ mod tests { #[test] fn test_should_filter_exclude_anchored_regex() { let filter = FilterConfig { - max_field_length: None, - include: vec![], exclude: vec![make_rule(vec![], "status", "^inactive$")], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -746,9 +744,8 @@ mod tests { #[test] fn test_should_filter_exclude_unanchored_regex() { let filter = FilterConfig { - max_field_length: None, - include: vec![], exclude: vec![make_rule(vec![], "desc", "DEPRECATED")], + ..Default::default() }; let fields = vec!["id".to_string(), "desc".to_string()]; @@ -767,9 +764,8 @@ mod tests { #[test] fn test_should_filter_exclude_alternation_regex() { let filter = FilterConfig { - max_field_length: None, - include: vec![], exclude: vec![make_rule(vec![], "status", "^(inactive|archived)$")], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -795,9 +791,8 @@ mod tests { #[test] fn test_should_filter_exclude_skipped_when_field_not_in_table() { let filter = FilterConfig { - max_field_length: None, - include: vec![], exclude: vec![make_rule(vec![], "nonexistent", "^value$")], + ..Default::default() }; let fields = vec!["id".to_string(), "name".to_string()]; @@ -811,9 +806,8 @@ mod tests { #[test] fn test_should_filter_exclude_table_scoped() { let filter = FilterConfig { - max_field_length: None, - include: vec![], exclude: vec![make_rule(vec!["users"], "status", "^inactive$")], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -834,9 +828,8 @@ mod tests { #[test] fn test_should_filter_exclude_multiple_tables() { let filter = FilterConfig { - max_field_length: None, - include: vec![], exclude: vec![make_rule(vec!["users", "admins"], "status", "^inactive$")], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -893,9 +886,8 @@ fields = [ #[test] fn test_should_filter_include_match_keeps_record() { let filter = FilterConfig { - max_field_length: None, include: vec![make_rule(vec![], "status", "^(active|pending)$")], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -914,9 +906,8 @@ fields = [ #[test] fn test_should_filter_include_no_match_drops_record() { let filter = FilterConfig { - max_field_length: None, include: vec![make_rule(vec![], "status", "^(active|pending)$")], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -930,9 +921,8 @@ fields = [ #[test] fn test_should_filter_include_unanchored_regex() { let filter = FilterConfig { - max_field_length: None, include: vec![make_rule(vec![], "desc", "PRODUCTION")], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "desc".to_string()]; @@ -953,12 +943,11 @@ fields = [ #[test] fn test_should_filter_include_or_semantics() { let filter = FilterConfig { - max_field_length: None, include: vec![ make_rule(vec![], "status", "^active$"), make_rule(vec![], "status", "^pending$"), ], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -984,9 +973,8 @@ fields = [ #[test] fn test_should_filter_include_skipped_when_field_not_in_table() { let filter = FilterConfig { - max_field_length: None, include: vec![make_rule(vec![], "nonexistent", "^value$")], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "name".to_string()]; @@ -1002,9 +990,8 @@ fields = [ #[test] fn test_should_filter_include_no_applicable_rule_keeps_record() { let filter = FilterConfig { - max_field_length: None, include: vec![make_rule(vec!["users"], "status", "^active$")], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -1018,9 +1005,8 @@ fields = [ #[test] fn test_should_filter_include_table_scoped() { let filter = FilterConfig { - max_field_length: None, include: vec![make_rule(vec!["users"], "status", "^active$")], - exclude: vec![], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()]; @@ -1049,9 +1035,9 @@ fields = [ #[test] fn test_should_filter_exclude_wins_over_include() { let filter = FilterConfig { - max_field_length: None, include: vec![make_rule(vec![], "status", "^(active|pending)$")], exclude: vec![make_rule(vec![], "status", "^pending$")], + ..Default::default() }; let fields = vec!["id".to_string(), "status".to_string()];