@@ -7,6 +7,7 @@ import * as path from "path";
7
7
import * as vscode from "vscode" ;
8
8
import { DocumentSelector } from "vscode-languageclient" ;
9
9
import * as folding from "../../src/features/Folding" ;
10
+ import * as Settings from "../../src/settings" ;
10
11
import { MockLogger } from "../test_utils" ;
11
12
12
13
const fixturePath = path . join ( __dirname , ".." , ".." , ".." , "test" , "fixtures" ) ;
@@ -22,6 +23,13 @@ function assertFoldingRegions(result, expected): void {
22
23
assert . equal ( result . length , expected . length ) ;
23
24
}
24
25
26
+ // Wrap the FoldingProvider class with our own custom settings for testing
27
+ class CustomSettingFoldingProvider extends folding . FoldingProvider {
28
+ public customSettings : Settings . ISettings = Settings . load ( ) ;
29
+ // Overridde the super currentSettings method with our own custom test settings
30
+ public currentSettings ( ) : Settings . ISettings { return this . customSettings ; }
31
+ }
32
+
25
33
suite ( "Features" , ( ) => {
26
34
27
35
suite ( "Folding Provider" , async ( ) => {
@@ -38,21 +46,21 @@ suite("Features", () => {
38
46
39
47
suite ( "For a single document" , async ( ) => {
40
48
const expectedFoldingRegions = [
41
- { start : 0 , end : 4 , kind : 3 } ,
42
- { start : 1 , end : 3 , kind : 1 } ,
43
- { start : 10 , end : 15 , kind : 1 } ,
44
- { start : 16 , end : 60 , kind : null } ,
45
- { start : 17 , end : 22 , kind : 1 } ,
46
- { start : 23 , end : 26 , kind : null } ,
47
- { start : 28 , end : 31 , kind : null } ,
48
- { start : 35 , end : 37 , kind : 1 } ,
49
- { start : 39 , end : 49 , kind : 3 } ,
50
- { start : 41 , end : 45 , kind : 3 } ,
51
- { start : 51 , end : 53 , kind : null } ,
52
- { start : 56 , end : 59 , kind : null } ,
53
- { start : 64 , end : 66 , kind : 1 } ,
54
- { start : 67 , end : 72 , kind : 3 } ,
55
- { start : 68 , end : 70 , kind : 1 } ,
49
+ { start : 0 , end : 3 , kind : 3 } ,
50
+ { start : 1 , end : 2 , kind : 1 } ,
51
+ { start : 10 , end : 14 , kind : 1 } ,
52
+ { start : 16 , end : 59 , kind : null } ,
53
+ { start : 17 , end : 21 , kind : 1 } ,
54
+ { start : 23 , end : 25 , kind : null } ,
55
+ { start : 28 , end : 30 , kind : null } ,
56
+ { start : 35 , end : 36 , kind : 1 } ,
57
+ { start : 39 , end : 48 , kind : 3 } ,
58
+ { start : 41 , end : 44 , kind : 3 } ,
59
+ { start : 51 , end : 52 , kind : null } ,
60
+ { start : 56 , end : 58 , kind : null } ,
61
+ { start : 64 , end : 65 , kind : 1 } ,
62
+ { start : 67 , end : 71 , kind : 3 } ,
63
+ { start : 68 , end : 69 , kind : 1 } ,
56
64
] ;
57
65
58
66
test ( "Can detect all of the foldable regions in a document with CRLF line endings" , async ( ) => {
@@ -83,9 +91,31 @@ suite("Features", () => {
83
91
assertFoldingRegions ( result , expectedFoldingRegions ) ;
84
92
} ) ;
85
93
94
+ suite ( "Where showLastLine setting is false" , async ( ) => {
95
+ const customprovider = ( new CustomSettingFoldingProvider ( psGrammar ) ) ;
96
+ customprovider . customSettings . codeFolding . showLastLine = false ;
97
+
98
+ test ( "Can detect all foldable regions in a document" , async ( ) => {
99
+ // Integration test against the test fixture 'folding-lf.ps1' that contains
100
+ // all of the different types of folding available
101
+ const uri = vscode . Uri . file ( path . join ( fixturePath , "folding-lf.ps1" ) ) ;
102
+ const document = await vscode . workspace . openTextDocument ( uri ) ;
103
+ const result = await customprovider . provideFoldingRanges ( document , null , null ) ;
104
+
105
+ // Incrememnt the end line of the expected regions by one as we will
106
+ // be hiding the last line
107
+ const expectedLastLineRegions = expectedFoldingRegions . map ( ( item ) => {
108
+ item . end ++ ;
109
+ return item ;
110
+ } ) ;
111
+
112
+ assertFoldingRegions ( result , expectedLastLineRegions ) ;
113
+ } ) ;
114
+ } ) ;
115
+
86
116
test ( "Can detect all of the foldable regions in a document with mismatched regions" , async ( ) => {
87
117
const expectedMismatchedFoldingRegions = [
88
- { start : 2 , end : 4 , kind : 3 } ,
118
+ { start : 2 , end : 3 , kind : 3 } ,
89
119
] ;
90
120
91
121
// Integration test against the test fixture 'folding-mismatch.ps1' that contains
@@ -99,8 +129,8 @@ suite("Features", () => {
99
129
100
130
test ( "Does not return duplicate or overlapping regions" , async ( ) => {
101
131
const expectedMismatchedFoldingRegions = [
102
- { start : 1 , end : 2 , kind : null } ,
103
- { start : 2 , end : 4 , kind : null } ,
132
+ { start : 1 , end : 1 , kind : null } ,
133
+ { start : 2 , end : 3 , kind : null } ,
104
134
] ;
105
135
106
136
// Integration test against the test fixture 'folding-mismatch.ps1' that contains
0 commit comments