-
Notifications
You must be signed in to change notification settings - Fork 815
/
Copy pathSynPatTests.fs
36 lines (29 loc) · 1.22 KB
/
SynPatTests.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
module FSharp.Compiler.Service.Tests.SynPatTests
open FSharp.Compiler.Service.Tests.Common
open FSharp.Compiler.Syntax
open Xunit
type Parenthesization = Needed | Unneeded
module Parenthesization =
let ofBool shouldParenthesize =
if shouldParenthesize then Needed
else Unneeded
let pats: obj array list =
[
[|[Needed]; "match () with () -> ()"|]
[|[Needed]; "let (Lazy x) = lazy 1"|]
[|[Unneeded; Unneeded]; "let ((Lazy x)) = lazy 1"|]
[|[Needed; Unneeded]; "let (()) = ()"|]
[|[Needed; Unneeded; Unneeded]; "let ((())) = ()"|]
]
// `expected` represents whether each parenthesized pattern, from the inside outward, requires its parentheses.
[<Theory; MemberData(nameof pats)>]
let shouldBeParenthesizedInContext (expected: Parenthesization list) src =
let ast = getParseResults src
let actual =
([], ast)
||> ParsedInput.fold (fun actual path node ->
match node, path with
| SyntaxNode.SynPat pat, SyntaxNode.SynPat(SynPat.Paren _) :: path ->
Parenthesization.ofBool (SynPat.shouldBeParenthesizedInContext path pat) :: actual
| _ -> actual)
Assert.Equal<Parenthesization list>(expected, actual)