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