File: test_syntax_floating.cpp

package info (click to toggle)
toml11 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,464 kB
  • sloc: cpp: 38,446; makefile: 8; sh: 5
file content (99 lines) | stat: -rw-r--r-- 4,073 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>

#include "utility.hpp"

#include <toml11/syntax.hpp>

TEST_CASE("testing fractional_valid")
{
    const auto floating = toml::detail::syntax::floating(toml::spec::v(1,0,0));
    test_scan_success(floating, "1.0",               "1.0"              );
    test_scan_success(floating, "0.1",               "0.1"              );
    test_scan_success(floating, "0.001",             "0.001"            );
    test_scan_success(floating, "0.100",             "0.100"            );
    test_scan_success(floating, "+3.14",             "+3.14"            );
    test_scan_success(floating, "-3.14",             "-3.14"            );
    test_scan_success(floating, "3.1415_9265_3589",  "3.1415_9265_3589" );
    test_scan_success(floating, "+3.1415_9265_3589", "+3.1415_9265_3589");
    test_scan_success(floating, "-3.1415_9265_3589", "-3.1415_9265_3589");
    test_scan_success(floating, "123_456.789",       "123_456.789"      );
    test_scan_success(floating, "+123_456.789",      "+123_456.789"     );
    test_scan_success(floating, "-123_456.789",      "-123_456.789"     );
}

TEST_CASE("testing fractional_invalid")
{
    const auto floating = toml::detail::syntax::floating(toml::spec::v(1,0,0));
    test_scan_failure(floating, "0.");
    test_scan_failure(floating, ".0");
    test_scan_failure(floating, "01.0");
    test_scan_failure(floating, "3,14");
    test_scan_failure(floating, "+-1.0");
    test_scan_failure(floating, "1._0");
}

TEST_CASE("testing exponential_valid")
{
    const auto floating = toml::detail::syntax::floating(toml::spec::v(1,0,0));
    test_scan_success(floating, "1e10",       "1e10");
    test_scan_success(floating, "1e+10",      "1e+10");
    test_scan_success(floating, "1e-10",      "1e-10");
    test_scan_success(floating, "+1e10",      "+1e10");
    test_scan_success(floating, "+1e+10",     "+1e+10");
    test_scan_success(floating, "+1e-10",     "+1e-10");
    test_scan_success(floating, "-1e10",      "-1e10");
    test_scan_success(floating, "-1e+10",     "-1e+10");
    test_scan_success(floating, "-1e-10",     "-1e-10");
    test_scan_success(floating, "123e-10",    "123e-10");
    test_scan_success(floating, "1E10",       "1E10");
    test_scan_success(floating, "1E+10",      "1E+10");
    test_scan_success(floating, "1E-10",      "1E-10");
    test_scan_success(floating, "123E-10",    "123E-10");
    test_scan_success(floating, "1_2_3E-10",  "1_2_3E-10");
    test_scan_success(floating, "1_2_3E-1_0", "1_2_3E-1_0");

    test_scan_success(floating, "1_2_3E-01",  "1_2_3E-01");
    test_scan_success(floating, "1_2_3E-0_1", "1_2_3E-0_1");
}

TEST_CASE("testing exponential_invalid")
{
    const auto floating = toml::detail::syntax::floating(toml::spec::v(1,0,0));
    // accept partially
    test_scan_success(floating, "1e1E0", "1e1");
    test_scan_success(floating, "1E1e0", "1E1");
}

TEST_CASE("testing both_valid")
{
    const auto floating = toml::detail::syntax::floating(toml::spec::v(1,0,0));
    test_scan_success(floating, "6.02e23",          "6.02e23");
    test_scan_success(floating, "6.02e+23",         "6.02e+23");
    test_scan_success(floating, "1.112_650_06e-17", "1.112_650_06e-17");

    test_scan_success(floating, "1.0e-07",          "1.0e-07");
}

TEST_CASE("testing both_invalid")
{
    const auto floating = toml::detail::syntax::floating(toml::spec::v(1,0,0));
    test_scan_failure(floating, "01e1.0");
    // accept partially
    test_scan_success(floating, "1e1.0",  "1e1");

    test_scan_success(floating, "1.0e_01",  "1.0");
    test_scan_success(floating, "1.0e0__1", "1.0e0");
}

TEST_CASE("testing special_floating_point")
{
    const auto floating = toml::detail::syntax::floating(toml::spec::v(1,0,0));
    test_scan_success(floating,  "inf",  "inf");
    test_scan_success(floating, "+inf", "+inf");
    test_scan_success(floating, "-inf", "-inf");

    test_scan_success(floating,  "nan",  "nan");
    test_scan_success(floating, "+nan", "+nan");
    test_scan_success(floating, "-nan", "-nan");
}