Skip to content

Commit

Permalink
fix tests, and add cases for all ASCII chars that require encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspimentel committed Nov 13, 2024
1 parent 3b01d1a commit 3286c90
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,22 @@ static W3CBaggagePropagatorTests()
};

[Theory]
[InlineData(null, new char[0], "")] // null
[InlineData("", new char[0], "")] // empty string
[InlineData("abcd", new char[0], "abcd")] // no chars to encode
[InlineData("abcd", new[] { 'x' }, "abcd")] // encode a char that is not in the string
[InlineData("abcd", new[] { 'b', 'd' }, "a%62c%64")] // encode chars that are in the string
[InlineData("José 🐶\t", new char[0], "Jos%C3%A9%20%F0%9F%90%B6%09%E6%88%91")] // always encode whitespace and unicode chars
public void EncodeStringAndAppend(string value, char[] charsToEncode, string expected)
// keys
[InlineData(null, true, "")] // null
[InlineData("", true, "")] // empty string
[InlineData("abcd", true, "abcd")] // no chars to encode
[InlineData("José 🐶\t", true, "Jos%C3%A9%20%F0%9F%90%B6%09%E6%88%91")] // always encode whitespace and Unicode chars
[InlineData("\",;\\()/:<=>?@[]{}", true, "%22%2C%3B%5C%28%29%2F%3A%3C%3D%3E%3F%40%5B%5D%7B%7D")] // other chars (NOTE: different from value)
// values
[InlineData(null, false, "")] // null
[InlineData("", false, "")] // empty string
[InlineData("abcd", false, "abcd")] // no chars to encode
[InlineData("José 🐶\t", false, "Jos%C3%A9%20%F0%9F%90%B6%09%E6%88%91")] // always encode whitespace and Unicode chars
[InlineData("\",;\\()/:<=>?@[]{}", false, "%22%2C%3B%5C()/:<=>?@[]{}")] // other chars (NOTE: different from key)
public void EncodeStringAndAppend(string value, bool isKey, string expected)
{
var sb = new StringBuilder();
W3CBaggagePropagator.EncodeStringAndAppend(sb, value, [..charsToEncode]);

W3CBaggagePropagator.EncodeStringAndAppend(sb, value, isKey);
sb.ToString().Should().Be(expected);
}

Expand Down

0 comments on commit 3286c90

Please sign in to comment.