Skip to content

Commit 47519ee

Browse files
committed
more test cases
1 parent 9f6792e commit 47519ee

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

IDisposableAnalyzers.Test/Helpers/DisposableTests.Ignores.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,12 @@ public void Dispose()
10901090
Assert.AreEqual(false, Disposable.Ignores(value, semanticModel, CancellationToken.None));
10911091
}
10921092

1093-
[Test]
1094-
public static void Builder()
1093+
[TestCase(".Append(1)")]
1094+
[TestCase(".Append(true)")]
1095+
[TestCase(".Append((string?)null)")]
1096+
[TestCase(".Append(condition)")]
1097+
[TestCase(".Append(!condition, null)")]
1098+
public static void Builder(string expression)
10951099
{
10961100
var syntaxTree = CSharpSyntaxTree.ParseText("""
10971101
namespace N;
@@ -1100,7 +1104,23 @@ namespace N;
11001104
11011105
public record struct S : IDisposable
11021106
{
1103-
public S Append(int value)
1107+
internal Request Append(string? value, string? name = null)
1108+
{
1109+
if (value is not null)
1110+
{
1111+
foreach (var c in value)
1112+
{
1113+
this.bytes[this.position] = (byte)c;
1114+
this.position++;
1115+
}
1116+
}
1117+
1118+
this.bytes[this.position] = 0;
1119+
this.position++;
1120+
return this;
1121+
}
1122+
1123+
public S Append(int value, string? name = null)
11041124
{
11051125
if (value > 3)
11061126
{
@@ -1110,16 +1130,16 @@ public S Append(int value)
11101130
throw new Exception();
11111131
}
11121132
1113-
internal S Append(bool value) => this.Append(1);
1133+
internal S Append(bool value, string? name = null) => this.Append(value ? 1 : 0, name);
11141134
11151135
public void Dispose() { }
11161136
1117-
public void M()
1137+
public void M(bool condition)
11181138
{
11191139
using var s = new S().Append(true);
11201140
}
11211141
}
1122-
""");
1142+
""".AssertReplace(".Append(true)", expression));
11231143

11241144
var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }, Settings.Default.MetadataReferences);
11251145
var semanticModel = compilation.GetSemanticModel(syntaxTree);

0 commit comments

Comments
 (0)