Skip to content

Commit

Permalink
fix test failures in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Feb 3, 2025
1 parent e38caff commit a8f7051
Showing 1 changed file with 116 additions and 87 deletions.
203 changes: 116 additions & 87 deletions test/FsAutoComplete.Tests.Lsp/CoreTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ let initTests createServer =
})

let validateSymbolExists msgType symbolInfos predicate =
Expect.exists
symbolInfos
predicate
$"{msgType}s do not contain the expected symbol"
Expect.exists symbolInfos predicate $"{msgType}s do not contain the expected symbol"

let allSymbolInfosExist (infos: SymbolInformation seq) predicates =
predicates |> List.iter (validateSymbolExists (nameof SymbolInformation) infos)
Expand Down Expand Up @@ -187,16 +184,12 @@ let documentSymbolTest state =
| Ok(Some(U2.C1 symbolInformations)) ->
Expect.equal symbolInformations.Length 15 "Document Symbol has all symbols"

allSymbolInfosExist
symbolInformations
[fun n -> n.Name = "MyDateTime" && n.Kind = SymbolKind.Class]
allSymbolInfosExist symbolInformations [ fun n -> n.Name = "MyDateTime" && n.Kind = SymbolKind.Class ]

| Ok(Some(U2.C2 documentSymbols)) ->
Expect.equal documentSymbols.Length 15 "Document Symbol has all symbols"

allDocumentSymbolsExist
documentSymbols
[fun n -> n.Name = "MyDateTime" && n.Kind = SymbolKind.Class]
allDocumentSymbolsExist documentSymbols [ fun n -> n.Name = "MyDateTime" && n.Kind = SymbolKind.Class ]
} ]

let workspaceSymbolTest state =
Expand All @@ -213,8 +206,7 @@ let workspaceSymbolTest state =

testList
"Workspace Symbols Tests"
[
testCaseAsync "Get Workspace Symbols Using Filename of Script File as Query"
[ testCaseAsync "Get Workspace Symbols Using Filename of Script File as Query"
<| async {
let! server, _path = server

Expand All @@ -231,16 +223,12 @@ let workspaceSymbolTest state =
| Ok(Some(U2.C1 symbolInfos)) ->
Expect.equal symbolInfos.Length 1 "Workspace did not find all the expected symbols"

allSymbolInfosExist
symbolInfos
[fun n -> n.Name = "Script" && n.Kind = SymbolKind.Module]
allSymbolInfosExist symbolInfos [ fun n -> n.Name = "Script" && n.Kind = SymbolKind.Module ]

| Ok(Some(U2.C2 workspaceSymbols)) ->
Expect.equal workspaceSymbols.Length 1 "Workspace did not find all the expected symbols"

allWorkspaceSymbolsExist
workspaceSymbols
[fun n -> n.Name = "Script" && n.Kind = SymbolKind.Module]
allWorkspaceSymbolsExist workspaceSymbols [ fun n -> n.Name = "Script" && n.Kind = SymbolKind.Module ]
}

testCaseAsync "Get Workspace Symbols Using Query w/ Text"
Expand All @@ -262,26 +250,22 @@ let workspaceSymbolTest state =

allSymbolInfosExist
symbolInfos
[
fun n -> n.Name = "X" && n.Kind = SymbolKind.Class
[ fun n -> n.Name = "X" && n.Kind = SymbolKind.Class
fun n -> n.Name = "X" && n.Kind = SymbolKind.Class
fun n -> n.Name = "X.X" && n.Kind = SymbolKind.Module
fun n -> n.Name = "X.Y" && n.Kind = SymbolKind.Module
fun n -> n.Name = "X.Z" && n.Kind = SymbolKind.Class
]
fun n -> n.Name = "X.Z" && n.Kind = SymbolKind.Class ]

| Ok(Some(U2.C2 workspaceSymbols)) ->
Expect.equal workspaceSymbols.Length 5 "Workspace did not find all the expected symbols"

allWorkspaceSymbolsExist
workspaceSymbols
[
fun n -> n.Name = "X" && n.Kind = SymbolKind.Class
[ fun n -> n.Name = "X" && n.Kind = SymbolKind.Class
fun n -> n.Name = "X" && n.Kind = SymbolKind.Class
fun n -> n.Name = "X.X" && n.Kind = SymbolKind.Module
fun n -> n.Name = "X.Y" && n.Kind = SymbolKind.Module
fun n -> n.Name = "X.Z" && n.Kind = SymbolKind.Class
]
fun n -> n.Name = "X.Z" && n.Kind = SymbolKind.Class ]
}

testCaseAsync "Get Workspace Symbols Using Query w/o Text"
Expand All @@ -298,12 +282,9 @@ let workspaceSymbolTest state =
match res with
| Result.Error e -> failtestf "Request failed: %A" e
| Ok None -> failtest "Request none"
| Ok(Some(U2.C1 res)) ->
Expect.equal res.Length 0 "Workspace found symbols when we didn't expect to find any"
| Ok(Some(U2.C2 res)) ->
Expect.equal res.Length 0 "Workspace found symbols when we didn't expect to find any"
}
]
| Ok(Some(U2.C1 res)) -> Expect.equal res.Length 0 "Workspace found symbols when we didn't expect to find any"
| Ok(Some(U2.C2 res)) -> Expect.equal res.Length 0 "Workspace found symbols when we didn't expect to find any"
} ]


let foldingTests state =
Expand Down Expand Up @@ -438,7 +419,8 @@ let tooltipTests state =
"tooltip evaluation"
[ testList
"tests"
[ verifyDescription "language keywords"
[ verifyDescription
"language keywords"
0u
2u
[ "**Description**"
Expand All @@ -450,8 +432,13 @@ let tooltipTests state =
verifySignature "trigger.innerCharacter" 0u 5u "val arrayOfTuples: (int * int) array" // inner positions trigger
verifySignature "uses prefix generics" 1u 5u "val listOfTuples: list<int * int>" // verify we default to prefix-generics style
verifySignature "struct tuple handling" 2u 5u "val listOfStructTuples: list<struct (int * int)>" // verify we render struct tuples in a round-tripabble format
verifySignature "strip meaningless units of measure" 3u 5u "val floatThatShouldHaveGenericReportedInTooltip: float" // verify we strip <MeasureOne> measure annotations
verifyDescription "tooltip formatting for external library functions"
verifySignature
"strip meaningless units of measure"
3u
5u
"val floatThatShouldHaveGenericReportedInTooltip: float" // verify we strip <MeasureOne> measure annotations
verifyDescription
"tooltip formatting for external library functions"
4u
4u
[ "**Description**"
Expand All @@ -469,7 +456,8 @@ let tooltipTests state =
"**Generic Parameters**"
""
"* `'T` is `System.String`" ] // verify fancy descriptions for external library functions and correct backticks for multiple segments
verifyDescription "multiple generic parameters are explained"
verifyDescription
"multiple generic parameters are explained"
13u
11u
[ "**Description**"
Expand All @@ -491,34 +479,51 @@ let tooltipTests state =
verifySignature "mixed struct and reference tuples" 15u 5u "val nestedStructTuples: int * struct (int * int)" // verify we can differentiate between struct and non-struct tuples
verifySignature "units of measure are rendered nicely" 21u 9u "val speed: float<m/s>" // verify we nicely-render measure annotations
// verify formatting of function-parameters to values. NOTE: we want to wrap them in parens for user clarity eventually.
verifySignature "parameters that are functions are wrapped in parens for clarity"
verifySignature
"parameters that are functions are wrapped in parens for clarity"
26u
5u
(concatLines [ "val funcWithFunParam:"; " f: (int -> unit) ->"; " i: int"; " -> unit" ])
// verify formatting of tuple args. NOTE: we want to wrap tuples in parens for user clarify eventually.
verifySignature "tuple args are split on each line"
verifySignature
"tuple args are split on each line"
30u
12u
(concatLines [ "val funcWithTupleParam:"; " int *"; " int"; " -> int * int" ])
// verify formatting of struct tuple args in parameter tooltips.
verifySignature "struct tuple parameters are rendered correctly"
verifySignature
"struct tuple parameters are rendered correctly"
32u
12u
(concatLines
[ "val funcWithStructTupleParam:"
" f: struct (int * int)"
" -> struct (int * int)" ])
verifySignature "tuple member parameters are gathered on single line" 36u 15u (concatLines [ "member Foo:"; " stuff: int * int * int"; " -> int" ])
verifySignature "multiple named member parameters are split on each line"
verifySignature
"tuple member parameters are gathered on single line"
36u
15u
(concatLines [ "member Foo:"; " stuff: int * int * int"; " -> int" ])
verifySignature
"multiple named member parameters are split on each line"
37u
15u
(concatLines [ "member Bar:"; " a: int *"; " b: int *"; " c: int"; " -> int" ])
// verify formatting for multi-char operators
verifySignature "multi-char operator rendering" 39u 7u (concatLines [ "val ( .>> ):"; " x: int ->"; " y: int"; " -> int" ])
verifySignature
"multi-char operator rendering"
39u
7u
(concatLines [ "val ( .>> ):"; " x: int ->"; " y: int"; " -> int" ])
// verify formatting for single-char operators
verifySignature "single-char operator rendering" 41u 6u (concatLines [ "val ( ^ ):"; " x: int ->"; " y: int"; " -> int" ])
verifySignature
"single-char operator rendering"
41u
6u
(concatLines [ "val ( ^ ):"; " x: int ->"; " y: int"; " -> int" ])
// verify rendering of generic constraints
verifySignature "generic constraints on parameters"
verifySignature
"generic constraints on parameters"
43u
13u
(concatLines
Expand All @@ -527,93 +532,117 @@ let tooltipTests state =
" y: 'b (requires static member ( + ))"
" -> 'c" ])
//verify rendering of solved generic constraints in tooltips for members where they are solved
verifyDescription "solved generic parameters are called out in tooltip"
verifyDescription
"solved generic parameters are called out in tooltip"
45u
15u
[ "**Generic Parameters**"
""
"* `'a` is `int`"
"* `'b` is `int`"
"* `'c` is `int`" ]
verifySignature "optional member parameters are rendered with leading question mark"
verifySignature
"optional member parameters are rendered with leading question mark"
48u
28u
(concatLines
[ "static member Start:"
" body : (MailboxProcessor<string> -> Async<unit>) *"
" ?cancellationToken: System.Threading.CancellationToken"
" -> MailboxProcessor<string>" ])
verifySignature "union case named parameters are rendered" 54u 9u "Case2 of string * newlineBefore: bool * newlineAfter: bool"
verifySignature "active pattern signatures with potentially-nullable results"
verifySignature
"union case named parameters are rendered"
54u
9u
"Case2 of string * newlineBefore: bool * newlineAfter: bool"
verifySignature
"active pattern signatures with potentially-nullable results"
60u
7u
(concatLines
#if NET8_0
[ "active pattern Value: "
" input: Expr"
" -> option<obj * System.Type>" ])
#else
[ "active pattern Value: "
" input: Expr"
" -> option<objnull * System.Type>" ])
verifySignature "generic constraint rendering for IWSAM"
#endif
verifySignature
"generic constraint rendering for IWSAM"
77u
5u
(concatLines [
"val testIWSAMTest:"
(concatLines
[ "val testIWSAMTest:"
" unit"
" -> Result<string,'e> (requires :> IWSAMTest<'e>)"
])
verifySignature "multiple generic constraints for IWASMs"
" -> Result<string | null,'e> (requires :> IWSAMTest<'e>)" ])
verifySignature
"multiple generic constraints for IWASMs"
90u
25u
(concatLines [
"static member GetAwaiter:"
(concatLines
[ "static member GetAwaiter:"
" awaitable: 'Awaitable (requires member GetAwaiter)"
" -> Awaiter<^Awaiter,'TResult> (requires :> ICriticalNotifyCompletion and member IsCompleted and member GetResult)"
])
verifySignature "basic active pattern"
" -> Awaiter<^Awaiter,'TResult> (requires :> ICriticalNotifyCompletion and member IsCompleted and member GetResult)" ])
verifySignature
"basic active pattern"
65u
7u
(concatLines
[ "active pattern DefaultValue: "
" input: Expr"
" -> option<System.Type>" ])
verifySignature "basic active pattern with nullability awareness"
verifySignature
"basic active pattern with nullability awareness"
70u
7u
(concatLines
#if NET8_0
[ "active pattern ValueWithName: "
" input: Expr"
" -> option<obj * System.Type * string>" ])
#else
[ "active pattern ValueWithName: "
" input: Expr"
" -> option<objnull * System.Type * string>" ])
verifySignature "interface with members with and without parameter names"
#endif
verifySignature
"interface with members with and without parameter names"
96u
7u
(concatLines
[ "interface IWithAndWithoutParamNames"
" abstract member WithParamNames: arg1: int * arg2: float -> string"
" abstract member WithoutParamNames: int * string -> int" ])
verifySignature "function with unsolved nullable parameter" 102u 7u (concatLines [
"val usesNullable:"
" x: 't | null"
" -> 't (requires reference)"
])

verifySignature "function with concrete nullable parameter" 103u 7u (concatLines [
"val usesConcreteNullable:"
" x: string | null"
" -> String"
])
verifySignature "function with generic nullable return" 104u 7u (concatLines [
"val makesNullable:"
" x: 'x"
" -> 'x | null (requires reference)"
])
verifySignature "function with concrete nullable return" 105u 7u (concatLines [
"val makesConcreteNullable:"
" x: string"
" -> string | null"
])
verifySignature "function with nullable return from BCL call" 106u 7u (concatLines [
"val usesBCLNullable:"
" key: string"
" -> string | null"
])] ]
#if NET8_0_OR_GREATER
verifySignature
"function with unsolved nullable parameter"
102u
7u
(concatLines [ "val usesNullable:"; " x: 't | null"; " -> 't (requires reference)" ])
verifySignature
"function with concrete nullable parameter"
103u
7u
(concatLines [ "val usesConcreteNullable:"; " x: string | null"; " -> String" ])
verifySignature
"function with generic nullable return"
104u
7u
(concatLines [ "val makesNullable:"; " x: 'x"; " -> 'x | null (requires reference)" ])
verifySignature
"function with concrete nullable return"
105u
7u
(concatLines [ "val makesConcreteNullable:"; " x: string"; " -> string | null" ])
verifySignature
"function with nullable return from BCL call"
106u
7u
(concatLines [ "val usesBCLNullable:"; " key: string"; " -> string | null" ])
#endif
] ]

let closeTests state =
// Note: clear diagnostics also implies clear caches (-> remove file & project options from State).
Expand Down

0 comments on commit a8f7051

Please sign in to comment.