-
Notifications
You must be signed in to change notification settings - Fork 415
Support for escaping curly braces in embedded expression #3962
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
639e4f9
3bce799
31d8469
0c44d92
4fdf463
ef14f09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,7 @@ public static IEnumerable<object[]> GenerateValidRequests() | |
| var generationNumber = 0; | ||
|
|
||
| foreach(var namedRequest in ValidNamedRequests()) | ||
| foreach (var variables in ValidVariableDeclarations()) | ||
| foreach (var method in ValidMethods()) | ||
| foreach (var url in ValidUrls()) | ||
| foreach (var version in ValidVersions()) | ||
|
|
@@ -115,7 +116,7 @@ public static IEnumerable<object[]> GenerateValidRequests() | |
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, method, url, version, headerSection, bodySection), | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection), | ||
| generationNumber | ||
| }; | ||
| } | ||
|
|
@@ -125,6 +126,7 @@ public static IEnumerable<object[]> GenerateValidRequestsWithExtraTrivia() | |
| { | ||
| var generationNumber = 0; | ||
|
|
||
| foreach(var variables in ValidVariableDeclarations()) | ||
| foreach (var namedRequest in ValidNamedRequests()) | ||
| foreach (var method in ValidMethods()) | ||
| foreach (var url in ValidUrls()) | ||
|
|
@@ -135,7 +137,7 @@ public static IEnumerable<object[]> GenerateValidRequestsWithExtraTrivia() | |
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, method, url, version, headerSection, bodySection) | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection) | ||
| { | ||
| Randomizer = new Random(1) | ||
| }, | ||
|
|
@@ -149,6 +151,7 @@ public static IEnumerable<object[]> GenerateInvalidRequests() | |
| var generationNumber = 0; | ||
|
|
||
| foreach (var namedRequest in ValidNamedRequests()) | ||
| foreach (var variables in ValidVariableDeclarations()) | ||
| foreach (var method in InvalidMethods()) | ||
| foreach (var url in ValidUrls()) | ||
| foreach (var version in ValidVersions()) | ||
|
|
@@ -158,12 +161,13 @@ public static IEnumerable<object[]> GenerateInvalidRequests() | |
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, method, url, version, headerSection, bodySection), | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection), | ||
| generationNumber | ||
| }; | ||
| } | ||
|
|
||
| foreach (var namedRequest in ValidNamedRequests()) | ||
| foreach (var variables in ValidVariableDeclarations()) | ||
| foreach (var method in ValidMethods()) | ||
| foreach (var url in InvalidUrls()) | ||
| foreach (var version in ValidVersions()) | ||
|
|
@@ -173,12 +177,13 @@ public static IEnumerable<object[]> GenerateInvalidRequests() | |
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, method, url, version, headerSection, bodySection), | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection), | ||
| generationNumber | ||
| }; | ||
| } | ||
|
|
||
| foreach(var namedRequest in ValidNamedRequests()) | ||
| foreach (var variables in ValidVariableDeclarations()) | ||
| foreach (var method in ValidMethods()) | ||
| foreach (var url in ValidUrls()) | ||
| foreach (var version in InvalidVersions()) | ||
|
|
@@ -188,12 +193,13 @@ public static IEnumerable<object[]> GenerateInvalidRequests() | |
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, method, url, version, headerSection, bodySection), | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection), | ||
| generationNumber | ||
| }; | ||
| } | ||
|
|
||
| foreach(var namedRequest in ValidNamedRequests()) | ||
| foreach (var variables in ValidVariableDeclarations()) | ||
| foreach (var method in ValidMethods()) | ||
| foreach (var url in ValidUrls()) | ||
| foreach (var version in ValidVersions()) | ||
|
|
@@ -203,12 +209,14 @@ public static IEnumerable<object[]> GenerateInvalidRequests() | |
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, method, url, version, headerSection, bodySection), | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection), | ||
| generationNumber | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| foreach (var namedRequest in InvalidNamedRequests()) | ||
| foreach (var variables in ValidVariableDeclarations()) | ||
| foreach (var method in ValidMethods()) | ||
| foreach (var url in ValidUrls()) | ||
| foreach (var version in ValidVersions()) | ||
|
|
@@ -218,11 +226,28 @@ public static IEnumerable<object[]> GenerateInvalidRequests() | |
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, method, url, version, headerSection, bodySection), | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection), | ||
| generationNumber | ||
| }; | ||
| } | ||
|
|
||
| foreach (var namedRequest in ValidNamedRequests()) | ||
| foreach (var variables in InvalidVariableDeclarations()) | ||
| foreach (var method in ValidMethods()) | ||
| foreach (var url in ValidUrls()) | ||
| foreach (var version in ValidVersions()) | ||
| foreach (var headerSection in ValidHeaderSections()) | ||
| foreach (var bodySection in ValidBodySections()) | ||
| { | ||
| ++generationNumber; | ||
| yield return new object[] | ||
| { | ||
| new HttpRequestNodeSyntaxSpec(namedRequest, variables, method, url, version, headerSection, bodySection), | ||
| generationNumber | ||
| }; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static IEnumerable<HttpMethodNodeSyntaxSpec> ValidMethods() | ||
| { | ||
|
|
@@ -355,5 +380,64 @@ with XML.</description> | |
| .Should().BeEquivalentTo("numberValue", "stringValue"); | ||
| }); | ||
| } | ||
|
|
||
| private static IEnumerable<HttpVariableDeclarationAndAssignmentNodeSyntaxSpec> ValidVariableDeclarations() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might not be necessary to add so many cases. The goal of these tests is generally not to test every detail of the feature. The unit tests already cover that. They tend to be useful for catching issues with different combinations of syntax (e.g. does the parser move correctly from one node type to another) as well as incomplete syntax (e.g. does the parser handle it gracefully when the user is typing and the syntax is malformed in various normal ways.) |
||
| { | ||
| yield return null; | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@host=localhost"); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@host=https://example.com"); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@api_key=secret123"); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@base_url=https://{{host}}/api", node => | ||
| { | ||
| node.ValueNode.DescendantNodesAndTokens().OfType<HttpEmbeddedExpressionNode>() | ||
| .Should().ContainSingle() | ||
| .Which.ExpressionNode.Text.Should().Be("host"); | ||
| }); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@escaped=\\{\\{text\\}\\}", node => | ||
| { | ||
| node.ValueNode.Text.Should().Be("{{text}}"); | ||
| }); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@with_spaces=one two three"); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@quoted=\"hello world\""); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@single_quoted='hello world'"); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@user.name=john_doe"); | ||
|
|
||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@dynamic={{$guid}}", node => | ||
| { | ||
| node.ValueNode.DescendantNodesAndTokens().OfType<HttpEmbeddedExpressionNode>() | ||
| .Should().ContainSingle() | ||
| .Which.ExpressionNode.Text.Should().Be("$guid"); | ||
| }); | ||
| } | ||
|
|
||
| private static IEnumerable<HttpVariableDeclarationAndAssignmentNodeSyntaxSpec> InvalidVariableDeclarations() | ||
| { | ||
| // Missing variable name | ||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@=value"); | ||
|
|
||
| // Variable name starting with number | ||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@123invalid=value"); | ||
|
|
||
| // Invalid character in variable name (hyphen) | ||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@my-var=value"); | ||
|
|
||
| // Space in variable name | ||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@var name=value"); | ||
|
|
||
| // Missing equals sign | ||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@host value"); | ||
|
|
||
| // Special characters in variable name | ||
| yield return new HttpVariableDeclarationAndAssignmentNodeSyntaxSpec("@host!name=value"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to repeat this section?