未验证 提交 63689142 编写于 作者: W Will Smith 提交者: GitHub

Merge pull request #3955 from TIHan/ide-test-fix1

Added tests to CompletionProvider tests. Cleaned up formatting for CompletionProvider tests.
......@@ -49,6 +49,9 @@ let internal projectOptions = {
Stamp = None
}
let formatCompletions(completions : string seq) =
"\n\t" + String.Join("\n\t", completions)
let VerifyCompletionList(fileContents: string, marker: string, expected: string list, unexpected: string list) =
let caretPosition = fileContents.IndexOf(marker) + marker.Length
let results =
......@@ -57,11 +60,44 @@ let VerifyCompletionList(fileContents: string, marker: string, expected: string
|> Option.defaultValue (ResizeArray())
|> Seq.map(fun result -> result.DisplayText)
for item in expected do
Assert.IsTrue(results.Contains(item), sprintf "Completions should contain '%s'. Got '%s'." item (String.Join(", ", results)))
let expectedFound =
expected
|> Seq.filter results.Contains
let expectedNotFound =
expected
|> Seq.filter (expectedFound.Contains >> not)
let unexpectedNotFound =
unexpected
|> Seq.filter (results.Contains >> not)
let unexpectedFound =
unexpected
|> Seq.filter (unexpectedNotFound.Contains >> not)
// If either of these are true, then the test fails.
let hasExpectedNotFound = not (Seq.isEmpty expectedNotFound)
let hasUnexpectedFound = not (Seq.isEmpty unexpectedFound)
if hasExpectedNotFound || hasUnexpectedFound then
let expectedNotFoundMsg =
if hasExpectedNotFound then
sprintf "\nExpected completions not found:%s\n" (formatCompletions expectedNotFound)
else
String.Empty
for item in unexpected do
Assert.IsFalse(results.Contains(item), sprintf "Completions should not contain '%s'. Got '{%s}'" item (String.Join(", ", results)))
let unexpectedFoundMsg =
if hasUnexpectedFound then
sprintf "\nUnexpected completions found:%s\n" (formatCompletions unexpectedFound)
else
String.Empty
let completionsMsg = sprintf "\nin Completions:%s" (formatCompletions results)
let msg = sprintf "%s%s%s" expectedNotFoundMsg unexpectedFoundMsg completionsMsg
Assert.Fail(msg)
let VerifyCompletionListExactly(fileContents: string, marker: string, expected: string list) =
let caretPosition = fileContents.IndexOf(marker) + marker.Length
......@@ -259,6 +295,52 @@ x.
"ToArray"; "ToString"; "TrimExcess"; "TrueForAll"]
VerifyCompletionListExactly(fileContents, "x.", expected)
[<Test;Ignore("Before this test can pass, the test below needs to pass. Related to: https://github.com/Microsoft/visualfsharp/issues/2973")>]
let ``Constructing a new class with object initializer syntax``() =
let fileContents = """
type A() =
member val SettableProperty = 1 with get, set
member val AnotherSettableProperty = 1 with get, set
member val NonSettableProperty = 1
let _ = new A(Setta
"""
let expected = ["SettableProperty"; "AnotherSettableProperty"]
let notExpected = ["NonSettableProperty"]
VerifyCompletionList(fileContents, "(Setta", expected, notExpected)
[<Test;Ignore("https://github.com/Microsoft/visualfsharp/issues/2973")>]
let ``Constructing a new class with object initializer syntax and verifying 'at' character doesn't exist.``() =
let fileContents = """
type A() =
member val SettableProperty = 1 with get, set
member val AnotherSettableProperty = 1 with get, set
member val NonSettableProperty = 1
let _ = new A(Setta
"""
let expected = []
let notExpected = ["SettableProperty@"; "AnotherSettableProperty@"; "NonSettableProperty@"]
VerifyCompletionList(fileContents, "(Setta", expected, notExpected)
[<Test;Ignore("https://github.com/Microsoft/visualfsharp/issues/3954")>]
let ``Constructing a new fully qualified class with object initializer syntax``() =
let fileContents = """
module M =
type A() =
member val SettableProperty = 1 with get, set
member val AnotherSettableProperty = 1 with get, set
member val NonSettableProperty = 1
let _ = new M.A(Setta
"""
let expected = ["SettableProperty"; "AnotherSettableProperty"]
let notExpected = ["NonSettableProperty"]
VerifyCompletionList(fileContents, "(Setta", expected, notExpected)
[<Test>]
let ``Extension methods go after everything else, extension properties are treated as normal ones``() =
let fileContents = """
......
......@@ -596,7 +596,6 @@ a.
AssertCtrlSpaceCompleteContains (typeDef3 @ ["new M.A((**))"]) "A((**)" ["SettableProperty"; "AnotherSettableProperty"] ["NonSettableProperty"]
AssertCtrlSpaceCompleteContains (typeDef3 @ ["new M.A(S = 1)"]) "A(S" ["SettableProperty"] ["NonSettableProperty"]
AssertCtrlSpaceCompleteContains (typeDef3 @ ["new M.A(S = 1)"]) "A(S = 1" [] ["NonSettableProperty"; "SettableProperty"] // neg test
AssertCtrlSpaceCompleteContains (typeDef3 @ ["new M.A(S = 1,)"]) "A(S = 1," ["AnotherSettableProperty"] ["NonSettableProperty"]
let typeDef4 =
[
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册