mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 09:08:08 +08:00
add test for lexers
This commit is contained in:
78
tests/test_lex_string.cpp
Normal file
78
tests/test_lex_string.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#define BOOST_TEST_MODULE "test_lex_string"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <toml/lexer.hpp>
|
||||
#include "test_lex_aux.hpp"
|
||||
|
||||
using namespace toml;
|
||||
using namespace detail;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_string)
|
||||
{
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\"The quick brown fox jumps over the lazy dog\"",
|
||||
"\"The quick brown fox jumps over the lazy dog\"");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\'The quick brown fox jumps over the lazy dog\'",
|
||||
"\'The quick brown fox jumps over the lazy dog\'");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_ml_basic_string,
|
||||
"\"\"\"The quick brown fox \\\njumps over the lazy dog\"\"\"",
|
||||
"\"\"\"The quick brown fox \\\njumps over the lazy dog\"\"\"");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_ml_literal_string,
|
||||
"'''The quick brown fox \njumps over the lazy dog'''",
|
||||
"'''The quick brown fox \njumps over the lazy dog'''");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_basic_string)
|
||||
{
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\"GitHub Cofounder & CEO\\nLikes tater tots and beer.\"",
|
||||
"\"GitHub Cofounder & CEO\\nLikes tater tots and beer.\"");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\"192.168.1.1\"",
|
||||
"\"192.168.1.1\"");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\"中国\"",
|
||||
"\"中国\"");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\"You'll hate me after this - #\"",
|
||||
"\"You'll hate me after this - #\"");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\" And when \\\"'s are in the string, along with # \\\"\"",
|
||||
"\" And when \\\"'s are in the string, along with # \\\"\"");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ml_basic_string)
|
||||
{
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"\"\"\"\nThe quick brown \\\n\n fox jumps over \\\n the lazy dog.\"\"\"",
|
||||
"\"\"\"\nThe quick brown \\\n\n fox jumps over \\\n the lazy dog.\"\"\"");
|
||||
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 \"\"\"");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_literal_string)
|
||||
{
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"'C:\\Users\\nodejs\\templates'",
|
||||
"'C:\\Users\\nodejs\\templates'");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"'\\\\ServerX\\admin$\\system32\\'",
|
||||
"'\\\\ServerX\\admin$\\system32\\'");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"'Tom \"Dubs\" Preston-Werner'",
|
||||
"'Tom \"Dubs\" Preston-Werner'");
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"'<\\i\\c*\\s*>'",
|
||||
"'<\\i\\c*\\s*>'");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ml_literal_string)
|
||||
{
|
||||
TOML11_TEST_LEX_ACCEPT(lex_string,
|
||||
"'''I [dw]on't need \\d{2} apples'''",
|
||||
"'''I [dw]on't need \\d{2} apples'''");
|
||||
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'''");
|
||||
}
|
Reference in New Issue
Block a user