Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmetic changes #380

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Preview versions of this package are available on [GitHub Packages](https://gith
Generates token based on input text. Lexer takes advantage of `ReadOnlyMemory<char>` and in most cases
does not allocate memory on the managed heap at all.

### Usage
Usage:

```csharp
var token = Lexer.Lex("\"str\"");
Expand All @@ -36,7 +36,7 @@ Lex method always returns the first token it finds. In this case case the result
Parses provided GraphQL expression into AST (abstract syntax tree). Parser also takes advantage of
`ReadOnlyMemory<char>` but still allocates memory for AST.

### Usage
Usage:

```csharp
var ast1 = Parser.Parse(@"
Expand Down Expand Up @@ -84,7 +84,8 @@ new SDLPrinter().Print(document, sb);

// print to a string with some options
var sdlPrinter = new SDLPrinter(
new SDLPrinterOptions {
new SDLPrinterOptions
{
PrintComments = true,
EachDirectiveLocationOnNewLine = true,
EachUnionMemberOnNewLine = true,
Expand All @@ -111,8 +112,8 @@ query {
### SDLSorter

An AST document can be sorted with the `SDLSorter` using a predefined
sort order. You can specify the string comparison; by default it uses
a culture-invariant case-insensitive comparison. Any futher customization
sort order. You can specify the string comparison; by default it uses
a culture-invariant case-insensitive comparison. Any futher customization
is possible by deriving from `SDLSorterOptions` and overriding the `Compare`
methods.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task Printer_Should_Print_Pretty_If_Directives_Skipped(
string expected)
{
var printer = new MyPrinter();
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer);
Expand Down
34 changes: 17 additions & 17 deletions src/GraphQLParser.Tests/Visitors/SDLPrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public async Task Print_Matches_PrintAsync_String()
{
var query = "KitchenSink".ReadGraphQLFile().Parse();
var writer = new SDLPrinter();
var sw = new StringWriter();
using var sw = new StringWriter();
await writer.PrintAsync(query, sw);
sw.Flush();
var txt = sw.ToString();
Expand Down Expand Up @@ -580,7 +580,7 @@ public async Task SDLPrinter_Should_Print_Document(
EachDirectiveLocationOnNewLine = eachDirectiveLocationOnNewLine,
EachUnionMemberOnNewLine = eachUnionMemberOnNewLine
});
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer);
Expand Down Expand Up @@ -636,7 +636,7 @@ public async Task SDLPrinter_Should_Print_BlockStrings(int number, string input,
? "\"\"\"" + expected + "\"\"\""
: "\"" + expected + "\"";

var writer = new StringWriter();
using var writer = new StringWriter();

var document = (input + " scalar a").Parse();

Expand Down Expand Up @@ -667,7 +667,7 @@ public async Task SDLPrinter_Should_Print_EscapedStrings(string stringValue)
string expected = @$"{{
a(p: {stringValue})
}}";
var writer = new StringWriter();
using var writer = new StringWriter();

var document = query.Parse();

Expand All @@ -683,16 +683,16 @@ public async Task SDLPrinter_Should_Print_EscapedStrings(string stringValue)
public async Task SelectionSet_Without_Parent_Should_Be_Printed_On_New_Line()
{
var selectionSet = new GraphQLSelectionSetWithComment { Selections = new List<ASTNode>() };
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter(new SDLPrinterOptions { PrintComments = true });
await printer.PrintAsync(selectionSet, writer);
writer.ToString().ShouldBe(@"{
}
");
selectionSet.Comments = new List<GraphQLComment> { new GraphQLComment("comment") };
writer = new StringWriter();
await printer.PrintAsync(selectionSet, writer);
writer.ToString().ShouldBe(@"#comment
using var writer2 = new StringWriter();
await printer.PrintAsync(selectionSet, writer2);
writer2.ToString().ShouldBe(@"#comment
{
}
");
Expand All @@ -705,15 +705,15 @@ public async Task SelectionSet_Under_Operation_With_Null_Name_Should_Be_Printed_
{
SelectionSet = new GraphQLSelectionSetWithComment { Selections = new List<ASTNode>() }
};
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter(new SDLPrinterOptions { PrintComments = true });
await printer.PrintAsync(def, writer);
writer.ToString().ShouldBe(@"{
}");
def.SelectionSet.Comments = new List<GraphQLComment> { new GraphQLComment("comment") };
writer = new StringWriter();
await printer.PrintAsync(def, writer);
writer.ToString().ShouldBe(@"#comment
using var writer2 = new StringWriter();
await printer.PrintAsync(def, writer2);
writer2.ToString().ShouldBe(@"#comment
{
}");
}
Expand All @@ -734,7 +734,7 @@ public async Task SelectionSet_Under_Operation_With_Null_Name_Should_Be_Printed_
public async Task Description_Without_Parent_Should_Be_Printed(string text, string expected)
{
var description = new GraphQLDescription(text);
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(description, writer);
writer.ToString().ShouldBe(expected);
Expand All @@ -761,7 +761,7 @@ Line 4
public async Task Description_With_Escaped_Unicode_Should_Be_Printed(string text, string expected)
{
var description = new GraphQLDescription(text);
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(description, writer);
writer.ToString().ShouldBe(expected);
Expand All @@ -777,7 +777,7 @@ public async Task InputValueDefinition_Without_Parent_Should_Be_Printed()
DefaultValue = new GraphQLStringValue("abc")
};

var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(def, writer);
writer.ToString().ShouldBe("field: String = \"abc\"");
Expand All @@ -787,7 +787,7 @@ public async Task InputValueDefinition_Without_Parent_Should_Be_Printed()
public async Task Directive_Without_Parent_Should_Be_Printed()
{
var directive = new GraphQLDirective { Name = new GraphQLName("upper") };
var writer = new StringWriter();
using var writer = new StringWriter();
var printer = new SDLPrinter();
await printer.PrintAsync(directive, writer);
writer.ToString().ShouldBe("@upper");
Expand Down Expand Up @@ -818,7 +818,7 @@ public void UTF8_MemoryStream_Runs_Synchronously()
[InlineData("directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT")]
public async Task SDLPrinter_Should_Throw_On_Unknown_Values(string text)
{
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await new DoBadThingsVisitor().VisitAsync(document, new Context());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public async Task Printer_Should_Print_Pretty_If_Definitions_Skipped(
string expected)
{
var printer = new MyPrinter();
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();

await printer.PrintAsync(document, writer);
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQLParser.Tests/Visitors/StructurePrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ Name [dir]
")]
public async Task StructurePrinter_Should_Print_Tree(string text, string expected)
{
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();
await _structPrinter1.PrintAsync(document, writer);
var actual = writer.ToString();
Expand All @@ -302,7 +302,7 @@ public async Task StructurePrinter_Should_Print_Tree(string text, string expecte
")]
public async Task StructurePrinter_Should_Print_Tree_Without_Names(string text, string expected)
{
var writer = new StringWriter();
using var writer = new StringWriter();
var document = text.Parse();
await _structPrinter2.PrintAsync(document, writer);
var actual = writer.ToString();
Expand Down Expand Up @@ -547,7 +547,7 @@ public async Task StructurePrinter_Should_Print_Tree_With_Locations(string text,
if (option == IgnoreOptions.Comments && !ignoreComments)
continue;

var writer = new StringWriter();
using var writer = new StringWriter();

var document = text.Parse(new ParserOptions { Ignore = option });
await _structPrinter3.PrintAsync(document, writer);
Expand Down
Loading