forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSourceTextTests.fs
46 lines (40 loc) · 1.59 KB
/
SourceTextTests.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
module FSharp.Compiler.Service.Tests.SourceTextTests
open System
open FSharp.Compiler.Text
open Xunit
[<Fact>]
let ``Select text from a single line via the range`` () =
let sourceText = SourceText.ofString """
let a = 2
"""
let m = Range.mkRange "Sample.fs" (Position.mkPos 2 4) (Position.mkPos 2 5)
let v = sourceText.GetSubTextFromRange m
Assert.Equal("a", v)
[<Fact>]
let ``Select text from multiple lines via the range`` () =
let sourceText = SourceText.ofString """
let a b c =
// comment
2
"""
let m = Range.mkRange "Sample.fs" (Position.mkPos 2 4) (Position.mkPos 4 5)
let v = sourceText.GetSubTextFromRange m
let sanitized = v.Replace("\r", "")
Assert.Equal("a b c =\n // comment\n 2", sanitized)
[<Fact>]
let ``Inconsistent return carriage return correct text`` () =
let sourceText = SourceText.ofString "let a =\r\n // foo\n 43"
let m = Range.mkRange "Sample.fs" (Position.mkPos 1 4) (Position.mkPos 3 6)
let v = sourceText.GetSubTextFromRange m
let sanitized = v.Replace("\r", "")
Assert.Equal("a =\n // foo\n 43", sanitized)
[<Fact>]
let ``Zero range should return empty string`` () =
let sourceText = SourceText.ofString "a"
let v = sourceText.GetSubTextFromRange Range.Zero
Assert.Equal(String.Empty, v)
[<Fact>]
let ``Invalid range should throw argument exception`` () =
let sourceText = SourceText.ofString "a"
let mInvalid = Range.mkRange "Sample.fs" (Position.mkPos 3 6) (Position.mkPos 1 4)
Assert.Throws<ArgumentException>(fun () -> sourceText.GetSubTextFromRange mInvalid |> ignore)