Skip to content

Commit

Permalink
Added support for no request nodes and just comments present (#3469)
Browse files Browse the repository at this point in the history
* Added support for no request nodesand just comments

* Addition of theory test for comments
  • Loading branch information
bleaphar committed Feb 27, 2024
1 parent 3ba37fe commit 8e99f3e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public HttpSyntaxTree Parse()
}
}

foreach (var comment in commentsToPrepend)
{
_syntaxTree.RootNode.Add(comment);
}

return _syntaxTree;
}

Expand Down Expand Up @@ -294,7 +299,7 @@ private void ConsumeCurrentTokenInto(HttpSyntaxNode node)

private HttpRequestNode? ParseRequest()
{
if (IsComment())
if (!MoreTokens() || IsComment())
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public void Add(HttpRequestNode requestNode)
AddInternal(requestNode);
}

public void Add(HttpCommentNode commentNode)
{
AddInternal(commentNode);
}

public void Add(HttpVariableDeclarationAndAssignmentNode variableNode)
{
AddInternal(variableNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Management.Automation.Internal;
using FluentAssertions;
using Microsoft.DotNet.Interactive.Http.Parsing;
using Microsoft.DotNet.Interactive.Http.Tests.Utility;
Expand Down Expand Up @@ -64,5 +65,43 @@ public void Comment_node_can_immediately_follow_headers()
.Should().ContainSingle<HttpCommentNode>()
.Which.Text.Should().Be("# This is a comment");
}

[Theory]
[InlineData("""
# This is a comment
""")]
[InlineData("""
# This is a comment
# This is the second line of the comment
""")]
[InlineData("""
# This is a comment
# This is the second line of the comment
# This is the third line of the comment
""")]
[InlineData("""
GET https://example.com
# This is a comment
# This is the second line of the comment
""")]
[InlineData("""
# This is a comment
# This is the second line of the comment
""")]
[InlineData("""
# This is a comment
# This is the second line of the comment
# This is the third line of the comments
""")]
public void Comment_node_without_request_node_does_not_produce_diagnostics(string code)
{
var result = Parse(code);

result.GetDiagnostics().Should().BeEmpty();

}
}
}

0 comments on commit 8e99f3e

Please sign in to comment.