- more readability for branch testing
Unified · Split
| @@ -12,11 +12,24 @@ enum Value { · 11 unmodified lines | ||
| 12 | 12 | OverrideByInclude, |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | −fn assert_section_value(condition: &str, branch_name: &str, expect: Value) { | |
| 16 | − assert_section_value_msg(condition, branch_name, expect, None) | |
| 15 | +struct Options<'a> { | |
| 16 | + condition: &'a str, | |
| 17 | + branch_name: &'a str, | |
| 18 | + expect: Value, | |
| 17 | 19 | } |
| 18 | 20 | |
| 19 | −fn assert_section_value_msg(condition: &str, branch_name: &str, expect: Value, message: Option<&str>) { | |
| 21 | +fn assert_section_value(opts: Options) { | |
| 22 | + assert_section_value_msg(opts, None) | |
| 23 | +} | |
| 24 | + | |
| 25 | +fn assert_section_value_msg( | |
| 26 | + Options { | |
| 27 | + condition, | |
| 28 | + branch_name, | |
| 29 | + expect, | |
| 30 | + }: Options, | |
| 31 | + message: Option<&str>, | |
| 32 | +) { | |
| 20 | 33 | let dir = tempdir().unwrap(); |
| 21 | 34 | let root_config = dir.path().join("root.config"); |
| 22 | 35 | let included_config = dir.path().join("include.config"); |
| @@ -73,42 +86,66 @@ value = branch-override-by-include · 50 unmodified lines | ||
| 73 | 86 | |
| 74 | 87 | #[test] |
| 75 | 88 | fn literal_branch_names_match() { |
| 76 | − assert_section_value("literal-match", "refs/heads/literal-match", Value::OverrideByInclude); | |
| 89 | + assert_section_value(Options { | |
| 90 | + condition: "literal-match", | |
| 91 | + branch_name: "refs/heads/literal-match", | |
| 92 | + expect: Value::OverrideByInclude, | |
| 93 | + }); | |
| 77 | 94 | } |
| 78 | 95 | |
| 79 | 96 | #[test] |
| 80 | 97 | fn full_ref_names_do_not_match() { |
| 81 | − assert_section_value("refs/heads/simple", "refs/heads/simple", Value::Base); | |
| 98 | + assert_section_value(Options { | |
| 99 | + condition: "refs/heads/simple", | |
| 100 | + branch_name: "refs/heads/simple", | |
| 101 | + expect: Value::Base, | |
| 102 | + }); | |
| 82 | 103 | } |
| 83 | 104 | |
| 84 | 105 | #[test] |
| 85 | 106 | fn non_branches_never_match() { |
| 86 | − assert_section_value("good", "refs/bisect/good", Value::Base); | |
| 107 | + assert_section_value(Options { | |
| 108 | + condition: "good", | |
| 109 | + branch_name: "refs/bisect/good", | |
| 110 | + expect: Value::Base, | |
| 111 | + }); | |
| 87 | 112 | } |
| 88 | 113 | |
| 89 | 114 | #[test] |
| 90 | 115 | fn patterns_ending_with_slash_match_subdirectories_recursively() { |
| 91 | − assert_section_value("feature/b/", "refs/heads/feature/b/start", Value::OverrideByInclude); | |
| 92 | − assert_section_value("feature/", "refs/heads/feature/b/start", Value::OverrideByInclude); | |
| 116 | + assert_section_value(Options { | |
| 117 | + condition: "feature/b/", | |
| 118 | + branch_name: "refs/heads/feature/b/start", | |
| 119 | + expect: Value::OverrideByInclude, | |
| 120 | + }); | |
| 121 | + assert_section_value(Options { | |
| 122 | + condition: "feature/", | |
| 123 | + branch_name: "refs/heads/feature/b/start", | |
| 124 | + expect: Value::OverrideByInclude, | |
| 125 | + }); | |
| 93 | 126 | assert_section_value_msg( |
| 94 | − "feature/b/start", | |
| 95 | − "refs/heads/feature/b/start", | |
| 96 | − Value::OverrideByInclude, | |
| 127 | + Options { | |
| 128 | + condition: "feature/b/start", | |
| 129 | + branch_name: "refs/heads/feature/b/start", | |
| 130 | + expect: Value::OverrideByInclude, | |
| 131 | + }, | |
| 97 | 132 | "just for good measure, we would expect branch paths to work as well".into(), |
| 98 | 133 | ); |
| 99 | 134 | } |
| 100 | 135 | |
| 101 | 136 | #[test] |
| 102 | 137 | fn simple_globs_do_not_cross_component_boundary() { |
| 103 | − assert_section_value( | |
| 104 | − "feature/*/start", | |
| 105 | − "refs/heads/feature/a/start", | |
| 106 | − Value::OverrideByInclude, | |
| 107 | − ); | |
| 138 | + assert_section_value(Options { | |
| 139 | + condition: "feature/*/start", | |
| 140 | + branch_name: "refs/heads/feature/a/start", | |
| 141 | + expect: Value::OverrideByInclude, | |
| 142 | + }); | |
| 108 | 143 | assert_section_value_msg( |
| 109 | − "feature/*/start", | |
| 110 | − "refs/heads/feature/a/b/start", | |
| 111 | − Value::Base, | |
| 144 | + Options { | |
| 145 | + condition: "feature/*/start", | |
| 146 | + branch_name: "refs/heads/feature/a/b/start", | |
| 147 | + expect: Value::Base, | |
| 148 | + }, | |
| 112 | 149 | "path matching would never match 'a/b' as it cannot cross /".into(), |
| 113 | 150 | ); |
| 114 | 151 | } |