Skip to content

Commit 31a3501

Browse files
committed
Fix stub generation tests
1 parent 52d1df2 commit 31a3501

7 files changed

+109
-100
lines changed

src/FsAutoComplete.Core/Commands.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ module Commands =
258258
| None -> return CoreResponse.InfoRes "Record at position not found"
259259
| Some(recordEpr, (Some recordDefinition), insertionPos) ->
260260
if shouldGenerateRecordStub recordEpr recordDefinition then
261-
let result = formatRecord insertionPos "$1" recordDefinition recordEpr.FieldExprList
261+
let result = (formatRecord insertionPos "$1" recordDefinition recordEpr.FieldExprList).TrimStart(' ')
262262
return CoreResponse.Res(result, insertionPos.InsertionPos)
263263
else
264264
return CoreResponse.InfoRes "Record at position not found"

test/FsAutoComplete.Tests.Lsp/CodeFixTests/GenerateAbstractClassStubTests.fs

Lines changed: 10 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ open Helpers
55
open Utils.ServerTests
66
open Utils.CursorbasedTests
77
open FsAutoComplete.CodeFix
8+
open System.IO
89

10+
let sourceDir = __SOURCE_DIRECTORY__
11+
let expectedTestDir = Path.Join(sourceDir, "GenerateAbstractClassStubTests")
12+
let expectFile file = File.ReadAllText(Path.Join(expectedTestDir, file))
913
let tests state =
1014
let config = { defaultConfigDto with AbstractClassStubGeneration = Some true }
1115
serverTestList (nameof GenerateAbstractClassStub) state config None (fun server -> [
@@ -28,6 +32,7 @@ let tests state =
2832
(Diagnostics.expectCode "365")
2933
selectCodeFix
3034
testCaseAsync "can generate abstract class stub" <|
35+
3136
CodeFix.check server
3237
"""
3338
[<AbstractClass>]
@@ -46,26 +51,8 @@ let tests state =
4651
()"""
4752
(Diagnostics.expectCode "365")
4853
selectCodeFix
49-
"""
50-
[<AbstractClass>]
51-
type Shape(x0: float, y0: float) =
52-
let mutable x, y = x0, y0
53-
54-
abstract Name : string with get
55-
abstract Area : float with get
56-
57-
member _.Move dx dy =
58-
x <- x + dx
59-
y <- y + dy
54+
(expectFile "can_generate_abstract_class_stub.expected")
6055

61-
type Square(x,y, sideLength) =
62-
inherit Shape(x,y)
63-
64-
override this.Area: float =
65-
failwith "Not Implemented"
66-
override this.Name: string =
67-
failwith "Not Implemented"
68-
()"""
6956
testCaseAsync "can generate abstract class stub with another member with attribute" <|
7057
CodeFix.check server
7158
"""
@@ -88,29 +75,8 @@ let tests state =
8875
()"""
8976
(Diagnostics.expectCode "365")
9077
selectCodeFix
91-
"""
92-
[<AbstractClass>]
93-
type Shape(x0: float, y0: float) =
94-
let mutable x, y = x0, y0
78+
(expectFile "can_generate_abstract_class_stub_with_another_member_with_attribute.expected")
9579

96-
abstract Name : string with get
97-
abstract Area : float with get
98-
99-
member _.Move dx dy =
100-
x <- x + dx
101-
y <- y + dy
102-
103-
type Square(x,y, sideLength) =
104-
inherit Shape(x,y)
105-
106-
override this.Area: float =
107-
failwith "Not Implemented"
108-
override this.Name: string =
109-
failwith "Not Implemented"
110-
111-
[<CompiledName("yo")>]
112-
member x.Foo() = 1
113-
()"""
11480
testCaseAsync "can generate abstract class stub without trailing nl" <|
11581
CodeFix.check server
11682
"""
@@ -130,26 +96,8 @@ let tests state =
13096
()"""
13197
(Diagnostics.expectCode "365")
13298
selectCodeFix
133-
"""
134-
[<AbstractClass>]
135-
type Shape(x0: float, y0: float) =
136-
let mutable x, y = x0, y0
137-
138-
abstract Name : string with get
139-
abstract Area : float with get
99+
(expectFile "can_generate_abstract_class_stub_without_trailing_nl.expected")
140100

141-
member _.Move dx dy =
142-
x <- x + dx
143-
y <- y + dy
144-
145-
type Square(x,y, sideLength) =
146-
inherit Shape(x,y)
147-
148-
override this.Area: float =
149-
failwith "Not Implemented"
150-
override this.Name: string =
151-
failwith "Not Implemented"
152-
()"""
153101
testCaseAsync "inserts override in correct place" <|
154102
CodeFix.check server
155103
"""
@@ -169,26 +117,8 @@ let tests state =
169117
let a = 0"""
170118
(Diagnostics.expectCode "365")
171119
selectCodeFix
172-
"""
173-
[<AbstractClass>]
174-
type Shape(x0: float, y0: float) =
175-
let mutable x, y = x0, y0
176-
177-
abstract Name : string with get
178-
abstract Area : float with get
179-
180-
member _.Move dx dy =
181-
x <- x + dx
182-
y <- y + dy
183-
184-
type Square(x,y, sideLength) =
185-
inherit Shape(x,y)
120+
(expectFile "inserts_override_in_correct_place.expected")
186121

187-
override this.Area: float =
188-
failwith "Not Implemented"
189-
override this.Name: string =
190-
failwith "Not Implemented"
191-
let a = 0"""
192122
testCaseAsync "can generate abstract class stub with existing override" <|
193123
CodeFix.check server
194124
"""
@@ -210,24 +140,5 @@ let tests state =
210140
()"""
211141
(Diagnostics.expectCode "365")
212142
selectCodeFix
213-
"""
214-
[<AbstractClass>]
215-
type Shape(x0: float, y0: float) =
216-
let mutable x, y = x0, y0
217-
218-
abstract Name : string with get
219-
abstract Area : float with get
220-
221-
member _.Move dx dy =
222-
x <- x + dx
223-
y <- y + dy
224-
225-
type Square(x,y, sideLength) =
226-
inherit Shape(x,y)
227-
228-
override this.Area: float =
229-
failwith "Not Implemented"
230-
231-
override this.Name = "Circle"
232-
()"""
143+
(expectFile "can_generate_abstract_class_stub_with_existing_override.expected")
233144
])
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[<AbstractClass>]
2+
type Shape(x0: float, y0: float) =
3+
let mutable x, y = x0, y0
4+
5+
abstract Name : string with get
6+
abstract Area : float with get
7+
8+
member _.Move dx dy =
9+
x <- x + dx
10+
y <- y + dy
11+
12+
type Square(x,y, sideLength) =
13+
inherit Shape(x,y)
14+
15+
override this.Area: float =
16+
failwith "Not Implemented"
17+
override this.Name: string =
18+
failwith "Not Implemented"
19+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[<AbstractClass>]
2+
type Shape(x0: float, y0: float) =
3+
let mutable x, y = x0, y0
4+
5+
abstract Name : string with get
6+
abstract Area : float with get
7+
8+
member _.Move dx dy =
9+
x <- x + dx
10+
y <- y + dy
11+
12+
type Square(x,y, sideLength) =
13+
inherit Shape(x,y)
14+
15+
override this.Area: float =
16+
failwith "Not Implemented"
17+
override this.Name: string =
18+
failwith "Not Implemented"
19+
20+
[<CompiledName("yo")>]
21+
member x.Foo() = 1
22+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[<AbstractClass>]
2+
type Shape(x0: float, y0: float) =
3+
let mutable x, y = x0, y0
4+
5+
abstract Name : string with get
6+
abstract Area : float with get
7+
8+
member _.Move dx dy =
9+
x <- x + dx
10+
y <- y + dy
11+
12+
type Square(x,y, sideLength) =
13+
inherit Shape(x,y)
14+
15+
override this.Area: float =
16+
failwith "Not Implemented"
17+
18+
override this.Name = "Circle"
19+
()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[<AbstractClass>]
2+
type Shape(x0: float, y0: float) =
3+
let mutable x, y = x0, y0
4+
5+
abstract Name : string with get
6+
abstract Area : float with get
7+
8+
member _.Move dx dy =
9+
x <- x + dx
10+
y <- y + dy
11+
12+
type Square(x,y, sideLength) =
13+
inherit Shape(x,y)
14+
15+
override this.Area: float =
16+
failwith "Not Implemented"
17+
override this.Name: string =
18+
failwith "Not Implemented"
19+
()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[<AbstractClass>]
2+
type Shape(x0: float, y0: float) =
3+
let mutable x, y = x0, y0
4+
5+
abstract Name : string with get
6+
abstract Area : float with get
7+
8+
member _.Move dx dy =
9+
x <- x + dx
10+
y <- y + dy
11+
12+
type Square(x,y, sideLength) =
13+
inherit Shape(x,y)
14+
15+
override this.Area: float =
16+
failwith "Not Implemented"
17+
override this.Name: string =
18+
failwith "Not Implemented"
19+
let a = 0

0 commit comments

Comments
 (0)