Skip to content

Commit

Permalink
Merge pull request #94 from NeonGraal/union-tests
Browse files Browse the repository at this point in the history
Improve Union tests from samples
  • Loading branch information
NeonGraal authored Feb 8, 2025
2 parents 95a8c92 + d979dd4 commit a486da2
Show file tree
Hide file tree
Showing 55 changed files with 549 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/GqlPlus.Verifier/Verifying/Schema/AstParentVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private void CheckTypedParentType(ParentUsage<TAst> input, TContext context, boo
onParent?.Invoke(parentType);
}
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ protected override UsageContext MakeContext(IGqlpUnion usage, IGqlpType[] aliase

protected override void UsageValue(IGqlpUnion usage, UsageContext context)
{
base.UsageValue(usage, context);

foreach (IGqlpUnionItem member in usage.Items) {
context.AddError(usage, "Union", $"'{member.Name}' not defined", CheckMember(usage.Name, member, context, CheckTypeLabel));
}
Expand All @@ -31,9 +33,7 @@ protected override void UsageValue(IGqlpUnion usage, UsageContext context)
}

void CheckTypeLabel(string name, IGqlpType type)
{
context.AddError(usage, "union", $"Type kind mismatch for {name}. Found {type?.Label}", type is not IGqlpSimple and not IGqlpTypeSpecial);
}
=> context.AddError(usage, "union", $"Type kind mismatch for {name}. Found {type?.Label}", type is not IGqlpSimple and not IGqlpTypeSpecial);
}

private static bool CheckMember(string name, IGqlpUnionItem member, UsageContext context, Action<string, IGqlpType>? checkType = null)
Expand Down
2 changes: 1 addition & 1 deletion test/GqlPlus.ComponentTestBase/BuildData.t4
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void BuildData(string directory, string prefix) {
var gitFile = samplesDir.GetFiles("git-details.txt")[0];
string gitDetails;
using (var gitText = gitFile.OpenText()) {
gitDetails = gitText.ReadToEnd();
gitDetails = gitText.ReadToEnd().Trim();
}#>
// Generated from <#= relative #>
// Collected from <#= gitDetails #>
Expand Down
3 changes: 1 addition & 2 deletions test/GqlPlus.ComponentTestBase/OperationData.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated from .\test\GqlPlus.ComponentTestBase\Samples\Operation
// Collected from 5e5c83d (HEAD -> main, origin/main, origin/HEAD) 2024-09-24 Merge pull request #3 from graphql-plus/samples

// Collected from 247728f (HEAD -> union-tests, origin/union-tests) 2025-02-08 Improve Union parent samples

namespace GqlPlus;

Expand Down
2 changes: 0 additions & 2 deletions test/GqlPlus.ComponentTestBase/SampleChecks.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using GqlPlus.Abstractions;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

namespace GqlPlus;

public class SampleChecks
Expand Down
3 changes: 1 addition & 2 deletions test/GqlPlus.ComponentTestBase/SampleData.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated from .\test\GqlPlus.ComponentTestBase\Samples
// Collected from 5e5c83d (HEAD -> main, origin/main, origin/HEAD) 2024-09-24 Merge pull request #3 from graphql-plus/samples

// Collected from 247728f (HEAD -> union-tests, origin/union-tests) 2025-02-08 Improve Union parent samples

namespace GqlPlus;

Expand Down
2 changes: 0 additions & 2 deletions test/GqlPlus.ComponentTestBase/SampleSchemaChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using GqlPlus.Result;
using GqlPlus.Token;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

namespace GqlPlus;

public class SampleSchemaChecks(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
object Test { field1[alias]: Test }
object Test { field2[alias]: Test[] }
object Test { field1 [alias]: Test }
object Test { field2 [alias]: Test[] }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
object Test { :Recurse field1[alias]: Test }
object Test { :Recurse field1 [alias]: Test }
object Recurse { :More }
object More { :Parent }
object Parent { field2[alias]: Parent }
object Parent { field2 [alias]: Parent }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
object Test { :Recurse field1[alias]: Test }
object Test { :Recurse field1 [alias]: Test }
object Recurse { :Parent }
object Parent { field2[alias]: Parent }
object Parent { field2 [alias]: Parent }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
object Test { :Parent }
object Test { field1[alias]: Test }
object Parent { field2[alias]: Parent }
object Test { field1 [alias]: Test }
object Parent { field2 [alias]: Parent }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union Test [a] { Bad }
union Dup [a] { Test }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Multiple Unions with alias 'a' found. Names 'Test' 'Dup',
Multiple Types with alias 'a' found. Names 'Test' 'Dup'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
union Test { :Parent Number }
union Test { Number }
union Parent { String }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Multiple Unions with name 'Test' can't be merged.,
Group of Union for 'Test' is not singular Parent['', 'Parent'],
Multiple Types with name 'Test' can't be merged.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
union Test { :Parent }
union Test { :Parent String }
union Parent { More }
union More { :Bad }
union More { :Bad String }
union Bad { Test }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
union Test { :Parent }
union Test { :Parent String }
union Parent { Bad }
union Bad { Test }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
union Test { :Parent Number }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid Union Parent. 'Parent' not defined.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union Test { :Parent Number }
output Parent { }
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Invalid Union Parent. 'Parent' invalid type. Found 'Output'.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
union Test { :Parent }
union Test { :Parent String }
union Parent { Test }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
union Test { Bad }
union Bad { :Parent }
union Bad { :Parent String }
union Parent { Test }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union UnDiff [UnA1] { Boolean }
union UnDiff [UnA2] { Number }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
union UnSameParent { :UnParent Boolean }
union UnSameParent { :UnParent Boolean }
union UnParent { String }
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
union UnionPrnt { :PrntUnion Number }
union PrntUnion { Number }
2 changes: 1 addition & 1 deletion test/GqlPlus.ComponentTestBase/Samples/git-details.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5e5c83d (HEAD -> main, origin/main, origin/HEAD) 2024-09-24 Merge pull request #3 from graphql-plus/samples
247728f (HEAD -> union-tests, origin/union-tests) 2025-02-08 Improve Union parent samples
10 changes: 8 additions & 2 deletions test/GqlPlus.ComponentTestBase/SchemaData.gen.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Generated from .\test\GqlPlus.ComponentTestBase\Samples\Schema
// Collected from 5e5c83d (HEAD -> main, origin/main, origin/HEAD) 2024-09-24 Merge pull request #3 from graphql-plus/samples

// Collected from 247728f (HEAD -> union-tests, origin/union-tests) 2025-02-08 Improve Union parent samples

namespace GqlPlus;

Expand Down Expand Up @@ -141,11 +140,15 @@ public SchemaInvalidSimpleData()
Add("enum-parent-diff");
Add("enum-parent-undef");
Add("enum-parent-wrong");
Add("union-dup-alias");
Add("union-more");
Add("union-more-parent");
Add("union-parent");
Add("union-parent-diff");
Add("union-parent-more");
Add("union-parent-recurse");
Add("union-parent-undef");
Add("union-parent-wrong");
Add("union-recurse");
Add("union-recurse-parent");
Add("union-self");
Expand Down Expand Up @@ -220,8 +223,10 @@ public SchemaValidMergesData()
Add("output-field-enum-alias");
Add("output-field-enum-value");
Add("output-field-param");
Add("union-alias");
Add("union-diff");
Add("union-same");
Add("union-same-parent");
}
}

Expand Down Expand Up @@ -301,5 +306,6 @@ public SchemaValidSimpleData()
Add("enum-parent-alias");
Add("enum-parent-dup");
Add("union-parent");
Add("union-parent-dup");
}
}
5 changes: 1 addition & 4 deletions test/GqlPlus.ComponentTestBase/SchemaDataBase.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using GqlPlus.Abstractions.Schema;
using GqlPlus.Merging;
using GqlPlus.Parsing;
using GqlPlus.Result;
using GqlPlus.Token;

using Grpc.Core;

namespace GqlPlus;

public class SchemaDataBase(
Expand All @@ -30,7 +27,7 @@ protected static IEnumerable<string> ReplaceKeys(IDictionary<string, string> inp
: [k])
.Order();

protected async static Task<IEnumerable<string>> ReplaceSchemaKeys(string group)
protected static async Task<IEnumerable<string>> ReplaceSchemaKeys(string group)
{
IEnumerable<Task<(string input, string file)>> tasks = SchemaValidData
.Files[group]
Expand Down
1 change: 0 additions & 1 deletion test/GqlPlus.Modeller.ComponentTests/BuiltInTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void ModelAllBasicTypes()
Declarations = BuiltIn.Basic
};


ITypesContext context = renderer.Context();
RenderStructure result = renderer.RenderAst(schema, context);

Expand Down
4 changes: 1 addition & 3 deletions test/GqlPlus.Modeller.ComponentTests/SampleModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using FluentAssertions.Execution;

using GqlPlus;
using GqlPlus;
using GqlPlus.Abstractions.Schema;
using GqlPlus.Convert;
using GqlPlus.Parsing;
Expand Down
1 change: 0 additions & 1 deletion test/GqlPlus.Modeller.ComponentTests/SchemaJsonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using GqlPlus.Convert;
using GqlPlus.Merging;
using GqlPlus.Parsing;
using GqlPlus.Resolving;
using GqlPlus.Result;

namespace GqlPlus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10572,6 +10572,7 @@
},
"UnDiff": {
"$tag": "_TypeUnion",
"aliases": ["UnA1", "UnA2"],
"allItems": [
{
"$tag": "_UnionMember",
Expand Down Expand Up @@ -10609,12 +10610,21 @@
"$tag": "_UnionMember",
"name": "String",
"union": "UnionPrnt"
},
{
"$tag": "_UnionMember",
"name": "Number",
"union": "UnionPrnt"
}
],
"items": [
{
"$tag": "_Aliased",
"value": "String"
},
{
"$tag": "_Aliased",
"value": "Number"
}
],
"name": "UnionPrnt",
Expand All @@ -10625,6 +10635,24 @@
},
"typeKind": "Union"
},
"UnParent": {
"$tag": "_TypeUnion",
"allItems": [
{
"$tag": "_UnionMember",
"name": "String",
"union": "UnParent"
}
],
"items": [
{
"$tag": "_Aliased",
"value": "String"
}
],
"name": "UnParent",
"typeKind": "Union"
},
"UnSame": {
"$tag": "_TypeUnion",
"allItems": [
Expand All @@ -10642,6 +10670,34 @@
],
"name": "UnSame",
"typeKind": "Union"
},
"UnSameParent": {
"$tag": "_TypeUnion",
"allItems": [
{
"$tag": "_UnionMember",
"name": "String",
"union": "UnParent"
},
{
"$tag": "_UnionMember",
"name": "Boolean",
"union": "UnSameParent"
}
],
"items": [
{
"$tag": "_Aliased",
"value": "Boolean"
}
],
"name": "UnSameParent",
"parent": {
"$tag": "_TypeRef(_SimpleKind)",
"name": "UnParent",
"typeKind": "Union"
},
"typeKind": "Union"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@
},
"UnDiff": {
"$tag": "_TypeUnion",
"aliases": ["UnA1", "UnA2"],
"allItems": [
{
"$tag": "_UnionMember",
Expand All @@ -1131,6 +1132,24 @@
"name": "UnDiff",
"typeKind": "Union"
},
"UnParent": {
"$tag": "_TypeUnion",
"allItems": [
{
"$tag": "_UnionMember",
"name": "String",
"union": "UnParent"
}
],
"items": [
{
"$tag": "_Aliased",
"value": "String"
}
],
"name": "UnParent",
"typeKind": "Union"
},
"UnSame": {
"$tag": "_TypeUnion",
"allItems": [
Expand All @@ -1148,6 +1167,34 @@
],
"name": "UnSame",
"typeKind": "Union"
},
"UnSameParent": {
"$tag": "_TypeUnion",
"allItems": [
{
"$tag": "_UnionMember",
"name": "String",
"union": "UnParent"
},
{
"$tag": "_UnionMember",
"name": "Boolean",
"union": "UnSameParent"
}
],
"items": [
{
"$tag": "_Aliased",
"value": "Boolean"
}
],
"name": "UnSameParent",
"parent": {
"$tag": "_TypeRef(_SimpleKind)",
"name": "UnParent",
"typeKind": "Union"
},
"typeKind": "Union"
}
}
}
Loading

0 comments on commit a486da2

Please sign in to comment.