forked from fsprojects/fantomas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActivePatternTests.fs
65 lines (55 loc) · 1.75 KB
/
ActivePatternTests.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
module Fantomas.Tests.ActivePatternTests
open NUnit.Framework
open FsUnit
open Fantomas.CodeFormatter
open Fantomas.Tests.TestHelper
[<Test>]
let ``should keep parens around active patterns``() =
formatSourceString false """let (|Boolean|_|) = Boolean.parse
""" config
|> should equal """let (|Boolean|_|) = Boolean.parse
"""
[<Test>]
let ``should keep parens around active patterns in module``() =
formatSourceString false """module Interpreted =
let (|Match|_|) = (|Match|_|) RegexOptions.None
""" config
|> prepend newline
|> should equal """
module Interpreted =
let (|Match|_|) = (|Match|_|) RegexOptions.None
"""
[<Test>]
let ``should keep parens around active patterns in inlined functions``() =
formatSourceString false """let inline (|Match|_|) x = tryMatchWithOptions x
""" config
|> should equal """let inline (|Match|_|) x = tryMatchWithOptions x
"""
[<Test>]
let ``active patterns``() =
formatSourceString false """
let (|Even|Odd|) input = if input % 2 = 0 then Even else Odd
let (|Integer|_|) (str: string) =
let mutable intvalue = 0
if System.Int32.TryParse(str, &intvalue) then Some(intvalue)
else None
let (|ParseRegex|_|) regex str =
let m = Regex(regex).Match(str)
if m.Success
then Some (List.tail [ for x in m.Groups -> x.Value ])
else None""" config
|> prepend newline
|> should equal """
let (|Even|Odd|) input =
if input % 2 = 0 then Even
else Odd
let (|Integer|_|) (str : string) =
let mutable intvalue = 0
if System.Int32.TryParse(str, &intvalue) then Some(intvalue)
else None
let (|ParseRegex|_|) regex str =
let m = Regex(regex).Match(str)
if m.Success then
Some(List.tail [ for x in m.Groups -> x.Value ])
else None
"""