Commit 068d6078 authored by Ian Clelland's avatar Ian Clelland Committed by Commit Bot

Structured Headers: Include all public tests

This imports all of the tests from the public test repository at
https://github.com/httpwg/structured-header-tests, which have been
automatically converted from JSON to C++ unit tests.

Tests which were already present in structured_headers_unittest.cc
have been removed from that file, to avoid needless redundancy.

Bug: 1069790
Change-Id: I05536c36cb66c7dda43aab2f6c5ae77961120a6a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2146237
Commit-Queue: Ian Clelland <iclelland@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759015}
parent cd86d58a
...@@ -4289,6 +4289,7 @@ test("net_unittests") { ...@@ -4289,6 +4289,7 @@ test("net_unittests") {
"http/http_vary_data_unittest.cc", "http/http_vary_data_unittest.cc",
"http/mock_allow_http_auth_preferences.cc", "http/mock_allow_http_auth_preferences.cc",
"http/mock_allow_http_auth_preferences.h", "http/mock_allow_http_auth_preferences.h",
"http/structured_headers_generated_unittest.cc",
"http/structured_headers_unittest.cc", "http/structured_headers_unittest.cc",
"http/transport_security_persister_unittest.cc", "http/transport_security_persister_unittest.cc",
"http/transport_security_state_unittest.cc", "http/transport_security_state_unittest.cc",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -55,8 +55,9 @@ std::pair<std::string, Item> TokenParam(std::string key, std::string value) { ...@@ -55,8 +55,9 @@ std::pair<std::string, Item> TokenParam(std::string key, std::string value) {
return std::make_pair(key, Token(value)); return std::make_pair(key, Token(value));
} }
// Most test cases are taken from // Test cases taken from https://github.com/httpwg/structured-header-tests can
// https://github.com/httpwg/structured-header-tests. // be found in structured_headers_generated_unittest.cc
const struct ItemTestCase { const struct ItemTestCase {
const char* name; const char* name;
const char* raw; const char* raw;
...@@ -65,350 +66,19 @@ const struct ItemTestCase { ...@@ -65,350 +66,19 @@ const struct ItemTestCase {
// format is identical to raw. // format is identical to raw.
} item_test_cases[] = { } item_test_cases[] = {
// Token // Token
{"basic token - item", "a_b-c.d3:f%00/*", Token("a_b-c.d3:f%00/*")},
{"token with capitals - item", "fooBar", Token("fooBar")},
{"token starting with capitals - item", "FooBar", Token("FooBar")},
{"bad token - item", "abc$@%!", base::nullopt}, {"bad token - item", "abc$@%!", base::nullopt},
{"leading whitespace", " foo", Token("foo"), "foo"}, {"leading whitespace", " foo", Token("foo"), "foo"},
{"trailing whitespace", "foo ", Token("foo"), "foo"}, {"trailing whitespace", "foo ", Token("foo"), "foo"},
{"leading asterisk", "*foo", Token("*foo")}, {"leading asterisk", "*foo", Token("*foo")},
// Number // Number
{"basic integer", "42", Integer(42L)},
{"zero integer", "0", Integer(0L)},
{"leading 0 zero", "00", Integer(0L), "0"},
{"negative zero", "-0", Integer(0L), "0"},
{"double negative zero", "--0", base::nullopt},
{"negative integer", "-42", Integer(-42L)},
{"leading zero integer", "042", Integer(42L), "42"},
{"leading zero negative integer", "-042", Integer(-42L), "-42"},
{"comma", "2,3", base::nullopt},
{"negative non-DIGIT first character", "-a23", base::nullopt},
{"sign out of place", "4-2", base::nullopt},
{"whitespace after sign", "- 42", base::nullopt},
{"long integer", "999999999999999", Integer(999999999999999L)}, {"long integer", "999999999999999", Integer(999999999999999L)},
{"long negative integer", "-999999999999999", Integer(-999999999999999L)}, {"long negative integer", "-999999999999999", Integer(-999999999999999L)},
{"too long integer", "1000000000000000", base::nullopt}, {"too long integer", "1000000000000000", base::nullopt},
{"negative too long integer", "-1000000000000000", base::nullopt}, {"negative too long integer", "-1000000000000000", base::nullopt},
{"simple decimal", "1.23", Item(1.23)},
{"negative decimal", "-1.23", Item(-1.23)},
{"integral decimal", "1.0", Item(1.0)}, {"integral decimal", "1.0", Item(1.0)},
{"decimal, whitespace after decimal", "1. 23", base::nullopt},
{"decimal, whitespace before decimal", "1 .23", base::nullopt},
{"negative decimal, whitespace after sign", "- 1.23", base::nullopt},
{"double decimal decimal", "1.5.4", base::nullopt},
{"adjacent double decimal decimal", "1..4", base::nullopt},
{"decimal with three fractional digits", "1.123", Item(1.123)},
{"negative decimal with three fractional digits", "-1.123", Item(-1.123)},
{"decimal with four fractional digits", "1.1234", base::nullopt},
{"negative decimal with four fractional digits", "-1.1234", base::nullopt},
{"decimal with thirteen integer digits", "1234567890123.0", base::nullopt},
{"negative decimal with thirteen integer digits", "-1234567890123.0",
base::nullopt},
// Generated number tests
{"1 digits of zero", "0", Integer(0), "0"},
{"1 digit small integer", "1", Integer(1)},
{"1 digit large integer", "9", Integer(9)},
{"2 digits of zero", "00", Integer(0), "0"},
{"2 digit small integer", "11", Integer(11)},
{"2 digit large integer", "99", Integer(99)},
{"3 digits of zero", "000", Integer(0), "0"},
{"3 digit small integer", "111", Integer(111)},
{"3 digit large integer", "999", Integer(999)},
{"4 digits of zero", "0000", Integer(0), "0"},
{"4 digit small integer", "1111", Integer(1111)},
{"4 digit large integer", "9999", Integer(9999)},
{"5 digits of zero", "00000", Integer(0), "0"},
{"5 digit small integer", "11111", Integer(11111)},
{"5 digit large integer", "99999", Integer(99999)},
{"6 digits of zero", "000000", Integer(0), "0"},
{"6 digit small integer", "111111", Integer(111111)},
{"6 digit large integer", "999999", Integer(999999)},
{"7 digits of zero", "0000000", Integer(0), "0"},
{"7 digit small integer", "1111111", Integer(1111111)},
{"7 digit large integer", "9999999", Integer(9999999)},
{"8 digits of zero", "00000000", Integer(0), "0"},
{"8 digit small integer", "11111111", Integer(11111111)},
{"8 digit large integer", "99999999", Integer(99999999)},
{"9 digits of zero", "000000000", Integer(0), "0"},
{"9 digit small integer", "111111111", Integer(111111111)},
{"9 digit large integer", "999999999", Integer(999999999)},
{"10 digits of zero", "0000000000", Integer(0), "0"},
{"10 digit small integer", "1111111111", Integer(1111111111)},
{"10 digit large integer", "9999999999", Integer(9999999999)},
{"11 digits of zero", "00000000000", Integer(0), "0"},
{"11 digit small integer", "11111111111", Integer(11111111111)},
{"11 digit large integer", "99999999999", Integer(99999999999)},
{"12 digits of zero", "000000000000", Integer(0), "0"},
{"12 digit small integer", "111111111111", Integer(111111111111)},
{"12 digit large integer", "999999999999", Integer(999999999999)},
{"13 digits of zero", "0000000000000", Integer(0), "0"},
{"13 digit small integer", "1111111111111", Integer(1111111111111)},
{"13 digit large integer", "9999999999999", Integer(9999999999999)},
{"14 digits of zero", "00000000000000", Integer(0), "0"},
{"14 digit small integer", "11111111111111", Integer(11111111111111)},
{"14 digit large integer", "99999999999999", Integer(99999999999999)},
{"15 digits of zero", "000000000000000", Integer(0), "0"},
{"15 digit small integer", "111111111111111", Integer(111111111111111)},
{"15 digit large integer", "999999999999999", Integer(999999999999999)},
{"2 digit 0, 1 fractional small decimal", "0.1", Item(0.1), "0.1"},
{"2 digit, 1 fractional 0 decimal", "1.0", Item(1.0), "1.0"},
{"2 digit, 1 fractional small decimal", "1.1", Item(1.1)},
{"2 digit, 1 fractional large decimal", "9.9", Item(9.9)},
{"3 digit 0, 2 fractional small decimal", "0.11", Item(0.11), "0.11"},
{"3 digit, 2 fractional 0 decimal", "1.00", Item(1.0), "1.0"},
{"3 digit, 2 fractional small decimal", "1.11", Item(1.11)},
{"3 digit, 2 fractional large decimal", "9.99", Item(9.99)},
{"4 digit 0, 3 fractional small decimal", "0.111", Item(0.111), "0.111"},
{"4 digit, 3 fractional 0 decimal", "1.000", Item(1.0), "1.0"},
{"4 digit, 3 fractional small decimal", "1.111", Item(1.111)},
{"4 digit, 3 fractional large decimal", "9.999", Item(9.999)},
{"3 digit 0, 1 fractional small decimal", "00.1", Item(0.1), "0.1"},
{"3 digit, 1 fractional 0 decimal", "11.0", Item(11.0), "11.0"},
{"3 digit, 1 fractional small decimal", "11.1", Item(11.1)},
{"3 digit, 1 fractional large decimal", "99.9", Item(99.9)},
{"4 digit 0, 2 fractional small decimal", "00.11", Item(0.11), "0.11"},
{"4 digit, 2 fractional 0 decimal", "11.00", Item(11.0), "11.0"},
{"4 digit, 2 fractional small decimal", "11.11", Item(11.11)},
{"4 digit, 2 fractional large decimal", "99.99", Item(99.99)},
{"5 digit 0, 3 fractional small decimal", "00.111", Item(0.111), "0.111"},
{"5 digit, 3 fractional 0 decimal", "11.000", Item(11.0), "11.0"},
{"5 digit, 3 fractional small decimal", "11.111", Item(11.111)},
{"5 digit, 3 fractional large decimal", "99.999", Item(99.999)},
{"4 digit 0, 1 fractional small decimal", "000.1", Item(0.1), "0.1"},
{"4 digit, 1 fractional 0 decimal", "111.0", Item(111.0), "111.0"},
{"4 digit, 1 fractional small decimal", "111.1", Item(111.1)},
{"4 digit, 1 fractional large decimal", "999.9", Item(999.9)},
{"5 digit 0, 2 fractional small decimal", "000.11", Item(0.11), "0.11"},
{"5 digit, 2 fractional 0 decimal", "111.00", Item(111.0), "111.0"},
{"5 digit, 2 fractional small decimal", "111.11", Item(111.11)},
{"5 digit, 2 fractional large decimal", "999.99", Item(999.99)},
{"6 digit 0, 3 fractional small decimal", "000.111", Item(0.111), "0.111"},
{"6 digit, 3 fractional 0 decimal", "111.000", Item(111.0), "111.0"},
{"6 digit, 3 fractional small decimal", "111.111", Item(111.111)},
{"6 digit, 3 fractional large decimal", "999.999", Item(999.999)},
{"5 digit 0, 1 fractional small decimal", "0000.1", Item(0.1), "0.1"},
{"5 digit, 1 fractional 0 decimal", "1111.0", Item(1111.0), "1111.0"},
{"5 digit, 1 fractional small decimal", "1111.1", Item(1111.1)},
{"5 digit, 1 fractional large decimal", "9999.9", Item(9999.9)},
{"6 digit 0, 2 fractional small decimal", "0000.11", Item(0.11), "0.11"},
{"6 digit, 2 fractional 0 decimal", "1111.00", Item(1111.0), "1111.0"},
{"6 digit, 2 fractional small decimal", "1111.11", Item(1111.11)},
{"6 digit, 2 fractional large decimal", "9999.99", Item(9999.99)},
{"7 digit 0, 3 fractional small decimal", "0000.111", Item(0.111), "0.111"},
{"7 digit, 3 fractional 0 decimal", "1111.000", Item(1111.0), "1111.0"},
{"7 digit, 3 fractional small decimal", "1111.111", Item(1111.111)},
{"7 digit, 3 fractional large decimal", "9999.999", Item(9999.999)},
{"6 digit 0, 1 fractional small decimal", "00000.1", Item(0.1), "0.1"},
{"6 digit, 1 fractional 0 decimal", "11111.0", Item(11111.0), "11111.0"},
{"6 digit, 1 fractional small decimal", "11111.1", Item(11111.1)},
{"6 digit, 1 fractional large decimal", "99999.9", Item(99999.9)},
{"7 digit 0, 2 fractional small decimal", "00000.11", Item(0.11), "0.11"},
{"7 digit, 2 fractional 0 decimal", "11111.00", Item(11111.0), "11111.0"},
{"7 digit, 2 fractional small decimal", "11111.11", Item(11111.11)},
{"7 digit, 2 fractional large decimal", "99999.99", Item(99999.99)},
{"8 digit 0, 3 fractional small decimal", "00000.111", Item(0.111),
"0.111"},
{"8 digit, 3 fractional 0 decimal", "11111.000", Item(11111.0), "11111.0"},
{"8 digit, 3 fractional small decimal", "11111.111", Item(11111.111)},
{"8 digit, 3 fractional large decimal", "99999.999", Item(99999.999)},
{"7 digit 0, 1 fractional small decimal", "000000.1", Item(0.1), "0.1"},
{"7 digit, 1 fractional 0 decimal", "111111.0", Item(111111.0), "111111.0"},
{"7 digit, 1 fractional small decimal", "111111.1", Item(111111.1)},
{"7 digit, 1 fractional large decimal", "999999.9", Item(999999.9)},
{"8 digit 0, 2 fractional small decimal", "000000.11", Item(0.11), "0.11"},
{"8 digit, 2 fractional 0 decimal", "111111.00", Item(111111.0),
"111111.0"},
{"8 digit, 2 fractional small decimal", "111111.11", Item(111111.11)},
{"8 digit, 2 fractional large decimal", "999999.99", Item(999999.99)},
{"9 digit 0, 3 fractional small decimal", "000000.111", Item(0.111),
"0.111"},
{"9 digit, 3 fractional 0 decimal", "111111.000", Item(111111.0),
"111111.0"},
{"9 digit, 3 fractional small decimal", "111111.111", Item(111111.111)},
{"9 digit, 3 fractional large decimal", "999999.999", Item(999999.999)},
{"8 digit 0, 1 fractional small decimal", "0000000.1", Item(0.1), "0.1"},
{"8 digit, 1 fractional 0 decimal", "1111111.0", Item(1111111.0),
"1111111.0"},
{"8 digit, 1 fractional small decimal", "1111111.1", Item(1111111.1)},
{"8 digit, 1 fractional large decimal", "9999999.9", Item(9999999.9)},
{"9 digit 0, 2 fractional small decimal", "0000000.11", Item(0.11), "0.11"},
{"9 digit, 2 fractional 0 decimal", "1111111.00", Item(1111111.0),
"1111111.0"},
{"9 digit, 2 fractional small decimal", "1111111.11", Item(1111111.11)},
{"9 digit, 2 fractional large decimal", "9999999.99", Item(9999999.99)},
{"10 digit 0, 3 fractional small decimal", "0000000.111", Item(0.111),
"0.111"},
{"10 digit, 3 fractional 0 decimal", "1111111.000", Item(1111111.0),
"1111111.0"},
{"10 digit, 3 fractional small decimal", "1111111.111", Item(1111111.111)},
{"10 digit, 3 fractional large decimal", "9999999.999", Item(9999999.999)},
{"9 digit 0, 1 fractional small decimal", "00000000.1", Item(0.1), "0.1"},
{"9 digit, 1 fractional 0 decimal", "11111111.0", Item(11111111.0),
"11111111.0"},
{"9 digit, 1 fractional small decimal", "11111111.1", Item(11111111.1)},
{"9 digit, 1 fractional large decimal", "99999999.9", Item(99999999.9)},
{"10 digit 0, 2 fractional small decimal", "00000000.11", Item(0.11),
"0.11"},
{"10 digit, 2 fractional 0 decimal", "11111111.00", Item(11111111.0),
"11111111.0"},
{"10 digit, 2 fractional small decimal", "11111111.11", Item(11111111.11)},
{"10 digit, 2 fractional large decimal", "99999999.99", Item(99999999.99)},
{"11 digit 0, 3 fractional small decimal", "00000000.111", Item(0.111),
"0.111"},
{"11 digit, 3 fractional 0 decimal", "11111111.000", Item(11111111.0),
"11111111.0"},
{"11 digit, 3 fractional small decimal", "11111111.111",
Item(11111111.111)},
{"11 digit, 3 fractional large decimal", "99999999.999",
Item(99999999.999)},
{"10 digit 0, 1 fractional small decimal", "000000000.1", Item(0.1), "0.1"},
{"10 digit, 1 fractional 0 decimal", "111111111.0", Item(111111111.0),
"111111111.0"},
{"10 digit, 1 fractional small decimal", "111111111.1", Item(111111111.1)},
{"10 digit, 1 fractional large decimal", "999999999.9", Item(999999999.9)},
{"11 digit 0, 2 fractional small decimal", "000000000.11", Item(0.11),
"0.11"},
{"11 digit, 2 fractional 0 decimal", "111111111.00", Item(111111111.0),
"111111111.0"},
{"11 digit, 2 fractional small decimal", "111111111.11",
Item(111111111.11)},
{"11 digit, 2 fractional large decimal", "999999999.99",
Item(999999999.99)},
{"12 digit 0, 3 fractional small decimal", "000000000.111", Item(0.111),
"0.111"},
{"12 digit, 3 fractional 0 decimal", "111111111.000", Item(111111111.0),
"111111111.0"},
{"12 digit, 3 fractional small decimal", "111111111.111",
Item(111111111.111)},
{"12 digit, 3 fractional large decimal", "999999999.999",
Item(999999999.999)},
{"11 digit 0, 1 fractional small decimal", "0000000000.1", Item(0.1),
"0.1"},
{"11 digit, 1 fractional 0 decimal", "1111111111.0", Item(1111111111.0),
"1111111111.0"},
{"11 digit, 1 fractional small decimal", "1111111111.1",
Item(1111111111.1)},
{"11 digit, 1 fractional large decimal", "9999999999.9",
Item(9999999999.9)},
{"12 digit 0, 2 fractional small decimal", "0000000000.11", Item(0.11),
"0.11"},
{"12 digit, 2 fractional 0 decimal", "1111111111.00", Item(1111111111.0),
"1111111111.0"},
{"12 digit, 2 fractional small decimal", "1111111111.11",
Item(1111111111.11)},
{"12 digit, 2 fractional large decimal", "9999999999.99",
Item(9999999999.99)},
{"13 digit 0, 3 fractional small decimal", "0000000000.111", Item(0.111),
"0.111"},
{"13 digit, 3 fractional 0 decimal", "1111111111.000", Item(1111111111.0),
"1111111111.0"},
{"13 digit, 3 fractional small decimal", "1111111111.111",
Item(1111111111.111)},
{"13 digit, 3 fractional large decimal", "9999999999.999",
Item(9999999999.999)},
{"12 digit 0, 1 fractional small decimal", "00000000000.1", Item(0.1),
"0.1"},
{"12 digit, 1 fractional 0 decimal", "11111111111.0", Item(11111111111.0),
"11111111111.0"},
{"12 digit, 1 fractional small decimal", "11111111111.1",
Item(11111111111.1)},
{"12 digit, 1 fractional large decimal", "99999999999.9",
Item(99999999999.9)},
{"13 digit 0, 2 fractional small decimal", "00000000000.11", Item(0.11),
"0.11"},
{"13 digit, 2 fractional 0 decimal", "11111111111.00", Item(11111111111.0),
"11111111111.0"},
{"13 digit, 2 fractional small decimal", "11111111111.11",
Item(11111111111.11)},
{"13 digit, 2 fractional large decimal", "99999999999.99",
Item(99999999999.99)},
{"14 digit 0, 3 fractional small decimal", "00000000000.111", Item(0.111),
"0.111"},
{"14 digit, 3 fractional 0 decimal", "11111111111.000", Item(11111111111.0),
"11111111111.0"},
{"14 digit, 3 fractional small decimal", "11111111111.111",
Item(11111111111.111)},
{"14 digit, 3 fractional large decimal", "99999999999.999",
Item(99999999999.999)},
{"13 digit 0, 1 fractional small decimal", "000000000000.1", Item(0.1),
"0.1"},
{"13 digit, 1 fractional 0 decimal", "111111111111.0", Item(111111111111.0),
"111111111111.0"},
{"13 digit, 1 fractional small decimal", "111111111111.1",
Item(111111111111.1)},
{"13 digit, 1 fractional large decimal", "999999999999.9",
Item(999999999999.9)},
{"14 digit 0, 2 fractional small decimal", "000000000000.11", Item(0.11),
"0.11"},
{"14 digit, 2 fractional 0 decimal", "111111111111.00",
Item(111111111111.0), "111111111111.0"},
{"14 digit, 2 fractional small decimal", "111111111111.11",
Item(111111111111.11)},
{"14 digit, 2 fractional large decimal", "999999999999.99",
Item(999999999999.99)},
{"15 digit 0, 3 fractional small decimal", "000000000000.111", Item(0.111),
"0.111"},
{"15 digit, 3 fractional 0 decimal", "111111111111.000",
Item(111111111111.0), "111111111111.0"},
{"15 digit, 3 fractional small decimal", "111111111111.111",
Item(111111111111.111)},
{"15 digit, 3 fractional large decimal", "999999999999.999",
Item(999999999999.999)},
{"too many digit 0 decimal", "000000000000000.0", base::nullopt},
{"too many fractional digits 0 decimal", "000000000000.0000",
base::nullopt},
{"too many digit 9 decimal", "999999999999999.9", base::nullopt},
{"too many fractional digits 9 decimal", "999999999999.9999",
base::nullopt},
// Boolean
{"basic true boolean", "?1", Item(true)},
{"basic false boolean", "?0", Item(false)},
{"unknown boolean", "?Q", base::nullopt},
{"whitespace boolean", "? 1", base::nullopt},
{"negative zero boolean", "?-0", base::nullopt},
{"T boolean", "?T", base::nullopt},
{"F boolean", "?F", base::nullopt},
{"t boolean", "?t", base::nullopt},
{"f boolean", "?f", base::nullopt},
{"spelled-out True boolean", "?True", base::nullopt},
{"spelled-out False boolean", "?False", base::nullopt},
// Byte Sequence
{"basic binary", ":aGVsbG8=:", Item("hello", Item::kByteSequenceType)},
{"empty binary", "::", Item("", Item::kByteSequenceType)},
{"bad paddding", ":aGVsbG8:", Item("hello", Item::kByteSequenceType),
":aGVsbG8=:"},
{"bad end delimiter", ":aGVsbG8=", base::nullopt},
{"extra whitespace", ":aGVsb G8=:", base::nullopt},
{"extra chars", ":aGVsbG!8=:", base::nullopt},
{"suffix chars", ":aGVsbG8=!:", base::nullopt},
{"non-zero pad bits", ":iZ==:", Item("\x89", Item::kByteSequenceType),
":iQ==:"},
{"non-ASCII binary", ":/+Ah:", Item("\xFF\xE0!", Item::kByteSequenceType)},
{"base64url binary", ":_-Ah:", base::nullopt},
// String // String
{"basic string", "\"foo\"", Item("foo")}, {"basic string", "\"foo\"", Item("foo")},
{"empty string", "\"\"", Item("")},
{"long string",
"\"foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo "
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo "
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo "
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo \"",
Item("foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo "
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo "
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo "
"foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo "
"foo ")},
{"whitespace string", "\" \"", Item(" ")},
{"non-ascii string", "\"f\xC3\xBC\xC3\xBC\"", base::nullopt}, {"non-ascii string", "\"f\xC3\xBC\xC3\xBC\"", base::nullopt},
{"tab in string", "\"\t\"", base::nullopt},
{"newline in string", "\" \n \"", base::nullopt},
{"single quoted string", "'foo'", base::nullopt},
{"unbalanced string", "\"foo", base::nullopt},
{"string quoting", "\"foo \\\"bar\\\" \\\\ baz\"",
Item("foo \"bar\" \\ baz")},
{"bad string quoting", "\"foo \\,\"", base::nullopt},
{"ending string quote", "\"foo \\\"", base::nullopt},
{"abruptly ending string quote", "\"foo \\", base::nullopt},
// Additional tests // Additional tests
{"valid quoting containing \\n", "\"\\\\n\"", Item("\\n")}, {"valid quoting containing \\n", "\"\\\\n\"", Item("\\n")},
{"valid quoting containing \\t", "\"\\\\t\"", Item("\\t")}, {"valid quoting containing \\t", "\"\\\\t\"", Item("\\t")},
...@@ -497,40 +167,11 @@ const struct ListTestCase { ...@@ -497,40 +167,11 @@ const struct ListTestCase {
const char* canonical; // nullptr if parse error is expected, or if canonical const char* canonical; // nullptr if parse error is expected, or if canonical
// format is identical to raw. // format is identical to raw.
} list_test_cases[] = { } list_test_cases[] = {
// Basic lists
{"basic list", "1, 42", {{{Integer(1L), {}}, {Integer(42L), {}}}}},
{"empty list", "", List()},
{"single item list", "42", {{{Integer(42L), {}}}}},
{"no whitespace list",
"1,42",
{{{Integer(1L), {}}, {Integer(42L), {}}}},
"1, 42"},
{"trailing comma list", "1, 42,", base::nullopt},
{"empty item list", "1,,42", base::nullopt},
// Lists of lists // Lists of lists
{"basic list of lists",
"(1 2), (42 43)",
{{{{{Integer(1L), {}}, {Integer(2L), {}}}, {}},
{{{Integer(42L), {}}, {Integer(43L), {}}}, {}}}}},
{"single item list of lists",
"(42)",
{{{std::vector<ParameterizedItem>{{Integer(42L), {}}}, {}}}}},
{"empty item list of lists",
"()",
{{{std::vector<ParameterizedItem>(), {}}}}},
{"empty middle item list of lists",
"(1),(),(42)",
{{{std::vector<ParameterizedItem>{{Integer(1L), {}}}, {}},
{std::vector<ParameterizedItem>(), {}},
{std::vector<ParameterizedItem>{{Integer(42L), {}}}, {}}}},
"(1), (), (42)"},
{"extra whitespace list of lists", {"extra whitespace list of lists",
"(1 42)", "(1 42)",
{{{{{Integer(1L), {}}, {Integer(42L), {}}}, {}}}}, {{{{{Integer(1L), {}}, {Integer(42L), {}}}, {}}}},
"(1 42)"}, "(1 42)"},
{"no trailing parenthesis list of lists", "(1 42", base::nullopt},
{"no trailing parenthesis middle list of lists", "(1 2, (42 43)",
base::nullopt},
// Parameterized Lists // Parameterized Lists
{"basic parameterised list", {"basic parameterised list",
"abc_123;a=1;b=2; cdef_456, ghi;q=\"9\";r=\"+w\"", "abc_123;a=1;b=2; cdef_456, ghi;q=\"9\";r=\"+w\"",
...@@ -538,41 +179,6 @@ const struct ListTestCase { ...@@ -538,41 +179,6 @@ const struct ListTestCase {
{Param("a", 1), Param("b", 2), BooleanParam("cdef_456", true)}}, {Param("a", 1), Param("b", 2), BooleanParam("cdef_456", true)}},
{Token("ghi"), {Param("q", "9"), Param("r", "+w")}}}}, {Token("ghi"), {Param("q", "9"), Param("r", "+w")}}}},
"abc_123;a=1;b=2;cdef_456, ghi;q=\"9\";r=\"+w\""}, "abc_123;a=1;b=2;cdef_456, ghi;q=\"9\";r=\"+w\""},
{"single item parameterised list",
"text/html;q=1.0",
{{{Token("text/html"), {DoubleParam("q", 1)}}}}},
{"missing parameter value parameterised list",
"text/html;a;q=1.0",
{{{Token("text/html"), {BooleanParam("a", true), DoubleParam("q", 1)}}}}},
{"missing terminal parameter value parameterised list",
"text/html;q=1.0;a",
{{{Token("text/html"), {DoubleParam("q", 1), BooleanParam("a", true)}}}}},
{"no whitespace parameterised list",
"text/html,text/plain;q=0.5",
{{{Token("text/html"), {}},
{Token("text/plain"), {DoubleParam("q", 0.5)}}}},
"text/html, text/plain;q=0.5"},
{"whitespace before = parameterised list", "text/html, text/plain;q =0.5",
base::nullopt},
{"whitespace after = parameterised list", "text/html, text/plain;q= 0.5",
base::nullopt},
{"whitespace before ; parameterised list", "text/html, text/plain ;q=0.5",
base::nullopt},
{"whitespace after ; parameterised list",
"text/html, text/plain; q=0.5",
{{{Token("text/html"), {}},
{Token("text/plain"), {DoubleParam("q", 0.5)}}}},
"text/html, text/plain;q=0.5"},
{"extra whitespace parameterised list",
"text/html , text/plain; q=0.5; charset=utf-8",
{{{Token("text/html"), {}},
{Token("text/plain"),
{DoubleParam("q", 0.5), TokenParam("charset", "utf-8")}}}},
"text/html, text/plain;q=0.5;charset=utf-8"},
{"trailing comma parameterised list", "text/html,text/plain;q=0.5,",
base::nullopt},
{"empty item parameterised list", "text/html,,text/plain;q=0.5",
base::nullopt},
// Parameterized inner lists // Parameterized inner lists
{"parameterised basic list of lists", {"parameterised basic list of lists",
"(1;a=1.0 2), (42 43)", "(1;a=1.0 2), (42 43)",
...@@ -630,107 +236,13 @@ const struct DictionaryTestCase { ...@@ -630,107 +236,13 @@ const struct DictionaryTestCase {
"en=\"Applepie\", da=:aGVsbG8=:", "en=\"Applepie\", da=:aGVsbG8=:",
{Dictionary{{{"en", {Item("Applepie"), {}}}, {Dictionary{{{"en", {Item("Applepie"), {}}},
{"da", {Item("hello", Item::kByteSequenceType), {}}}}}}}, {"da", {Item("hello", Item::kByteSequenceType), {}}}}}}},
{"empty dictionary", "", Dictionary()},
{"single item dictionary", "a=1", {Dictionary{{{"a", {Integer(1L), {}}}}}}},
{"list item dictionary",
"a=(1 2)",
{Dictionary{{{"a", {{{Integer(1L), {}}, {Integer(2L), {}}}, {}}}}}}},
{"single list item dictionary",
"a=(1)",
{Dictionary{
{{"a", {std::vector<ParameterizedItem>{{Integer(1L), {}}}, {}}}}}}},
{"empty list item dictionary",
"a=()",
{Dictionary{{{"a", {std::vector<ParameterizedItem>(), {}}}}}}},
{"no whitespace dictionary",
"a=1,b=2",
{Dictionary{{{"a", {Integer(1L), {}}}, {"b", {Integer(2L), {}}}}}},
"a=1, b=2"},
{"extra whitespace dictionary",
"a=1 , b=2",
{Dictionary{{{"a", {Integer(1L), {}}}, {"b", {Integer(2L), {}}}}}},
"a=1, b=2"},
{"tab separated dictionary", "a=1\t,\tb=2", base::nullopt}, {"tab separated dictionary", "a=1\t,\tb=2", base::nullopt},
{"leading whitespace dictionary",
" a=1 , b=2",
{Dictionary{{{"a", {Integer(1L), {}}}, {"b", {Integer(2L), {}}}}}},
"a=1, b=2"},
{"whitespace before = dictionary", "a =1, b=2", base::nullopt},
{"whitespace after = dictionary", "a=1, b= 2", base::nullopt},
{"missing value dictionary",
"a=1, b, c=3",
{Dictionary{{{"a", {Integer(1L), {}}},
{"b", {Item(true), {}}},
{"c", {Integer(3L), {}}}}}}},
{"all missing value dictionary",
"a, b, c",
{Dictionary{{{"a", {Item(true), {}}},
{"b", {Item(true), {}}},
{"c", {Item(true), {}}}}}}},
{"start missing value dictionary",
"a, b=2",
{Dictionary{{{"a", {Item(true), {}}}, {"b", {Integer(2L), {}}}}}}},
{"end missing value dictionary",
"a=1, b",
{Dictionary{{{"a", {Integer(1L), {}}}, {"b", {Item(true), {}}}}}}},
{"missing value with params dictionary", {"missing value with params dictionary",
"a=1, b=?1;foo=9, c=3", "a=1, b=?1;foo=9, c=3",
{Dictionary{{{"a", {Integer(1L), {}}}, {Dictionary{{{"a", {Integer(1L), {}}},
{"b", {Item(true), {Param("foo", 9)}}}, {"b", {Item(true), {Param("foo", 9)}}},
{"c", {Integer(3L), {}}}}}}}, {"c", {Integer(3L), {}}}}}}},
{"trailing comma dictionary", "a=1, b=2,", base::nullopt},
{"empty item dictionary", "a=1,,b=2,", base::nullopt},
{"duplicate key dictionary",
"a=1,b=2,a=3",
{Dictionary{{{"a", {Integer(3L), {}}}, {"b", {Integer(2L), {}}}}}},
"a=3, b=2"},
{"numeric key dictionary", "a=1,1b=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},
// Parameterised dictionary tests // Parameterised 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), {BooleanParam("c", true), Param("d", 5)}}}}}}},
{"terminal missing parameter value parameterised dict",
"a=3;c=5;d",
{Dictionary{
{{"a", {Integer(3), {Param("c", 5), BooleanParam("d", true)}}}}}}},
{"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 dict", "a=b; q=1.0,", base::nullopt},
{"empty item parameterised dict", "a=b; q=1.0,,c=d", base::nullopt},
{"parameterised inner list member dict", {"parameterised inner list member dict",
"a=(\"1\";b=1;c=?0 \"2\");d=\"e\"", "a=(\"1\";b=1;c=?0 \"2\");d=\"e\"",
{Dictionary{{{"a", {Dictionary{{{"a",
......
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