Skip to content

Commit 3d67766

Browse files
committed
Fix the iteration of descendant types/namespaces/functions to be consistent regardless the order.
1 parent 43af969 commit 3d67766

File tree

8 files changed

+100
-30
lines changed

8 files changed

+100
-30
lines changed

Source/AsyncGenerator.Core/Extensions/AnalyzationResultExtensions.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ private static IEnumerable<INamespaceAnalyzationResult> GetSelfAndDescendantsNam
2828
}
2929
foreach (var td in GetSelfAndDescendantsNamespacesRecursively(subNamespace, predicate))
3030
{
31-
if (predicate?.Invoke(td) == false)
32-
{
33-
continue;
34-
}
3531
yield return td;
3632
}
3733
}
@@ -57,10 +53,6 @@ private static IEnumerable<ITypeAnalyzationResult> GetSelfAndDescendantsTypesRec
5753
}
5854
foreach (var td in GetSelfAndDescendantsTypesRecursively(subTypeData, predicate))
5955
{
60-
if (predicate?.Invoke(td) == false)
61-
{
62-
continue;
63-
}
6456
yield return td;
6557
}
6658
}
@@ -86,10 +78,6 @@ private static IEnumerable<IFunctionAnalyzationResult> GetSelfAndDescendantsFunc
8678
}
8779
foreach (var td in GetSelfAndDescendantsFunctionsRecursively(subFuncData, predicate))
8880
{
89-
if (predicate?.Invoke(td) == false)
90-
{
91-
continue;
92-
}
9381
yield return td;
9482
}
9583
}

Source/AsyncGenerator.Tests/AsyncGenerator.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268
<Compile Include="NestedNamespaces\Fixture.cs" />
269269
<Compile Include="NestedNamespaces\Input\TestCase.cs" />
270270
<Compile Include="NestedTypes\Fixture.cs" />
271+
<Compile Include="NestedTypes\Input\MultipleNested.cs" />
271272
<Compile Include="NestedTypes\Input\TestCase.cs" />
272273
<Compile Include="NewTypes\Fixture.cs" />
273274
<Compile Include="NewTypes\Input\DerivedAsyncClass.cs" />
@@ -722,6 +723,9 @@
722723
<ItemGroup>
723724
<EmbeddedResource Include="Github\Issue44\Output\TestCase.txt" />
724725
</ItemGroup>
726+
<ItemGroup>
727+
<EmbeddedResource Include="NestedTypes\Output\MultipleNested.txt" />
728+
</ItemGroup>
725729
<Choose>
726730
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
727731
<ItemGroup>

Source/AsyncGenerator.Tests/NestedTypes/Fixture.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
namespace AsyncGenerator.Tests.NestedTypes
1111
{
1212
[TestFixture]
13-
public class Fixture : BaseFixture<TestCase>
13+
public class Fixture : BaseFixture
1414
{
1515
[Test]
1616
public void TestAfterAnalyzation()
1717
{
18-
var config = Configure(p => p
18+
var config = Configure(nameof(TestCase), p => p
1919
.ConfigureAnalyzation(a => a
2020
.MethodConversion(symbol => MethodConversion.Smart)
2121
.AfterAnalyzation(result =>
@@ -34,7 +34,7 @@ public void TestAfterAnalyzation()
3434
[Test]
3535
public void TestAfterTransformation()
3636
{
37-
var config = Configure(p => p
37+
var config = Configure(nameof(TestCase), p => p
3838
.ConfigureAnalyzation(a => a
3939
.MethodConversion(symbol => MethodConversion.Smart)
4040
)
@@ -53,5 +53,28 @@ public void TestAfterTransformation()
5353
var generator = new AsyncCodeGenerator();
5454
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
5555
}
56+
57+
[Test, Repeat(5)]
58+
public void TestMultipleNestedAfterTransformation()
59+
{
60+
var config = Configure(nameof(MultipleNested), p => p
61+
.ConfigureAnalyzation(a => a
62+
.TypeConversion(symbol => symbol.Name == "Nested1" ? TypeConversion.Ignore : TypeConversion.Unknown)
63+
.MethodConversion(symbol => MethodConversion.Smart)
64+
)
65+
.ConfigureTransformation(t => t
66+
.AfterTransformation(result =>
67+
{
68+
AssertValidAnnotations(result);
69+
Assert.AreEqual(1, result.Documents.Count);
70+
var document = result.Documents[0];
71+
Assert.NotNull(document.OriginalModified);
72+
Assert.AreEqual(GetOutputFile(nameof(MultipleNested)), document.Transformed.ToFullString());
73+
})
74+
)
75+
);
76+
var generator = new AsyncCodeGenerator();
77+
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
78+
}
5679
}
5780
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using AsyncGenerator.TestCases;
7+
8+
namespace AsyncGenerator.Tests.NestedTypes.Input
9+
{
10+
public class MultipleNested
11+
{
12+
public void Read()
13+
{
14+
SimpleFile.Read();
15+
}
16+
17+
public class Nested1
18+
{
19+
public bool Property { get; set; }
20+
21+
public void DoSomething()
22+
{
23+
24+
}
25+
}
26+
27+
public class Nested2
28+
{
29+
public bool Property { get; set; }
30+
31+
public void DoSomething()
32+
{
33+
34+
}
35+
}
36+
}
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Linq;
14+
using System.Text;
15+
using System.Threading.Tasks;
16+
using AsyncGenerator.TestCases;
17+
18+
namespace AsyncGenerator.Tests.NestedTypes.Input
19+
{
20+
/// <content>
21+
/// Contains generated async methods
22+
/// </content>
23+
public partial class MultipleNested
24+
{
25+
public Task ReadAsync()
26+
{
27+
return SimpleFile.ReadAsync();
28+
}
29+
}
30+
}

Source/AsyncGenerator/Internal/FunctionData.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,10 @@ private IEnumerable<T> GetSelfAndDescendantsFunctionsRecursively<T>(T functionDa
169169
{
170170
if (predicate?.Invoke(subTypeData) == false)
171171
{
172-
yield break;
172+
continue; // We shall never retrun here in order to be always consistent
173173
}
174174
foreach (var td in GetSelfAndDescendantsFunctionsRecursively(subTypeData, predicate))
175175
{
176-
if (predicate?.Invoke(td) == false)
177-
{
178-
yield break;
179-
}
180176
yield return td;
181177
}
182178
}

Source/AsyncGenerator/Internal/NamespaceData.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,10 @@ private IEnumerable<NamespaceData> GetSelfAndDescendantsNamespaceDataRecursively
101101
{
102102
if (predicate?.Invoke(subTypeData) == false)
103103
{
104-
yield break;
104+
continue; // We shall never retrun here in order to be always consistent
105105
}
106106
foreach (var td in GetSelfAndDescendantsNamespaceDataRecursively(subTypeData, predicate))
107107
{
108-
if (predicate?.Invoke(td) == false)
109-
{
110-
yield break;
111-
}
112108
yield return td;
113109
}
114110
}

Source/AsyncGenerator/Internal/TypeData.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,10 @@ private IEnumerable<TypeData> GetSelfAndDescendantsTypeDataRecursively(TypeData
129129
{
130130
if (predicate?.Invoke(subTypeData) == false)
131131
{
132-
yield break;
132+
continue; // We shall never retrun here in order to be always consistent
133133
}
134134
foreach (var td in GetSelfAndDescendantsTypeDataRecursively(subTypeData, predicate))
135135
{
136-
if (predicate?.Invoke(td) == false)
137-
{
138-
yield break;
139-
}
140136
yield return td;
141137
}
142138
}

0 commit comments

Comments
 (0)