From 7d03eb489a89ca24fdee415b1d2978a151316f0a Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Tue, 4 Feb 2020 22:37:11 +0900 Subject: [PATCH] test: add test cases with quotes in ml-string some of these example strings are copied from toml-lang/toml:README.md and some are modified. --- tests/test_lex_string.cpp | 28 +++++++++++++++++++++ tests/test_parse_string.cpp | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/tests/test_lex_string.cpp b/tests/test_lex_string.cpp index fcf0727..dadfcde 100644 --- a/tests/test_lex_string.cpp +++ b/tests/test_lex_string.cpp @@ -57,6 +57,22 @@ BOOST_AUTO_TEST_CASE(test_ml_basic_string) TOML11_TEST_LEX_ACCEPT(lex_string, "\"\"\"\\\n The quick brown \\\n\n fox jumps over \\\n the lazy dog.\\\n \"\"\"", "\"\"\"\\\n The quick brown \\\n\n fox jumps over \\\n the lazy dog.\\\n \"\"\""); + + TOML11_TEST_LEX_ACCEPT(lex_string, + "\"\"\"Here are two quotation marks: \"\". Simple enough.\"\"\"", + "\"\"\"Here are two quotation marks: \"\". Simple enough.\"\"\""); + + TOML11_TEST_LEX_ACCEPT(lex_string, + "\"\"\"Here are three quotation marks: \"\"\\\".\"\"\"", + "\"\"\"Here are three quotation marks: \"\"\\\".\"\"\""); + + TOML11_TEST_LEX_ACCEPT(lex_string, + "\"\"\"Here are fifteen quotation marks: \"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\".\"\"\"", + "\"\"\"Here are fifteen quotation marks: \"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\".\"\"\""); + + TOML11_TEST_LEX_ACCEPT(lex_string, + "\"\"\"\"This,\" she said, \"is just a pointless statement.\"\"\"\"", + "\"\"\"\"This,\" she said, \"is just a pointless statement.\"\"\"\""); } BOOST_AUTO_TEST_CASE(test_literal_string) @@ -83,4 +99,16 @@ BOOST_AUTO_TEST_CASE(test_ml_literal_string) TOML11_TEST_LEX_ACCEPT(lex_string, "'''\nThe first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n'''", "'''\nThe first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n'''"); + + TOML11_TEST_LEX_ACCEPT(lex_string, + "''''That's still pointless', she said.'''", + "''''That's still pointless', she said.'''"); + + TOML11_TEST_LEX_ACCEPT(lex_string, + "'''Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".'''", + "'''Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".'''"); + + TOML11_TEST_LEX_ACCEPT(lex_string, + "''''This,' she said, 'is just a pointless statement.''''", + "''''This,' she said, 'is just a pointless statement.''''"); } diff --git a/tests/test_parse_string.cpp b/tests/test_parse_string.cpp index fb1ff20..df4b787 100644 --- a/tests/test_parse_string.cpp +++ b/tests/test_parse_string.cpp @@ -69,6 +69,9 @@ BOOST_AUTO_TEST_CASE(test_basic_string) TOML11_TEST_PARSE_EQUAL(parse_string, "\" And when \\\"'s are in the along with # \\\"\"", string(" And when \"'s are in the along with # \"", string_t::basic)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "\"Here are fifteen apostrophes: '''''''''''''''\"", + string("Here are fifteen apostrophes: '''''''''''''''", string_t::basic)); } BOOST_AUTO_TEST_CASE(test_basic_string_value) @@ -94,6 +97,9 @@ BOOST_AUTO_TEST_CASE(test_basic_string_value) TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "\" And when \\\"'s are in the along with # \\\"\"", value(" And when \"'s are in the along with # \"", string_t::basic)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "\"Here are fifteen apostrophes: '''''''''''''''\"", + value("Here are fifteen apostrophes: '''''''''''''''", string_t::basic)); } BOOST_AUTO_TEST_CASE(test_ml_basic_string) @@ -104,6 +110,18 @@ BOOST_AUTO_TEST_CASE(test_ml_basic_string) TOML11_TEST_PARSE_EQUAL(parse_string, "\"\"\"\\\n The quick brown \\\n\n fox jumps over \\\n the lazy dog.\\\n \"\"\"", string("The quick brown fox jumps over the lazy dog.", string_t::basic)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "\"\"\"Here are two quotation marks: \"\". Simple enough.\"\"\"", + string("Here are two quotation marks: \"\". Simple enough.", string_t::basic)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "\"\"\"Here are three quotation marks: \"\"\\\".\"\"\"", + string("Here are three quotation marks: \"\"\".", string_t::basic)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "\"\"\"Here are fifteen quotation marks: \"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\".\"\"\"", + string("Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".", string_t::basic)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "\"\"\"\"This,\" she said, \"is just a pointless statement.\"\"\"\"", + string("\"This,\" she said, \"is just a pointless statement.\"", string_t::basic)); } BOOST_AUTO_TEST_CASE(test_ml_basic_string_value) @@ -114,6 +132,19 @@ BOOST_AUTO_TEST_CASE(test_ml_basic_string_value) TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "\"\"\"\\\n The quick brown \\\n\n fox jumps over \\\n the lazy dog.\\\n \"\"\"", value("The quick brown fox jumps over the lazy dog.", string_t::basic)); + + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "\"\"\"Here are two quotation marks: \"\". Simple enough.\"\"\"", + value("Here are two quotation marks: \"\". Simple enough.", string_t::basic)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "\"\"\"Here are three quotation marks: \"\"\\\".\"\"\"", + value("Here are three quotation marks: \"\"\".", string_t::basic)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "\"\"\"Here are fifteen quotation marks: \"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\"\"\"\\\".\"\"\"", + value("Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".", string_t::basic)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "\"\"\"\"This,\" she said, \"is just a pointless statement.\"\"\"\"", + value("\"This,\" she said, \"is just a pointless statement.\"", string_t::basic)); } BOOST_AUTO_TEST_CASE(test_literal_string) @@ -156,6 +187,15 @@ BOOST_AUTO_TEST_CASE(test_ml_literal_string) TOML11_TEST_PARSE_EQUAL(parse_string, "'''\nThe first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n'''", string("The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n", string_t::literal)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "''''That's still pointless', she said.'''", + string("'That's still pointless', she said.", string_t::literal)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "'''Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".'''", + string("Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".", string_t::literal)); + TOML11_TEST_PARSE_EQUAL(parse_string, + "''''This,' she said, 'is just a pointless statement.''''", + string("'This,' she said, 'is just a pointless statement.'", string_t::literal)); } BOOST_AUTO_TEST_CASE(test_ml_literal_string_value) @@ -166,6 +206,15 @@ BOOST_AUTO_TEST_CASE(test_ml_literal_string_value) TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, "'''\nThe first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n'''", value("The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n", string_t::literal)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "''''That's still pointless', she said.'''", + value("'That's still pointless', she said.", string_t::literal)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "'''Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".'''", + value("Here are fifteen quotation marks: \"\"\"\"\"\"\"\"\"\"\"\"\"\"\".", string_t::literal)); + TOML11_TEST_PARSE_EQUAL_VALUE(parse_value, + "''''This,' she said, 'is just a pointless statement.''''", + value("'This,' she said, 'is just a pointless statement.'", string_t::literal)); } BOOST_AUTO_TEST_CASE(test_unicode_escape_sequence)