Skip to content

Commit

Permalink
Fix bug in SelectionSetNode.AddSelections() and update test snap (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avilad authored and michaelstaib committed Oct 17, 2019
1 parent 3c1704c commit d395542
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/Core/Language.Tests/AST/SelectionSetNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,55 @@ public void AddSelections()
selectionSet.MatchSnapshot();
}

[Fact]
public void AddSelections_Two()
{
// arrange
Location location = AstTestHelper.CreateDummyLocation();
var selections = new List<ISelectionNode>
{
new FieldNode
(
null,
new NameNode("bar"),
null,
Array.Empty<DirectiveNode>(),
Array.Empty<ArgumentNode>(),
null
)
};

var selectionSet = new SelectionSetNode
(
location,
selections
);

// act
selectionSet = selectionSet.AddSelections(
new FieldNode
(
null,
new NameNode("baz"),
null,
Array.Empty<DirectiveNode>(),
Array.Empty<ArgumentNode>(),
null
),
new FieldNode
(
null,
new NameNode("qux"),
null,
Array.Empty<DirectiveNode>(),
Array.Empty<ArgumentNode>(),
null
));

// assert
selectionSet.MatchSnapshot();
}

[Fact]
public void RemoveSelection()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"Name": {
"Kind": "Name",
"Location": null,
"Value": "baz"
"Value": "bar"
},
"Directives": []
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"Kind": "SelectionSet",
"Location": {
"Start": 0,
"End": 0,
"Line": 0,
"Column": 0
},
"Selections": [
{
"Kind": "Field",
"Alias": null,
"Arguments": [],
"SelectionSet": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "bar"
},
"Directives": []
},
{
"Kind": "Field",
"Alias": null,
"Arguments": [],
"SelectionSet": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "baz"
},
"Directives": []
},
{
"Kind": "Field",
"Alias": null,
"Arguments": [],
"SelectionSet": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "qux"
},
"Directives": []
}
]
}
2 changes: 1 addition & 1 deletion src/Core/Language/AST/SelectionSetNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public SelectionSetNode AddSelections(
throw new ArgumentNullException(nameof(selection));
}

var selections = new List<ISelectionNode>(selection);
var selections = new List<ISelectionNode>(Selections);
selections.AddRange(selection);

return new SelectionSetNode(
Expand Down

0 comments on commit d395542

Please sign in to comment.