2020-06-26 18:01:27 +00:00
|
|
|
// This file is a part of toml++ and is subject to the the terms of the MIT license.
|
|
|
|
// Copyright (c) 2019-2020 Mark Gillard <mark.gillard@outlook.com.au>
|
|
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2020-01-04 14:21:38 +00:00
|
|
|
#include "tests.h"
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
TEST_CASE("parsing - key-value pairs")
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
key = "value"
|
|
|
|
bare_key = "value"
|
|
|
|
bare-key = "value"
|
|
|
|
1234 = "value"
|
|
|
|
"" = "blank"
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-04-02 21:39:21 +00:00
|
|
|
CHECK(tbl.size() == 5);
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["key"] == "value"sv);
|
|
|
|
CHECK(tbl["bare_key"] == "value"sv);
|
|
|
|
CHECK(tbl["bare-key"] == "value"sv);
|
|
|
|
CHECK(tbl["1234"] == "value"sv);
|
|
|
|
CHECK(tbl[""] == "blank"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(key = # INVALID)"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-08-08 17:51:33 +00:00
|
|
|
#if UNICODE_LITERALS_OK
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"127.0.0.1" = "value"
|
|
|
|
"character encoding" = "value"
|
|
|
|
"ʎǝʞ" = "value"
|
|
|
|
'key2' = "value"
|
|
|
|
'quoted "value"' = "value"
|
|
|
|
'' = 'blank'
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["127.0.0.1"] == "value"sv);
|
|
|
|
CHECK(tbl["character encoding"] == "value"sv);
|
|
|
|
CHECK(tbl["ʎǝʞ"] == "value"sv);
|
|
|
|
CHECK(tbl["key2"] == "value"sv);
|
|
|
|
CHECK(tbl["quoted \"value\""] == "value"sv);
|
|
|
|
CHECK(tbl[""] == "blank"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
2020-08-08 17:51:33 +00:00
|
|
|
#endif // UNICODE_LITERALS_OK
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(= "no key name")"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
# DO NOT DO THIS
|
|
|
|
name = "Tom"
|
|
|
|
name = "Pradyun"
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 09:12:43 +00:00
|
|
|
TEST_CASE("parsing - key-value pairs (dotted)")
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
name = "Orange"
|
|
|
|
physical.color = "orange"
|
|
|
|
physical.shape = "round"
|
|
|
|
site."google.com" = true
|
|
|
|
3.14159 = "pi"
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-04-02 21:39:21 +00:00
|
|
|
CHECK(tbl.size() == 4);
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["name"] == "Orange"sv);
|
|
|
|
CHECK(tbl["physical"]["color"] == "orange"sv);
|
|
|
|
CHECK(tbl["physical"]["shape"] == "round"sv);
|
|
|
|
CHECK(tbl["site"]["google.com"] == true);
|
|
|
|
CHECK(tbl["3"]["14159"] == "pi"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
fruit.apple.smooth = true
|
|
|
|
fruit.orange = 2
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["fruit"]["apple"]["smooth"] == true);
|
|
|
|
CHECK(tbl["fruit"]["orange"] == 2);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
# THIS IS INVALID
|
|
|
|
fruit.apple = 1
|
|
|
|
fruit.apple.smooth = true
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
# VALID BUT DISCOURAGED
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
apple.type = "fruit"
|
|
|
|
orange.type = "fruit"
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
apple.skin = "thin"
|
|
|
|
orange.skin = "thick"
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
apple.color = "red"
|
|
|
|
orange.color = "orange"
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["apple"]["type"] == "fruit"sv);
|
|
|
|
CHECK(tbl["apple"]["skin"] == "thin"sv);
|
|
|
|
CHECK(tbl["apple"]["color"] == "red"sv);
|
|
|
|
CHECK(tbl["orange"]["type"] == "fruit"sv);
|
|
|
|
CHECK(tbl["orange"]["skin"] == "thick"sv);
|
|
|
|
CHECK(tbl["orange"]["color"] == "orange"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
# RECOMMENDED
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
apple.type = "fruit"
|
|
|
|
apple.skin = "thin"
|
|
|
|
apple.color = "red"
|
2020-01-04 14:21:38 +00:00
|
|
|
|
2020-06-08 15:31:23 +00:00
|
|
|
orange.type = "fruit"
|
|
|
|
orange.skin = "thick"
|
|
|
|
orange.color = "orange"
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-01-04 14:21:38 +00:00
|
|
|
{
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["apple"]["type"] == "fruit"sv);
|
|
|
|
CHECK(tbl["apple"]["skin"] == "thin"sv);
|
|
|
|
CHECK(tbl["apple"]["color"] == "red"sv);
|
|
|
|
CHECK(tbl["orange"]["type"] == "fruit"sv);
|
|
|
|
CHECK(tbl["orange"]["skin"] == "thick"sv);
|
|
|
|
CHECK(tbl["orange"]["color"] == "orange"sv);
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
|
|
|
);
|
2020-01-06 18:21:16 +00:00
|
|
|
|
2020-04-02 21:39:21 +00:00
|
|
|
// toml/issues/644 ('+' in bare keys) & toml/issues/687 (unicode bare keys)
|
2020-08-08 17:51:33 +00:00
|
|
|
#if UNICODE_LITERALS_OK
|
2020-04-02 21:39:21 +00:00
|
|
|
#if TOML_LANG_UNRELEASED
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_succeed(
|
|
|
|
FILE_LINE_ARGS,
|
2020-06-28 22:57:59 +00:00
|
|
|
R"(
|
2020-04-06 12:57:49 +00:00
|
|
|
key+1 = 0
|
|
|
|
ʎǝʞ2 = 0
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv,
|
2020-04-18 13:14:07 +00:00
|
|
|
[](table&& tbl)
|
2020-04-02 21:39:21 +00:00
|
|
|
{
|
|
|
|
CHECK(tbl.size() == 2);
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["key+1"] == 0);
|
|
|
|
CHECK(tbl["ʎǝʞ2"] == 0);
|
2020-04-02 21:39:21 +00:00
|
|
|
}
|
|
|
|
);
|
2020-01-06 18:21:16 +00:00
|
|
|
#else
|
2020-04-06 12:57:49 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(key+1 = 0)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(ʎǝʞ2 = 0)"sv);
|
2020-01-06 18:21:16 +00:00
|
|
|
#endif
|
2020-08-08 17:51:33 +00:00
|
|
|
#endif // UNICODE_LITERALS_OK
|
2020-01-04 14:21:38 +00:00
|
|
|
}
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
TEST_CASE("parsing - key-value pairs (string keys)")
|
|
|
|
{
|
|
|
|
// these are all derived from the discussion at
|
|
|
|
// https://github.com/toml-lang/toml/issues/733.
|
|
|
|
|
|
|
|
// whitespace stripped, fail duplicate keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
a = 2
|
|
|
|
a = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// only surrounding whitespace is stripped, fail: illegal key name or syntax error
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, "a b = 3"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// whitespace is allowed when quoted, fail duplicate key
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, "\"a b\" = 3"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, "'a b' = 3"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"a b" = 3
|
|
|
|
'a b' = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// whitespace is allowed when quoted, but not collapsed, success
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"a b" = 3
|
|
|
|
'a b' = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// whitespace relevant, but fail: duplicate key
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"a " = 2
|
|
|
|
'a ' = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// whitespace relevant, and not collapsed, success
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"a " = 2
|
|
|
|
"a " = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// whitespace can be escaped, success, different keys (whitespace escapes are not normalized)
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"a\n" = 2
|
|
|
|
"a\r" = 3
|
|
|
|
"a\t" = 3
|
|
|
|
"a\f" = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// valid keys composed of various string/non-string mixes types
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(a = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"('a' = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("a" = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(a.b = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"('a'.b = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("a".b = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(a.'b' = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"('a'.'b' = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("a".'b' = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(a."b" = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"('a'."b" = 3)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("a"."b" = 3)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// multi-line strings can't be used in keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"('''a''' = 3)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"("""a""" = 3)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(a.'''b''' = 3)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(a."""b""" = 3)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// whitespace relevant (success test, values are NOTE equal)
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
a = " to do "
|
|
|
|
b = "to do"
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv, [](table&& tbl)
|
2020-06-08 15:31:23 +00:00
|
|
|
{
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["a"] == " to do "sv);
|
|
|
|
CHECK(tbl["b"] == "to do"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// values must be quoted, syntax error
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
a = to do
|
|
|
|
b = todo
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// different quotes, fail duplicate keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
a = 2
|
|
|
|
'a' = 2
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
'a' = 2
|
|
|
|
"a" = 2
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
'a' = 2
|
|
|
|
"""a""" = 2
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
'''a''' = 2
|
|
|
|
"""a""" = 2
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// success test, capital not equal to small
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
a = 2
|
|
|
|
A = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// inner quotes are not stripped from value, a & b are equal, value surrounded by quotes
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
a = "\"quoted\""
|
|
|
|
b = """"quoted""""
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv, [](table&& tbl)
|
2020-06-08 15:31:23 +00:00
|
|
|
{
|
2020-07-18 12:10:19 +00:00
|
|
|
CHECK(tbl["a"] == "\"quoted\""sv);
|
|
|
|
CHECK(tbl["b"] == "\"quoted\""sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// quote correction is not applied, fail syntax error
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"("a = "test")"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"('a = 'test')"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"("a = 'test")"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"('a = "test')"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// quotes cannot appear in keys this way, fail syntax error
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"("a'b = 3)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"("a"b = 3)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// escaped quotes and single quotes can appear this way, fail duplicate keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("a'b" = 2)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("a\u0027b" = 4)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"a'b" = 2
|
|
|
|
"a\u0027b" = 4
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// literal strings, escapes are not escaped, success, since keys are valid and not equal
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
'a"b' = 2
|
|
|
|
'a\"b' = 4
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// escapes must be compared after unescaping, fail duplicate key
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(a = 1)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("\u0061" = 2)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
a = 1
|
|
|
|
"\u0061" = 2
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// escaping requires quotes, syntax error
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(\u0061 = 2)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// empty keys are allowed, but can only appear once, fail duplicate key
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("" = 2)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"('' = 3)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
"" = 2
|
|
|
|
'' = 3
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, fail duplicate key
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(1234 = 5)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("1234" = 5)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
1234 = 5
|
|
|
|
"1234" = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, fail duplicate key
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(1234 = 5)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"('1234' = 5)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
1234 = 5
|
|
|
|
'1234' = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, valid, different keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
1234 = 5
|
|
|
|
01234 = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, valid, different keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
12e3 = 4
|
|
|
|
12000 = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, valid, different keys, one dotted
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
1.2e3 = 4
|
|
|
|
1200 = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, success, cause one is dotted
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
1.2e3 = 4
|
|
|
|
"1.2e3" = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, fail duplicate keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(12e3 = 4)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("12e3" = 5)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
12e3 = 4
|
|
|
|
"12e3" = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, fail duplicate dotted keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(1.2e3 = 4)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(1."2e3" = 5)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
1.2e3 = 4
|
|
|
|
1."2e3" = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
|
|
|
|
// bare keys can be numerals, but are interpreted as strings, fail duplicate dotted keys
|
2020-06-28 22:57:59 +00:00
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"(1.2e3 = 4)"sv);
|
|
|
|
parsing_should_succeed(FILE_LINE_ARGS, R"("1".2e3 = 5)"sv);
|
|
|
|
parsing_should_fail(FILE_LINE_ARGS, R"(
|
2020-06-08 15:31:23 +00:00
|
|
|
1.2e3 = 4
|
|
|
|
"1".2e3 = 5
|
2020-06-28 22:57:59 +00:00
|
|
|
)"sv);
|
2020-06-08 15:31:23 +00:00
|
|
|
}
|