forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDtoaTest.cpp
More file actions
48 lines (40 loc) · 1.41 KB
/
DtoaTest.cpp
File metadata and controls
48 lines (40 loc) · 1.41 KB
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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "dtoa/dtoa.h"
#include "gtest/gtest.h"
namespace {
TEST(DtoaTest, SmokeTest) {
char buf[32];
g_fmt(buf, 3.14);
EXPECT_STREQ("3.14", buf);
DtoaAllocator<> dalloc{};
char *se;
double val = hermes_g_strtod(buf, &se);
ASSERT_EQ(0, *se);
ASSERT_EQ(3.14, val);
const char *inv = "asdf";
val = hermes_g_strtod(inv, &se);
ASSERT_EQ(inv, se);
ASSERT_EQ(0, val);
#define DtoaDecimalTest(M, N, K, S, SIGN) \
{ \
int n, sign; \
char *s = ::g_dtoa(dalloc, M, 0, 0, &n, &sign, nullptr); \
int k = ::strlen(s); \
EXPECT_EQ(N, n); \
EXPECT_EQ(K, k); \
EXPECT_EQ(SIGN, sign); \
EXPECT_STREQ(S, s); \
g_freedtoa(dalloc, s); \
}
DtoaDecimalTest(2.123, 1, 4, "2123", 0);
DtoaDecimalTest(123, 3, 3, "123", 0);
DtoaDecimalTest(1000, 4, 1, "1", 0);
DtoaDecimalTest(1000000, 7, 1, "1", 0);
DtoaDecimalTest(-1000000, 7, 1, "1", 1);
}
} // namespace