@@ -16,7 +16,19 @@ def test_conventional_commits(self):
1616 rule = ConventionalCommit ()
1717
1818 # No violations when using a correct type and format
19- for type in ["fix" , "feat" , "chore" , "docs" , "style" , "refactor" , "perf" , "test" , "revert" , "ci" , "build" ]:
19+ for type in [
20+ "fix" ,
21+ "feat" ,
22+ "chore" ,
23+ "docs" ,
24+ "style" ,
25+ "refactor" ,
26+ "perf" ,
27+ "test" ,
28+ "revert" ,
29+ "ci" ,
30+ "build" ,
31+ ]:
2032 violations = rule .validate (type + ": föo" , None )
2133 self .assertListEqual ([], violations )
2234
@@ -80,3 +92,30 @@ def test_conventional_commits(self):
8092 for typ in ["föo123" , "123bär" ]:
8193 violations = rule .validate (typ + ": hür dur" , None )
8294 self .assertListEqual ([], violations )
95+
96+ # assert violation if scope is not in scopes
97+ rule = ConventionalCommit ({"scopes" : ["foo" , "bar" ]})
98+ violations = rule .validate ("fix(baz): hellö" , None )
99+ expected_violation = RuleViolation ("CT1" , "Scope is not one of foo, bar" , "fix(baz): hellö" )
100+ self .assertListEqual ([expected_violation ], violations )
101+
102+ # assert no violation if scope is in scopes
103+ rule = ConventionalCommit ({"scopes" : ["foo" , "bar" ]})
104+ violations = rule .validate ("fix(foo): hellö" , None )
105+ self .assertListEqual ([], violations )
106+
107+ # assert no violation if scopes is empty
108+ rule = ConventionalCommit ({"scopes" : []})
109+ violations = rule .validate ("fix(scope): hellö" , None )
110+ self .assertListEqual ([], violations )
111+
112+ # assert violation if scope is required but not specified
113+ rule = ConventionalCommit ({"require-scope" : True })
114+ violations = rule .validate ("fix: hellö" , None )
115+ expected_violation = RuleViolation ("CT1" , "Scope is required" , "fix: hellö" )
116+ self .assertListEqual ([expected_violation ], violations )
117+
118+ # assert no violation if scope is not required and not specified
119+ rule = ConventionalCommit ({"require-scope" : False })
120+ violations = rule .validate ("fix: hellö" , None )
121+ self .assertListEqual ([], violations )
0 commit comments