Skip to content

Commit

Permalink
Fix stub generation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Nov 23, 2024
1 parent 52d1df2 commit 31a3501
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ module Commands =
| None -> return CoreResponse.InfoRes "Record at position not found"
| Some(recordEpr, (Some recordDefinition), insertionPos) ->
if shouldGenerateRecordStub recordEpr recordDefinition then
let result = formatRecord insertionPos "$1" recordDefinition recordEpr.FieldExprList
let result = (formatRecord insertionPos "$1" recordDefinition recordEpr.FieldExprList).TrimStart(' ')
return CoreResponse.Res(result, insertionPos.InsertionPos)
else
return CoreResponse.InfoRes "Record at position not found"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ open Helpers
open Utils.ServerTests
open Utils.CursorbasedTests
open FsAutoComplete.CodeFix
open System.IO

let sourceDir = __SOURCE_DIRECTORY__
let expectedTestDir = Path.Join(sourceDir, "GenerateAbstractClassStubTests")
let expectFile file = File.ReadAllText(Path.Join(expectedTestDir, file))
let tests state =
let config = { defaultConfigDto with AbstractClassStubGeneration = Some true }
serverTestList (nameof GenerateAbstractClassStub) state config None (fun server -> [
Expand All @@ -28,6 +32,7 @@ let tests state =
(Diagnostics.expectCode "365")
selectCodeFix
testCaseAsync "can generate abstract class stub" <|

CodeFix.check server
"""
[<AbstractClass>]
Expand All @@ -46,26 +51,8 @@ let tests state =
()"""
(Diagnostics.expectCode "365")
selectCodeFix
"""
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0
abstract Name : string with get
abstract Area : float with get
member _.Move dx dy =
x <- x + dx
y <- y + dy
(expectFile "can_generate_abstract_class_stub.expected")

type Square(x,y, sideLength) =
inherit Shape(x,y)
override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"
()"""
testCaseAsync "can generate abstract class stub with another member with attribute" <|
CodeFix.check server
"""
Expand All @@ -88,29 +75,8 @@ let tests state =
()"""
(Diagnostics.expectCode "365")
selectCodeFix
"""
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0
(expectFile "can_generate_abstract_class_stub_with_another_member_with_attribute.expected")

abstract Name : string with get
abstract Area : float with get
member _.Move dx dy =
x <- x + dx
y <- y + dy
type Square(x,y, sideLength) =
inherit Shape(x,y)
override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"
[<CompiledName("yo")>]
member x.Foo() = 1
()"""
testCaseAsync "can generate abstract class stub without trailing nl" <|
CodeFix.check server
"""
Expand All @@ -130,26 +96,8 @@ let tests state =
()"""
(Diagnostics.expectCode "365")
selectCodeFix
"""
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0
abstract Name : string with get
abstract Area : float with get
(expectFile "can_generate_abstract_class_stub_without_trailing_nl.expected")

member _.Move dx dy =
x <- x + dx
y <- y + dy
type Square(x,y, sideLength) =
inherit Shape(x,y)
override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"
()"""
testCaseAsync "inserts override in correct place" <|
CodeFix.check server
"""
Expand All @@ -169,26 +117,8 @@ let tests state =
let a = 0"""
(Diagnostics.expectCode "365")
selectCodeFix
"""
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0
abstract Name : string with get
abstract Area : float with get
member _.Move dx dy =
x <- x + dx
y <- y + dy
type Square(x,y, sideLength) =
inherit Shape(x,y)
(expectFile "inserts_override_in_correct_place.expected")

override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"
let a = 0"""
testCaseAsync "can generate abstract class stub with existing override" <|
CodeFix.check server
"""
Expand All @@ -210,24 +140,5 @@ let tests state =
()"""
(Diagnostics.expectCode "365")
selectCodeFix
"""
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0
abstract Name : string with get
abstract Area : float with get
member _.Move dx dy =
x <- x + dx
y <- y + dy
type Square(x,y, sideLength) =
inherit Shape(x,y)
override this.Area: float =
failwith "Not Implemented"
override this.Name = "Circle"
()"""
(expectFile "can_generate_abstract_class_stub_with_existing_override.expected")
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0

abstract Name : string with get
abstract Area : float with get

member _.Move dx dy =
x <- x + dx
y <- y + dy

type Square(x,y, sideLength) =
inherit Shape(x,y)

override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"
()
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0

abstract Name : string with get
abstract Area : float with get

member _.Move dx dy =
x <- x + dx
y <- y + dy

type Square(x,y, sideLength) =
inherit Shape(x,y)

override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"

[<CompiledName("yo")>]
member x.Foo() = 1
()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0

abstract Name : string with get
abstract Area : float with get

member _.Move dx dy =
x <- x + dx
y <- y + dy

type Square(x,y, sideLength) =
inherit Shape(x,y)

override this.Area: float =
failwith "Not Implemented"

override this.Name = "Circle"
()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0

abstract Name : string with get
abstract Area : float with get

member _.Move dx dy =
x <- x + dx
y <- y + dy

type Square(x,y, sideLength) =
inherit Shape(x,y)

override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"
()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[<AbstractClass>]
type Shape(x0: float, y0: float) =
let mutable x, y = x0, y0

abstract Name : string with get
abstract Area : float with get

member _.Move dx dy =
x <- x + dx
y <- y + dy

type Square(x,y, sideLength) =
inherit Shape(x,y)

override this.Area: float =
failwith "Not Implemented"
override this.Name: string =
failwith "Not Implemented"
let a = 0

0 comments on commit 31a3501

Please sign in to comment.