Commit bbc70f7f authored by Ian Clelland's avatar Ian Clelland Committed by Commit Bot

Add tests for parameterized dictionaries in SH

This imports the tests from
https://github.com/httpwg/structured-header-tests/blob/master/param-dict.json
into the structured headers unit tests.

Bug: 1011101
Change-Id: If9b34906c00cb6e63b91a3c313be28510a4c1a0e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087992
Commit-Queue: Asanka Herath <asanka@chromium.org>
Auto-Submit: Ian Clelland <iclelland@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746816}
parent 4c3f5196
...@@ -620,8 +620,50 @@ const struct DictionaryTestCase { ...@@ -620,8 +620,50 @@ const struct DictionaryTestCase {
"a=3, b=2"}, "a=3, b=2"},
{"numeric key dictionary", "a=1,1b=2,a=1", base::nullopt}, {"numeric key dictionary", "a=1,1b=2,a=1", base::nullopt},
{"uppercase key dictionary", "a=1,B=2,a=1", base::nullopt}, {"uppercase key dictionary", "a=1,B=2,a=1", base::nullopt},
{"bad key dictionary", "a=1,b!=2,a=1", base::nullopt}}; {"bad key dictionary", "a=1,b!=2,a=1", base::nullopt},
// Paramaterised dictionary tests
{"basic parameterised dict",
"abc=123;a=1;b=2, def=456, ghi=789;q=9;r=\"+w\"",
{Dictionary{
{{"abc", {Integer(123), {Param("a", 1), Param("b", 2)}}},
{"def", {Integer(456), {}}},
{"ghi", {Integer(789), {Param("q", 9), Param("r", "+w")}}}}}}},
{"single item parameterised dict",
"a=b; q=1.0",
{Dictionary{{{"a", {Token("b"), {DoubleParam("q", 1.0)}}}}}},
"a=b;q=1.0"},
{"list item parameterised dictionary",
"a=(1 2); q=1.0",
{Dictionary{{{"a",
{{{Integer(1L), {}}, {Integer(2L), {}}},
{DoubleParam("q", 1.0)}}}}}},
"a=(1 2);q=1.0"},
{"missing parameter value parameterised dict",
"a=3;c;d=5",
{Dictionary{{{"a", {Integer(3), {Param("c"), Param("d", 5)}}}}}}},
{"terminal missing parameter value parameterised dict",
"a=3;c=5;d",
{Dictionary{{{"a", {Integer(3), {Param("c", 5), Param("d")}}}}}}},
{"no whitespace parameterised dict",
"a=b;c=1,d=e;f=2",
{Dictionary{{{"a", {Token("b"), {Param("c", 1)}}},
{"d", {Token("e"), {Param("f", 2)}}}}}},
"a=b;c=1, d=e;f=2"},
{"whitespace before = parameterised dict", "a=b;q =0.5", base::nullopt},
{"whitespace after = parameterised dict", "a=b;q= 0.5", base::nullopt},
{"whitespace before ; parameterised dict", "a=b ;q=0.5", base::nullopt},
{"whitespace after ; parameterised dict",
"a=b; q=0.5",
{Dictionary{{{"a", {Token("b"), {DoubleParam("q", 0.5)}}}}}},
"a=b;q=0.5"},
{"extra whitespace parameterised dict",
"a=b; c=1 , d=e; f=2; g=3",
{Dictionary{{{"a", {Token("b"), {Param("c", 1)}}},
{"d", {Token("e"), {Param("f", 2), Param("g", 3)}}}}}},
"a=b;c=1, d=e;f=2;g=3"},
{"trailing comma parameterised list", "a=b; q=1.0,", base::nullopt},
{"empty item parameterised list", "a=b; q=1.0,,c=d", base::nullopt},
};
} // namespace } // namespace
TEST(StructuredHeaderTest, ParseBareItem) { TEST(StructuredHeaderTest, ParseBareItem) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment