From 0c58de3235594c556cd9e57e8dd4d15e23958a9d Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Sun, 26 Sep 2021 09:40:59 -0700 Subject: [PATCH] more tests --- .../PatternMatchingTests_ListPatterns.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs index 9e3d47c9d7a5e..0c56d48b21ec5 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests_ListPatterns.cs @@ -3411,6 +3411,74 @@ public void LengthPattern_IsIncomplete() ); } + [Fact] + public void LengthPattern_IsIncomplete_() + { + // TODO2 + var src = @" +int[] a = null; +//_ = a is null or { Length: >= 0}; +_ = a switch // 1 +{ + null => 0, + { Length: > -1 and < 3 } => 1, +}; +_ = a switch +{ + null => 0, + { Length: > -1 and < 3 } => 1, + { Length: >= 3 } => 1, +}; +"; + var comp = CreateCompilation(src); + comp.VerifyDiagnostics( + // (4,7): warning CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{ Length: 3 }' is not covered. + // _ = a switch // 1 + Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithArguments("{ Length: 3 }").WithLocation(4, 7) + ); + } + + [Fact] + public void LengthPattern_IsIncomplete_2() + { + // TODO2 + var src = @" +int[] a = null; +//_ = a is null or { Length: >= 0}; +_ = a switch +{ + null => 0, + { Length: 0 } => 1, + { Length: > 0 } => 1, +}; +"; + var comp = CreateCompilation(src); + comp.VerifyDiagnostics( + ); + } + + [Fact] + public void LengthPattern_IsIncomplete_3() + { + // TODO2 + var src = @" +int[] a = null; +//_ = a is null or { Length: >= 0}; +_ = a switch +{ + null => 0, + { Length: 0 } => 1, + { Length: > 1 } => 1, +}; +"; + var comp = CreateCompilation(src); + comp.VerifyDiagnostics( + // (4,7): warning CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '{ Length: 1 }' is not covered. + // _ = a switch + Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithArguments("{ Length: 1 }").WithLocation(4, 7) + ); + } + [Fact] public void LengthPattern_Evaluation() {