forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskListServiceTests.fs
68 lines (55 loc) · 1.88 KB
/
TaskListServiceTests.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
module FSharp.Editor.Tests.TaskListServiceTests
open System
open System.Threading
open Xunit
open Microsoft.CodeAnalysis
open Microsoft.VisualStudio.FSharp.Editor
open Microsoft.IO
open FSharp.Editor.Tests.Helpers
open Microsoft.CodeAnalysis.Text
let createDocument (fileContents: string) =
RoslynTestHelpers.CreateSolution(fileContents)
|> RoslynTestHelpers.GetSingleDocument
let private service =
new Microsoft.VisualStudio.FSharp.Editor.FSharpTaskListService()
let private ct = CancellationToken.None
let private descriptors =
[| "TODO"; "HACK" |] |> Array.map (fun s -> s, Unchecked.defaultof<_>)
let assertTasks expectedTasks fileContents =
let doc = createDocument fileContents
let sourceText = doc.GetTextAsync().Result
let t = service.GetTaskListItems(doc, sourceText, [], descriptors, ct)
let tasks = t |> Seq.map (fun t -> t.Message) |> List.ofSeq
Assert.Equal<string list>(expectedTasks |> List.sort, tasks |> List.sort)
[<Fact>]
let ``End of line comment is a task`` () =
assertTasks [ "TODO improve" ] "let x = 1 // TODO improve"
[<Fact>]
let ``Inline comments are tasks`` () =
assertTasks [ "TODO first "; "HACK second " ] "let x = 1 (* TODO first *) + 2 (* HACK second *)"
[<Fact>]
let ``ifdef code is not a task`` () =
"""
let x = 1
#if UNDEFINED_VAR
// TODO not here
#endif
"""
|> assertTasks []
[<Fact>]
let ``Multiline comment can have more tasks`` () =
"""
(* TODO first
TODO second
TODO third *)
"""
|> assertTasks [ "TODO first"; "TODO second"; "TODO third " ]
[<Fact>]
let ``Lowercase todo is still a task`` () =
assertTasks [ "todo improve" ] "let x = 1 // todo improve"
[<Fact>]
let ``Descriptor followed by letter is NOT a task`` () =
assertTasks [] "let x = 1 // hackathon solution"
[<Fact>]
let ``Descriptor followed by non-letter is OK`` () =
assertTasks [ "HACK2: using 1" ] "let x = 1 // HACK2: using 1"