Skip to content

Commit

Permalink
Addition of period into variable declaration (#3582)
Browse files Browse the repository at this point in the history
* Addition of period into variable declaration

* Update src/Microsoft.DotNet.Interactive.Http.Parsing/Parsing/HttpRequestParser.cs

Co-authored-by: Jon Sequeira <jonsequeira@gmail.com>

---------

Co-authored-by: Jon Sequeira <jonsequeira@gmail.com>
  • Loading branch information
bleaphar and jonsequitur authored Jun 24, 2024
1 parent 3e1c708 commit 9374b49
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private HttpVariableDeclarationNode ParseVariableDeclaration()

while (MoreTokens())
{
if (CurrentToken is { Text: "@" } or { Kind: HttpTokenKind.Word } or { Text: "_" })
if (CurrentToken is { Kind: HttpTokenKind.Word } or { Text: "@" or "_" or "." })
{
ConsumeCurrentTokenInto(node);
}
Expand Down
31 changes: 31 additions & 0 deletions src/Microsoft.DotNet.Interactive.Http.Tests/ParserTests.Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,37 @@ public void binding_for_variable_using_another_variable_is_correct()
bindingResult.Value.RequestUri.ToString().Should().Be("https://httpbin.org/anything");
}

[Fact]
public void binding_for_variable_with_period_is_correct()
{
var result = Parse(
"""
@host.name = httpbin.org
@host.full = https://{{host.name}}
POST {{host.full}}/anything HTTP/1.1
content-type: application/json
{
"name": "sample1",
}
"""
);

var requestNode = result.SyntaxTree.RootNode.ChildNodes
.Should().ContainSingle<HttpRequestNode>().Which;

var bindingResult = requestNode.TryGetHttpRequestMessage(node =>
{
return node.CreateBindingFailure(CreateDiagnosticInfo(""));
});

bindingResult.IsSuccessful.Should().BeTrue();
bindingResult.Value.RequestUri.ToString().Should().Be("https://httpbin.org/anything");
}

[Fact]
public void binding_for_variable_in_header_is_correct()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ public void underscores_in_embedded_expressions_are_supported()

}

[Fact]
public void periods_in_embedded_expressions_are_supported()
{
var result = Parse(
"""
@host.name=httpbin.org
@host=https://{{host.name}}
"""
);

var variables = result.SyntaxTree.RootNode.GetDeclaredVariables();
variables.Should().Contain(n => n.Key == "host.name").Which.Value.Should().BeOfType<DeclaredVariable>().Which.Value.Should().Be("httpbin.org");
variables.Should().Contain(n => n.Key == "host").Which.Value.Should().BeOfType<DeclaredVariable>().Which.Value.Should().Be("https://httpbin.org");

}

[Fact]
public void spaces_after_variable_do_not_produce_diagnostics()
{
Expand Down

0 comments on commit 9374b49

Please sign in to comment.