mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-12 15:50:07 +00:00
10fd14f8b9
This patch consistently changes the inclusion order for unit test files to the following: 1. The header of the unit under test (using <> includes). 2. The unit_test.hpp header (using "" includes). 3. Any additional auxiliary test headers (using "" includes and sorted alphabetically). 4. Additional system headers needed for the test (using <> includes and sorted alphabetically). 5. Conditionally included system headers (using <> includes). Putting the unit under test's header at the very beginning has the advantage of also testing that the header is self-contained. It also makes it very quick to tell what unit is tested in this file.
102 lines
3.8 KiB
C++
102 lines
3.8 KiB
C++
#include <toml/lexer.hpp>
|
|
|
|
#include "unit_test.hpp"
|
|
#include "test_lex_aux.hpp"
|
|
|
|
using namespace toml;
|
|
using namespace detail;
|
|
|
|
BOOST_AUTO_TEST_CASE(test_decimal_correct)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "1234", "1234" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "+1234", "+1234" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "-1234", "-1234" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0", "0" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "1_2_3_4", "1_2_3_4" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "+1_2_3_4", "+1_2_3_4" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "-1_2_3_4", "-1_2_3_4" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "123_456_789", "123_456_789");
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_decimal_invalid)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "123+45", "123");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "123-45", "123");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "01234", "0");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "123__45", "123");
|
|
|
|
TOML11_TEST_LEX_REJECT(lex_integer, "_1234");
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_hex_correct)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xDEADBEEF", "0xDEADBEEF" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xdeadbeef", "0xdeadbeef" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xDEADbeef", "0xDEADbeef" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xDEAD_BEEF", "0xDEAD_BEEF");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xdead_beef", "0xdead_beef");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xdead_BEEF", "0xdead_BEEF");
|
|
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xFF", "0xFF" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0x00FF", "0x00FF" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0x0000FF", "0x0000FF");
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_hex_invalid)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xAPPLE", "0xA");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xDEAD+BEEF", "0xDEAD");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0xDEAD__BEEF", "0xDEAD");
|
|
|
|
TOML11_TEST_LEX_REJECT(lex_hex_int, "0x_DEADBEEF");
|
|
TOML11_TEST_LEX_REJECT(lex_hex_int, "0x+DEADBEEF");
|
|
TOML11_TEST_LEX_REJECT(lex_hex_int, "-0xFF" );
|
|
TOML11_TEST_LEX_REJECT(lex_hex_int, "-0x00FF" );
|
|
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0x_DEADBEEF", "0" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0x+DEADBEEF", "0" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "-0xFF" , "-0" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "-0x00FF" , "-0" );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_oct_correct)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o777", "0o777" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o7_7_7", "0o7_7_7");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o007", "0o007" );
|
|
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_oct_invalid)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o77+7", "0o77");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o1__0", "0o1");
|
|
|
|
TOML11_TEST_LEX_REJECT(lex_oct_int, "0o800" );
|
|
TOML11_TEST_LEX_REJECT(lex_oct_int, "-0o777");
|
|
TOML11_TEST_LEX_REJECT(lex_oct_int, "0o+777");
|
|
TOML11_TEST_LEX_REJECT(lex_oct_int, "0o_10" );
|
|
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o800", "0");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "-0o777", "-0");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o+777", "0");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0o_10", "0");
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_bin_correct)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0b10000", "0b10000" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0b010000", "0b010000" );
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0b01_00_00", "0b01_00_00");
|
|
TOML11_TEST_LEX_ACCEPT(lex_integer, "0b111111", "0b111111" );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_bin_invalid)
|
|
{
|
|
TOML11_TEST_LEX_ACCEPT(lex_bin_int, "0b11__11", "0b11");
|
|
TOML11_TEST_LEX_ACCEPT(lex_bin_int, "0b11+11" , "0b11");
|
|
|
|
TOML11_TEST_LEX_REJECT(lex_bin_int, "-0b10000");
|
|
TOML11_TEST_LEX_REJECT(lex_bin_int, "0b_1111" );
|
|
}
|