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

Support for an embedded expression in variable value node #3375

Merged
merged 10 commits into from
Dec 7, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ public HttpSyntaxTree Parse()
node = new HttpVariableValueNode(_sourceText, _syntaxTree);

ParseLeadingWhitespaceAndComments(node);
}
else if (IsAtStartOfEmbeddedExpression())
shyamnamboodiripad marked this conversation as resolved.
Show resolved Hide resolved
{
node = new HttpVariableValueNode(_sourceText, _syntaxTree);
node.Add(ParseEmbeddedExpression());
if(CurrentToken is { Kind: HttpTokenKind.NewLine })
shyamnamboodiripad marked this conversation as resolved.
Show resolved Hide resolved
{
break;
}
}
else
{
Expand Down
26 changes: 26 additions & 0 deletions src/Microsoft.DotNet.Interactive.Http.Tests/ParserTests.Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ public void request_node_containing_only_url_and_no_variable_expressions_returns
bindingResult.Value.Method.Should().Be(HttpMethod.Get);
}

[Fact]
public void request_node_with_multiple_variables_declared_prior_parsed_correctly()
{
var result = Parse(
"""
@searchTerm=some-search-term
@hostname=httpbin.org
# variable using another variable
@host=https://{{hostname}}
# variable using "dynamic variables"
@createdAt = {{$datetime iso8601}}
@anyhost={{host}}/anything
shyamnamboodiripad marked this conversation as resolved.
Show resolved Hide resolved
@fakeuser=fakeuser
@fakepwd=fakepwd

https://httpbin.org/get
""");

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

var variableNodes = result.SyntaxTree.RootNode.ChildNodes.OfType<HttpVariableDeclarationAndAssignmentNode>();
variableNodes.Count().Should().Be(7);
bleaphar marked this conversation as resolved.
Show resolved Hide resolved

requestNode.UrlNode.Text.Should().Be("https://httpbin.org/get");
bleaphar marked this conversation as resolved.
Show resolved Hide resolved
}

[Fact]
public void request_node_containing_method_and_url_and_no_variable_expressions_returns_HttpRequestMessage_with_specified_method()
{
Expand Down