Skip to content

Commit ca6c03e

Browse files
committed
more tests
1 parent d4c67dc commit ca6c03e

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/NamedPatPairs/NamedPatPairs.fs

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,4 +318,84 @@ but here has type
318318
|> ignoreWarnings
319319
|> withLangVersionPreview
320320
|> verifyCompileAndRun
321-
|> shouldSucceed
321+
|> shouldSucceed
322+
323+
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NamedPatPairs17.fs"|])>]
324+
let ``Version9: NamedPatPairs - NamedPatPairs17_fs`` compilation =
325+
compilation
326+
|> ignoreWarnings
327+
|> withLangVersion90
328+
|> typecheck
329+
|> shouldFail
330+
|> withDiagnostics [
331+
(Error 3350, Line 10, Col 21, Line 10, Col 22, "Feature 'Allow comma as union case name field separator.' is not available in F# 9.0. Please use language version 'PREVIEW' or greater.")
332+
]
333+
334+
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NamedPatPairs17.fs"|])>]
335+
let ``Preview: NamedPatPairs - NamedPatPairs17_fs`` compilation =
336+
compilation
337+
|> ignoreWarnings
338+
|> withLangVersionPreview
339+
|> typecheck
340+
|> shouldFail
341+
|> withDiagnostics [
342+
(Error 1, Line 9, Col 17, Line 9, Col 21, "This expression was expected to have type
343+
'int'
344+
but here has type
345+
''a * 'b' ");
346+
(Error 1, Line 10, Col 17, Line 10, Col 21, "This expression was expected to have type
347+
'float'
348+
but here has type
349+
''a * 'b' ");
350+
(Error 1, Line 10, Col 27, Line 10, Col 31, "This expression was expected to have type
351+
'bool'
352+
but here has type
353+
''a * 'b' ");
354+
(Warning 25, Line 7, Col 11, Line 7, Col 16, "Incomplete pattern matches on this expression.")
355+
]
356+
357+
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NamedPatPairs18.fs"|])>]
358+
let ``Version9: NamedPatPairs - NamedPatPairs18_fs`` compilation =
359+
compilation
360+
|> ignoreWarnings
361+
|> withLangVersion90
362+
|> typecheck
363+
|> shouldFail
364+
|> withDiagnostics [
365+
(Error 1, Line 9, Col 17, Line 9, Col 21, "This expression was expected to have type
366+
'int'
367+
but here has type
368+
''a * 'b' ");
369+
(Error 1, Line 10, Col 17, Line 10, Col 21, "This expression was expected to have type
370+
'float'
371+
but here has type
372+
''a * 'b' ");
373+
(Error 1, Line 10, Col 27, Line 10, Col 31, "This expression was expected to have type
374+
'bool'
375+
but here has type
376+
''a * 'b' ");
377+
(Warning 25, Line 7, Col 11, Line 7, Col 16, "Incomplete pattern matches on this expression.")
378+
]
379+
380+
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"NamedPatPairs18.fs"|])>]
381+
let ``Preview: NamedPatPairs - NamedPatPairs18_fs`` compilation =
382+
compilation
383+
|> ignoreWarnings
384+
|> withLangVersionPreview
385+
|> typecheck
386+
|> shouldFail
387+
|> withDiagnostics [
388+
(Error 1, Line 9, Col 17, Line 9, Col 21, "This expression was expected to have type
389+
'int'
390+
but here has type
391+
''a * 'b' ");
392+
(Error 1, Line 10, Col 17, Line 10, Col 21, "This expression was expected to have type
393+
'float'
394+
but here has type
395+
''a * 'b' ");
396+
(Error 1, Line 10, Col 27, Line 10, Col 31, "This expression was expected to have type
397+
'bool'
398+
but here has type
399+
''a * 'b' ");
400+
(Warning 25, Line 7, Col 11, Line 7, Col 16, "Incomplete pattern matches on this expression.")
401+
]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
type MyUnion =
2+
| CaseA of x: int
3+
| CaseB of x: int * y: string
4+
| CaseC of x: float * y: bool * z: char
5+
6+
let testComma value =
7+
match value with
8+
| CaseA(x = x) -> sprintf "CaseA: a=%d" x
9+
| CaseB(x = x, _) -> sprintf "CaseA: a=%d" x
10+
| CaseC(x = p, a, y = q, r) -> sprintf "CaseB: x=%f, y=%b" p q
11+
12+
let expected =
13+
[ "CaseA: a=42"
14+
"CaseA: a=7"
15+
"CaseB: x=3.140000, y=true" ]
16+
17+
let actual =
18+
[ testComma (CaseA 42)
19+
testComma (CaseB(7, "hello"))
20+
testComma (CaseC(3.14, true, 'z')) ]
21+
22+
if actual <> expected then
23+
failwithf "expected: %A, got: %A" expected actual
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
type MyUnion =
2+
| CaseA of x: int
3+
| CaseB of x: int * y: string
4+
| CaseC of x: float * y: bool * z: char
5+
6+
let testComma value =
7+
match value with
8+
| CaseA(x = x) -> sprintf "CaseA: a=%d" x
9+
| CaseB(x = x, _) -> sprintf "CaseA: a=%d" x
10+
| CaseC(x = p, a; y = q, r) -> sprintf "CaseB: x=%f, y=%b" p q
11+
12+
let expected =
13+
[ "CaseA: a=42"
14+
"CaseA: a=7"
15+
"CaseB: x=3.140000, y=true" ]
16+
17+
let actual =
18+
[ testComma (CaseA 42)
19+
testComma (CaseB(7, "hello"))
20+
testComma (CaseC(3.14, true, 'z')) ]
21+
22+
if actual <> expected then
23+
failwithf "expected: %A, got: %A" expected actual

0 commit comments

Comments
 (0)