forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SuggestionBuffer.fs
103 lines (77 loc) · 2.87 KB
/
SuggestionBuffer.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
namespace FSharp.Compiler.UnitTests
open Xunit
open FSharp.Test
module SuggestionBuffer =
open FSharp.Compiler.DiagnosticResolutionHints
[<Fact>]
let NewBufferShouldBeEmpty() =
let buffer = SuggestionBuffer("abdef")
Assert.shouldBeFalse buffer.Disabled
Assert.shouldBeEmpty buffer
[<Fact>]
let BufferShouldOnlyAcceptSimilarElements() =
let buffer = SuggestionBuffer("abcd")
buffer.Add("abce")
buffer.Add("somethingcompletelyunrelated")
let results = Array.ofSeq buffer
Assert.shouldBeEquivalentTo [| "abce" |] results
[<Fact>]
let SmallIdentifierShouldBeIgnored() =
let buffer = SuggestionBuffer("ab")
Assert.shouldBeTrue buffer.Disabled
buffer.Add("abce")
buffer.Add("somethingcompletelyunrelated")
buffer.Add("abcg")
buffer.Add("abch")
buffer.Add("abcde")
buffer.Add("abci")
buffer.Add("abcj")
let results = Array.ofSeq buffer
Assert.shouldBeTrue buffer.Disabled
Assert.shouldBeEquivalentTo [||] results
[<Fact>]
let BufferShouldOnlyTakeTop5Elements() =
let buffer = SuggestionBuffer("abcd")
buffer.Add("abce")
buffer.Add("somethingcompletelyunrelated")
buffer.Add("abcg")
buffer.Add("abch")
buffer.Add("abcde")
buffer.Add("abci")
buffer.Add("abcj")
let results = Array.ofSeq buffer
Assert.shouldBeEquivalentTo [| "abce"; "abcg"; "abch"; "abci"; "abcj"|] results
[<Fact>]
let BufferShouldUseEarlierElementsIfTheyHaveSameScore() =
let buffer = SuggestionBuffer("abcd")
buffer.Add("abce")
buffer.Add("abcf")
buffer.Add("abcg")
buffer.Add("abch")
buffer.Add("abci")
buffer.Add("abcj")
let results = Array.ofSeq buffer
Assert.shouldBeEquivalentTo [| "abce"; "abcf"; "abcg"; "abch"; "abci"|] results
[<Fact>]
let BufferShouldDisableItselfIfItSeesTheOriginalIdentifier() =
let buffer = SuggestionBuffer("abcd")
buffer.Add("abce")
buffer.Add("abcf")
buffer.Add("abcg")
buffer.Add("abch")
Assert.shouldBeFalse buffer.Disabled
Assert.shouldNotBeEmpty buffer
buffer.Add("abcd") // original Ident
buffer.Add("abcj")
Assert.shouldBeTrue buffer.Disabled
Assert.shouldBeEmpty buffer
[<Fact>]
let BufferShouldIgnoreSmallIdentifiers() =
let buffer = SuggestionBuffer("abd")
buffer.Add("abce")
buffer.Add("abc")
buffer.Add("ab")
buffer.Add("ad")
let results = Array.ofSeq buffer
Assert.shouldBeEquivalentTo [| "abc"; "abce" |] results