20 #include "gmock/gmock.h" 21 #include "gtest/gtest.h" 45 FloatType expected_type, uint64_t expected_mantissa,
46 int expected_exponent,
47 int expected_literal_exponent = -999) {
50 int begin_subrange = -1;
51 int end_subrange = -1;
54 std::string::size_type open_bracket_pos = s.find(
'[');
55 if (open_bracket_pos != std::string::npos) {
56 begin_subrange =
static_cast<int>(open_bracket_pos);
57 s.replace(open_bracket_pos, 1,
"");
58 std::string::size_type close_bracket_pos = s.find(
']');
60 "Test input contains [ without matching ]");
61 end_subrange =
static_cast<int>(close_bracket_pos);
62 s.replace(close_bracket_pos, 1,
"");
64 const std::string::size_type expected_characters_matched = s.find(
'$');
66 "Input std::string must contain $");
67 s.replace(expected_characters_matched, 1,
"");
70 ParseFloat<base>(s.data(), s.data() + s.size(), format_flags);
72 EXPECT_NE(parsed.
end,
nullptr);
73 if (parsed.
end ==
nullptr) {
76 EXPECT_EQ(parsed.
type, expected_type);
77 if (begin_subrange == -1) {
84 if (parsed.
type == FloatType::kNumber) {
85 EXPECT_EQ(parsed.
mantissa, expected_mantissa);
86 EXPECT_EQ(parsed.
exponent, expected_exponent);
87 if (expected_literal_exponent != -999) {
91 auto characters_matched =
static_cast<int>(parsed.
end - s.data());
92 EXPECT_EQ(characters_matched, expected_characters_matched);
102 uint64_t expected_mantissa,
int expected_exponent,
103 int expected_literal_exponent = -999) {
104 ExpectParsedFloat<base>(
std::move(s), format_flags, FloatType::kNumber,
105 expected_mantissa, expected_exponent,
106 expected_literal_exponent);
115 ExpectParsedFloat<10>(s, format_flags, type, 0, 0);
116 ExpectParsedFloat<16>(s, format_flags, type, 0, 0);
123 ParseFloat<base>(s.
data(), s.
data() + s.
size(), format_flags);
124 EXPECT_EQ(parsed.
end,
nullptr);
129 ExpectNumber<10>(
"1.23456789e5$", chars_format::general, 123456789, -3);
130 ExpectNumber<10>(
"1.23456789e+5$", chars_format::general, 123456789, -3);
131 ExpectNumber<10>(
"1.23456789E5$", chars_format::general, 123456789, -3);
132 ExpectNumber<10>(
"1.23456789e05$", chars_format::general, 123456789, -3);
133 ExpectNumber<10>(
"123.456789e3$", chars_format::general, 123456789, -3);
134 ExpectNumber<10>(
"0.000123456789e9$", chars_format::general, 123456789, -3);
135 ExpectNumber<10>(
"123456.789$", chars_format::general, 123456789, -3);
136 ExpectNumber<10>(
"123456789e-3$", chars_format::general, 123456789, -3);
138 ExpectNumber<16>(
"1.234abcdefp28$", chars_format::general, 0x1234abcdef, -8);
139 ExpectNumber<16>(
"1.234abcdefp+28$", chars_format::general, 0x1234abcdef, -8);
140 ExpectNumber<16>(
"1.234ABCDEFp28$", chars_format::general, 0x1234abcdef, -8);
141 ExpectNumber<16>(
"1.234AbCdEfP0028$", chars_format::general, 0x1234abcdef,
143 ExpectNumber<16>(
"123.4abcdefp20$", chars_format::general, 0x1234abcdef, -8);
144 ExpectNumber<16>(
"0.0001234abcdefp44$", chars_format::general, 0x1234abcdef,
146 ExpectNumber<16>(
"1234abcd.ef$", chars_format::general, 0x1234abcdef, -8);
147 ExpectNumber<16>(
"1234abcdefp-8$", chars_format::general, 0x1234abcdef, -8);
150 ExpectNumber<10>(
"0001.2345678900e005$", chars_format::general, 12345678900,
152 ExpectNumber<16>(
"0001.234abcdef000p28$", chars_format::general,
153 0x1234abcdef000, -20);
157 ExpectNumber<10>(
"1.23456789e5$ ", chars_format::general, 123456789, -3);
158 ExpectNumber<10>(
"1.23456789e5$e5e5", chars_format::general, 123456789, -3);
159 ExpectNumber<10>(
"1.23456789e5$.25", chars_format::general, 123456789, -3);
160 ExpectNumber<10>(
"1.23456789e5$-", chars_format::general, 123456789, -3);
161 ExpectNumber<10>(
"1.23456789e5$PUPPERS!!!", chars_format::general, 123456789,
163 ExpectNumber<10>(
"123456.789$efghij", chars_format::general, 123456789, -3);
164 ExpectNumber<10>(
"123456.789$e", chars_format::general, 123456789, -3);
165 ExpectNumber<10>(
"123456.789$p5", chars_format::general, 123456789, -3);
166 ExpectNumber<10>(
"123456.789$.10", chars_format::general, 123456789, -3);
168 ExpectNumber<16>(
"1.234abcdefp28$ ", chars_format::general, 0x1234abcdef,
170 ExpectNumber<16>(
"1.234abcdefp28$p28", chars_format::general, 0x1234abcdef,
172 ExpectNumber<16>(
"1.234abcdefp28$.125", chars_format::general, 0x1234abcdef,
174 ExpectNumber<16>(
"1.234abcdefp28$-", chars_format::general, 0x1234abcdef, -8);
175 ExpectNumber<16>(
"1.234abcdefp28$KITTEHS!!!", chars_format::general,
177 ExpectNumber<16>(
"1234abcd.ef$ghijk", chars_format::general, 0x1234abcdef,
179 ExpectNumber<16>(
"1234abcd.ef$p", chars_format::general, 0x1234abcdef, -8);
180 ExpectNumber<16>(
"1234abcd.ef$.10", chars_format::general, 0x1234abcdef, -8);
183 ExpectNumber<10>(
"9999999999999999999$", chars_format::general,
184 9999999999999999999u, 0);
185 ExpectNumber<16>(
"fffffffffffffff$", chars_format::general,
186 0xfffffffffffffffu, 0);
189 ExpectNumber<10>(
"0$", chars_format::general, 0, 0);
190 ExpectNumber<16>(
"0$", chars_format::general, 0, 0);
191 ExpectNumber<10>(
"000000000000000000000000000000000000000$",
192 chars_format::general, 0, 0);
193 ExpectNumber<16>(
"000000000000000000000000000000000000000$",
194 chars_format::general, 0, 0);
195 ExpectNumber<10>(
"0000000000000000000000.000000000000000000$",
196 chars_format::general, 0, 0);
197 ExpectNumber<16>(
"0000000000000000000000.000000000000000000$",
198 chars_format::general, 0, 0);
199 ExpectNumber<10>(
"0.00000000000000000000000000000000e123456$",
200 chars_format::general, 0, 0);
201 ExpectNumber<16>(
"0.00000000000000000000000000000000p123456$",
202 chars_format::general, 0, 0);
218 ExpectNumber<10>(
"100000000000000000000000000$", chars_format::general,
222 ExpectNumber<10>(
"123456789123456789100000000$", chars_format::general,
226 ExpectNumber<10>(
"[123456789123456789123456789]$", chars_format::general,
231 ExpectNumber<10>(
"[123456789123456789100000009]$", chars_format::general,
236 ExpectNumber<10>(
"[123456789123456789120000000]$", chars_format::general,
242 ExpectNumber<10>(
"[00000000123456789123456789123456789]$",
243 chars_format::general, 1234567891234567891,
247 ExpectNumber<10>(
"00000000123456789123456789100000000$",
248 chars_format::general, 1234567891234567891,
253 ExpectNumber<10>(
"1.234567891234567891e123$", chars_format::general,
254 1234567891234567891, 105);
255 ExpectNumber<10>(
"[1.23456789123456789123456789]e123$", chars_format::general,
263 ExpectNumber<10>(
"[1999999999999999999999]$", chars_format::general,
276 ExpectNumber<16>(
"123456789abcdef123456789abcdef$", chars_format::general,
277 0x123456789abcdef, 60);
280 ExpectNumber<16>(
"000000123456789abcdef123456789abcdef$",
281 chars_format::general, 0x123456789abcdef, 60);
285 ExpectNumber<16>(
"1.23456789abcdefp100$", chars_format::general,
286 0x123456789abcdef, 44);
287 ExpectNumber<16>(
"1.23456789abcdef123456789abcdefp100$",
288 chars_format::general, 0x123456789abcdef, 44);
292 ExpectNumber<16>(
"123456789abcdee123456789abcdee$", chars_format::general,
293 0x123456789abcdef, 60);
294 ExpectNumber<16>(
"123456789abcdee000000000000001$", chars_format::general,
295 0x123456789abcdef, 60);
296 ExpectNumber<16>(
"123456789abcdee000000000000000$", chars_format::general,
297 0x123456789abcdee, 60);
303 ExpectNumber<10>(
"1.23456789$e5", chars_format::fixed, 123456789, -8);
304 ExpectNumber<10>(
"123456.789$", chars_format::fixed, 123456789, -3);
305 ExpectNumber<16>(
"1.234abcdef$p28", chars_format::fixed, 0x1234abcdef, -36);
306 ExpectNumber<16>(
"1234abcd.ef$", chars_format::fixed, 0x1234abcdef, -8);
309 ExpectNumber<10>(
"1.23456789e5$", chars_format::scientific, 123456789, -3);
310 ExpectFailedParse<10>(
"-123456.789$", chars_format::scientific);
311 ExpectNumber<16>(
"1.234abcdefp28$", chars_format::scientific, 0x1234abcdef,
313 ExpectFailedParse<16>(
"1234abcd.ef$", chars_format::scientific);
317 ExpectFailedParse<10>(
"in", chars_format::general);
318 ExpectFailedParse<16>(
"in", chars_format::general);
319 ExpectFailedParse<10>(
"inx", chars_format::general);
320 ExpectFailedParse<16>(
"inx", chars_format::general);
321 ExpectSpecial(
"inf$", chars_format::general, FloatType::kInfinity);
322 ExpectSpecial(
"Inf$", chars_format::general, FloatType::kInfinity);
323 ExpectSpecial(
"INF$", chars_format::general, FloatType::kInfinity);
324 ExpectSpecial(
"inf$inite", chars_format::general, FloatType::kInfinity);
325 ExpectSpecial(
"iNfInItY$", chars_format::general, FloatType::kInfinity);
326 ExpectSpecial(
"infinity$!!!", chars_format::general, FloatType::kInfinity);
330 ExpectFailedParse<10>(
"na", chars_format::general);
331 ExpectFailedParse<16>(
"na", chars_format::general);
332 ExpectFailedParse<10>(
"nah", chars_format::general);
333 ExpectFailedParse<16>(
"nah", chars_format::general);
334 ExpectSpecial(
"nan$", chars_format::general, FloatType::kNan);
335 ExpectSpecial(
"NaN$", chars_format::general, FloatType::kNan);
336 ExpectSpecial(
"nAn$", chars_format::general, FloatType::kNan);
337 ExpectSpecial(
"NAN$", chars_format::general, FloatType::kNan);
338 ExpectSpecial(
"NaN$aNaNaNaNaBatman!", chars_format::general, FloatType::kNan);
346 ExpectSpecial(
"nan([0xabcdef])$", chars_format::general, FloatType::kNan);
347 ExpectSpecial(
"nan([0xabcdef])$...", chars_format::general, FloatType::kNan);
348 ExpectSpecial(
"nan([0xabcdef])$)...", chars_format::general, FloatType::kNan);
349 ExpectSpecial(
"nan([])$", chars_format::general, FloatType::kNan);
350 ExpectSpecial(
"nan([aAzZ09_])$", chars_format::general, FloatType::kNan);
352 ExpectSpecial(
"nan$(bad-char)", chars_format::general, FloatType::kNan);
354 ExpectSpecial(
"nan$(0xabcdef", chars_format::general, FloatType::kNan);
const char * subrange_begin
static constexpr size_type npos
constexpr size_type size() const noexcept
const char * subrange_end
#define ABSL_RAW_CHECK(condition, message)
strings_internal::ParsedFloat ParseFloat(const char *begin, const char *end, chars_format format_flags)
constexpr const_pointer data() const noexcept
TEST(Symbolize, Unimplemented)
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept