Skip to content

Commit 5c35178

Browse files
committed
AST printer
1 parent 6b5a980 commit 5c35178

File tree

5 files changed

+558
-1
lines changed

5 files changed

+558
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace GraphQLParser.Tests
2+
{
3+
using KellermanSoftware.CompareNetObjects;
4+
using System;
5+
6+
public static class AssertExtensions
7+
{
8+
public static void DeepEqual<T>(T obj1, T obj2, params Type[] typesToIgnore)
9+
{
10+
var compareLogic = new CompareLogic();
11+
12+
if (typesToIgnore != null)
13+
{
14+
foreach (var type in typesToIgnore)
15+
{
16+
compareLogic.Config.TypesToIgnore.Add(type);
17+
}
18+
}
19+
20+
var result = compareLogic.Compare(obj1, obj2);
21+
22+
if (!result.AreEqual)
23+
throw new Exception(
24+
"Objects are not the same: " +
25+
Environment.NewLine + Environment.NewLine +
26+
result.DifferencesString);
27+
}
28+
}
29+
}

src/GraphQLParser.Tests/GraphQLParser.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26+
<PackageReference Include="CompareNETObjects" Version="4.55.0" />
2627
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
2728
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
2829
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />

src/GraphQLParser.Tests/ParserTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private static ASTNode GetSingleSelection(GraphQLDocument document)
152152
return GetSingleOperationDefinition(document).SelectionSet.Selections.Single();
153153
}
154154

155-
private static string LoadKitchenSink()
155+
public static string LoadKitchenSink()
156156
{
157157
return @"# Copyright (c) 2015, Facebook, Inc.
158158
# All rights reserved.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace GraphQLParser.Tests
2+
{
3+
using GraphQLParser.AST;
4+
using Xunit;
5+
6+
public class PrinterTests
7+
{
8+
private Printer printer;
9+
10+
public PrinterTests()
11+
{
12+
this.printer = new Printer();
13+
}
14+
15+
[Fact]
16+
public void Print_KitchenSink_DoesNotModifyAST()
17+
{
18+
var ast = this.Parse(ParserTests.LoadKitchenSink());
19+
var printed = this.printer.Print(ast);
20+
var ast2 = this.Parse(printed);
21+
22+
AssertExtensions.DeepEqual(ast, ast2, typeof(GraphQLLocation));
23+
}
24+
25+
private GraphQLDocument Parse(string body)
26+
{
27+
var parser = new Parser(new Lexer());
28+
29+
return parser.Parse(new Source(body));
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)