-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GqlPlus.Generators project, tests and refactorings
- Loading branch information
Showing
15 changed files
with
158 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace GqlPlus; | ||
|
||
[Generator(LanguageNames.CSharp)] | ||
public class GqlModelGenerator : IIncrementalGenerator | ||
{ | ||
public void Initialize(IncrementalGeneratorInitializationContext context) | ||
{ | ||
IncrementalValueProvider<ImmutableArray<string>> samples = context.AdditionalTextsProvider | ||
.Select((text, token) => text.Path) | ||
.Where(path => Path.GetExtension(path).Equals(".graphql+", StringComparison.OrdinalIgnoreCase)) | ||
.Collect(); | ||
|
||
context.RegisterSourceOutput(samples, GenerateCode); | ||
} | ||
|
||
private void GenerateCode(SourceProductionContext context, ImmutableArray<string> array) | ||
{ | ||
if (array.IsDefaultOrEmpty) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<IncludeBuildOutput>false</IncludeBuildOutput> | ||
<IsRoslynComponent>true</IsRoslynComponent> | ||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
13 changes: 13 additions & 0 deletions
13
test/GqlPlus.GeneratorsTestBase/GqlPlus.GeneratorsTestBase.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<IsTestProject>false</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" /> | ||
<PackageReference Include="Verify.Xunit" Version="28.10.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
25 changes: 8 additions & 17 deletions
25
...stGeneratorsTests/TestGeneratorsHelper.cs → ...eneratorsTestBase/TestGeneratorsHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/GqlPlus.GeneratorsTests/GqlModelGeneratorTests.NoAdditionalFiles.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace GqlPlus; | ||
|
||
public class GqlModelGeneratorTests | ||
{ | ||
|
||
[Fact] | ||
public Task NoAdditionalFiles() | ||
{ | ||
string source = "using GqlPlusTests;"; | ||
|
||
GeneratorDriver driver = new GqlModelGenerator() | ||
.Generate(source, []); | ||
|
||
return Verifier.Verify(driver); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test/GqlPlus.GeneratorsTests/GqlPlus.GeneratorsTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\GqlPlus.Generators\GqlPlus.Generators.csproj" /> | ||
<ProjectReference Include="..\GqlPlus.GeneratorsTestBase\GqlPlus.GeneratorsTestBase.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
...eneratorsTests/BuildDataGeneratorTests.UsesAttributeCorrrectly#SampleData.gen.verified.cs
This file was deleted.
Oops, something went wrong.
39 changes: 29 additions & 10 deletions
39
test/GqlPlus.TestGeneratorsTests/BuildDataGeneratorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,50 @@ | ||
namespace GqlPlus; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace GqlPlus; | ||
|
||
public class BuildDataGeneratorTests | ||
{ | ||
private static readonly string[] s_additionalFilesWithIncorrectOne = [ | ||
"Sample/Files/File3.gql+", | ||
"Sample/Files/file2.graphql+", | ||
"Sample/Files/file1.txt", | ||
"Sample/git-details.txt"]; | ||
private static readonly string[] s_additionalSubdirectoryFiles = [ | ||
"Sample/Files/File3.gql", | ||
"Sample/More/file2.graphql+", | ||
"Sample/Files/Deeper/file1.gql+", | ||
"Sample/git-details.txt"]; | ||
|
||
[Fact] | ||
public Task NoAdditionalFiles() | ||
{ | ||
string source = "using GqlPlus;"; | ||
string source = "using GqlPlusTests;"; | ||
|
||
GeneratorDriver driver = new BuildDataGenerator("GqlPlusTests") | ||
.Generate(source, []); | ||
|
||
// Pass the source code to our helper and snapshot test the output | ||
return TestGeneratorsHelper.Verify(source); | ||
return Verifier.Verify(driver); | ||
} | ||
|
||
[Fact] | ||
public Task IgnoresIncorrectAdditionalFiles() | ||
{ | ||
string source = "using GqlPlus;"; | ||
string source = "using GqlPlusTests;"; | ||
|
||
// Pass the source code to our helper and snapshot test the output | ||
return TestGeneratorsHelper.Verify(source, "Sample/Files/File3.gql+", "Sample/Files/file2.graphql+", "Sample/Files/file1.txt", "Sample/git-details.txt"); | ||
GeneratorDriver driver = new BuildDataGenerator("GqlPlusTests") | ||
.Generate(source, s_additionalFilesWithIncorrectOne.AdditionalPaths()); | ||
|
||
return Verifier.Verify(driver); | ||
} | ||
|
||
[Fact] | ||
public Task SubDirectoryAdditionalFiles() | ||
{ | ||
string source = "using GqlPlus;"; | ||
string source = "using GqlPlusTests;"; | ||
|
||
GeneratorDriver driver = new BuildDataGenerator("GqlPlusTests") | ||
.Generate(source, s_additionalSubdirectoryFiles.AdditionalPaths()); | ||
|
||
// Pass the source code to our helper and snapshot test the output | ||
return TestGeneratorsHelper.Verify(source, "Sample/Files/File3.gql", "Sample/More/file2.graphql+", "Sample/Files/Deeper/file1.gql+", "Sample/git-details.txt"); | ||
return Verifier.Verify(driver); | ||
} | ||
} |
7 changes: 1 addition & 6 deletions
7
test/GqlPlus.TestGeneratorsTests/GqlPlus.TestGeneratorsTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters