File tree Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Expand file tree Collapse file tree 3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,15 @@ cc_test(
97
97
],
98
98
)
99
99
100
+ cc_test (
101
+ name = "supported_chars_test" ,
102
+ srcs = ["supported_chars_test.cpp" ],
103
+ deps = [
104
+ "//:fast_float" ,
105
+ "@doctest//doctest" ,
106
+ ],
107
+ )
108
+
100
109
cc_test (
101
110
name = "string_test" ,
102
111
srcs = ["string_test.cpp" ],
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ endfunction(fast_float_add_cpp_test)
68
68
69
69
fast_float_add_cpp_test (rcppfastfloat_test )
70
70
fast_float_add_cpp_test (wide_char_test )
71
+ fast_float_add_cpp_test (supported_chars_test )
71
72
fast_float_add_cpp_test (example_test )
72
73
fast_float_add_cpp_test (example_comma_test )
73
74
fast_float_add_cpp_test (basictest )
Original file line number Diff line number Diff line change
1
+ #include " fast_float/fast_float.h"
2
+ #include < iostream>
3
+ #include < string>
4
+ #include < system_error>
5
+
6
+ template <typename UC> bool test (std::string s, double expected) {
7
+ std::basic_string<UC> input (s.begin (), s.end ());
8
+ double result;
9
+ auto answer =
10
+ fast_float::from_chars (input.data (), input.data () + input.size (), result);
11
+ if (answer.ec != std::errc ()) {
12
+ std::cerr << " parsing of \" " << s << " \" should succeed\n " ;
13
+ return false ;
14
+ }
15
+ if (result != expected && !(std::isnan (result) && std::isnan (expected))) {
16
+ std::cerr << " parsing of \" " << s << " \" succeeded, expected " << expected
17
+ << " got " << result << " \n " ;
18
+ return false ;
19
+ }
20
+ return true ;
21
+ }
22
+
23
+ int main () {
24
+ if (!test<char >(" 4.2" , 4.2 )) {
25
+ std::cout << " test failure for char" << std::endl;
26
+ return EXIT_FAILURE;
27
+ }
28
+
29
+ if (!test<wchar_t >(" 4.2" , 4.2 )) {
30
+ std::cout << " test failure for wchar_t" << std::endl;
31
+ return EXIT_FAILURE;
32
+ }
33
+
34
+ #ifdef __cpp_char8_t
35
+ if (!test<char8_t >(" 4.2" , 4.2 )) {
36
+ std::cout << " test failure for char8_t" << std::endl;
37
+ return EXIT_FAILURE;
38
+ }
39
+ #endif
40
+
41
+ if (!test<char16_t >(" 4.2" , 4.2 )) {
42
+ std::cout << " test failure for char16_t" << std::endl;
43
+ return EXIT_FAILURE;
44
+ }
45
+
46
+ if (!test<char32_t >(" 4.2" , 4.2 )) {
47
+ std::cout << " test failure for char32_t" << std::endl;
48
+ return EXIT_FAILURE;
49
+ }
50
+
51
+ std::cout << " all ok" << std::endl;
52
+ return EXIT_SUCCESS;
53
+ }
You can’t perform that action at this time.
0 commit comments