History

refactor

- more readability for branch testing

Sebastian Thiel committed 4 years ago

Commit 11c417f1 parent 31e6db81 file · +56 −19Browse files

Unified · Split

git-config/tests/file/from_paths/includes/conditional/onbranch.rs+56−19
@@ -12,11 +12,24 @@ enum Value { · 11 unmodified lines
1212 OverrideByInclude,
1313 }
1414
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,
1719 }
1820
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+) {
2033 let dir = tempdir().unwrap();
2134 let root_config = dir.path().join("root.config");
2235 let included_config = dir.path().join("include.config");
@@ -73,42 +86,66 @@ value = branch-override-by-include · 50 unmodified lines
7386
7487 #[test]
7588 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+ });
7794 }
7895
7996 #[test]
8097 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+ });
82103 }
83104
84105 #[test]
85106 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+ });
87112 }
88113
89114 #[test]
90115 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+ });
93126 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+ },
97132 "just for good measure, we would expect branch paths to work as well".into(),
98133 );
99134 }
100135
101136 #[test]
102137 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+ });
108143 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+ },
112149 "path matching would never match 'a/b' as it cannot cross /".into(),
113150 );
114151 }