|
18 | 18 |
|
19 | 19 | class TestRuleRegistry: |
20 | 20 | def test_all_rules_loaded(self) -> None: |
21 | | - assert len(ALL_RULES) == 36 |
| 21 | + assert len(ALL_RULES) == 37 |
22 | 22 |
|
23 | 23 | def test_10_errors(self) -> None: |
24 | 24 | # 8 E-series + 2 T-series (T002 xp-cmdshell, T004 deprecated-outer-join). |
25 | 25 | errors = [r for r in ALL_RULES if r.severity == "error"] |
26 | 26 | assert len(errors) == 10 |
27 | 27 |
|
28 | | - def test_26_warnings(self) -> None: |
29 | | - # 20 W-series + 3 S-series + 3 T-series (T001 with-nolock, |
| 28 | + def test_27_warnings(self) -> None: |
| 29 | + # 21 W-series + 3 S-series + 3 T-series (T001 with-nolock, |
30 | 30 | # T003 cursor-declaration, T005 create-index-without-online). |
31 | 31 | warnings = [r for r in ALL_RULES if r.severity == "warning"] |
32 | | - assert len(warnings) == 26 |
| 32 | + assert len(warnings) == 27 |
33 | 33 |
|
34 | 34 | def test_unique_ids(self) -> None: |
35 | 35 | ids = [r.id for r in ALL_RULES] |
@@ -193,6 +193,26 @@ def test_w016_not_in_value_list_ok(self, tmp_path) -> None: |
193 | 193 | w016 = [f for f in result.findings if f.rule_id == "W016"] |
194 | 194 | assert not w016 |
195 | 195 |
|
| 196 | + def test_w014_case_without_else(self) -> None: |
| 197 | + findings = check([str(FIXTURES / "warnings.sql")]) |
| 198 | + w014 = [f for f in findings.findings if f.rule_id == "W014"] |
| 199 | + assert len(w014) >= 1 |
| 200 | + assert "CASE" in w014[0].message |
| 201 | + |
| 202 | + def test_w014_case_with_else_ok(self, tmp_path) -> None: |
| 203 | + sql = tmp_path / "case_with_else.sql" |
| 204 | + sql.write_text( |
| 205 | + "SELECT CASE\n" |
| 206 | + " WHEN status = 'paid' THEN 1\n" |
| 207 | + " WHEN status = 'pending' THEN 0\n" |
| 208 | + " ELSE NULL\n" |
| 209 | + "END AS paid_flag\n" |
| 210 | + "FROM orders;\n" |
| 211 | + ) |
| 212 | + result = check([str(sql)]) |
| 213 | + w014 = [f for f in result.findings if f.rule_id == "W014"] |
| 214 | + assert not w014 |
| 215 | + |
196 | 216 |
|
197 | 217 | # --------------------------------------------------------------------------- |
198 | 218 | # Clean file |
|
0 commit comments