@@ -19,6 +19,20 @@ class FakeTextDocument implements extension.TextDocumentLite {
19
19
}
20
20
}
21
21
22
+ function diag ( line : number , columnStart : number , columnEnd : number , message : string , severity : vscode . DiagnosticSeverity ) : vscode . Diagnostic {
23
+ const range = new vscode . Range ( new vscode . Position ( line , columnStart ) , new vscode . Position ( line , columnEnd ) ) ;
24
+ const returnMe = new vscode . Diagnostic (
25
+ range ,
26
+ message ,
27
+ severity
28
+ ) ;
29
+ returnMe . code = {
30
+ "target" : extension . _private . maxSubjectLineLengthUrl ,
31
+ "value" : "Git Commit Message Structure"
32
+ } ;
33
+ return returnMe ;
34
+ }
35
+
22
36
suite ( 'Git Commit Message Plus' , ( ) => {
23
37
vscode . window . showInformationMessage ( 'Start all tests.' ) ;
24
38
@@ -27,24 +41,36 @@ suite('Git Commit Message Plus', () => {
27
41
assert . deepStrictEqual ( extension . _private . getDiagnostics ( empty ) , [ ] ) ;
28
42
} ) ;
29
43
44
+ test ( 'First line 50 chars' , ( ) => {
45
+ const doc = new FakeTextDocument ( [ 'x' . repeat ( 50 ) ] ) ;
46
+ assert . deepStrictEqual ( extension . _private . getDiagnostics ( doc ) , [ ] ) ;
47
+ } ) ;
48
+
49
+ test ( 'First line 51 chars' , ( ) => {
50
+ const doc = new FakeTextDocument ( [ 'x' . repeat ( 51 ) ] ) ;
51
+
52
+ const expected = diag ( 0 , 50 , 51 , `Try keeping the subject to at most 50 characters` , vscode . DiagnosticSeverity . Hint ) ;
53
+
54
+ assert . deepStrictEqual ( extension . _private . getDiagnostics ( doc ) , [ expected ] ) ;
55
+ } ) ;
56
+
30
57
test ( 'First line 72 chars' , ( ) => {
31
- const empty = new FakeTextDocument ( [ 'x' . repeat ( 72 ) ] ) ;
32
- assert . deepStrictEqual ( extension . _private . getDiagnostics ( empty ) , [ ] ) ;
58
+ const doc = new FakeTextDocument ( [ 'x' . repeat ( 72 ) ] ) ;
59
+
60
+ const expected = diag ( 0 , 50 , 72 , `Try keeping the subject to at most 50 characters` , vscode . DiagnosticSeverity . Hint ) ;
61
+
62
+ assert . deepStrictEqual ( extension . _private . getDiagnostics ( doc ) , [ expected ] ) ;
33
63
} ) ;
34
64
35
65
test ( 'First line 73 chars' , ( ) => {
36
- const empty = new FakeTextDocument ( [ 'x' . repeat ( 73 ) ] ) ;
37
-
38
- const expectedRange = new vscode . Range ( new vscode . Position ( 0 , 72 ) , new vscode . Position ( 0 , 73 ) ) ;
39
- const expected = new vscode . Diagnostic (
40
- expectedRange ,
41
- `Subject line should be at most 72 characters` ,
42
- vscode . DiagnosticSeverity . Warning
43
- ) ;
44
- expected . code = {
45
- "target" : extension . _private . maxSubjectLineLengthUrl ,
46
- "value" : "Git Commit Message Structure"
47
- } ;
48
- assert . deepStrictEqual ( extension . _private . getDiagnostics ( empty ) , [ expected ] ) ;
66
+
67
+ const doc = new FakeTextDocument ( [ 'x' . repeat ( 73 ) ] ) ;
68
+
69
+ const expected = [
70
+ diag ( 0 , 50 , 72 , `Try keeping the subject to at most 50 characters` , vscode . DiagnosticSeverity . Hint ) ,
71
+ diag ( 0 , 72 , 73 , `Keep the subject line to at most 72 characters` , vscode . DiagnosticSeverity . Warning ) ,
72
+ ] ;
73
+
74
+ assert . deepStrictEqual ( extension . _private . getDiagnostics ( doc ) , expected ) ;
49
75
} ) ;
50
76
} ) ;
0 commit comments