v8/test/unittests/conversions-unittest.cc
Yang Guo 7bbd0bfe51 Move number related files to src/numbers
R=bmeurer@chromium.org, clemensh@chromium.org, jkummerow@chromium.org, sigurds@chromium.org, ulan@chromium.org, verwaest@chromium.org

Bug: v8:9247
Change-Id: I153a6bbfc55989fe7a86c052f95c5cb8ee61e841
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1613244
Commit-Queue: Yang Guo <yangguo@chromium.org>
Auto-Submit: Yang Guo <yangguo@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61557}
2019-05-15 19:34:44 +00:00

77 lines
2.1 KiB
C++

// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/v8.h"
#include "src/numbers/conversions.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace interpreter {
class ConversionsTest : public ::testing::Test {
public:
ConversionsTest() = default;
~ConversionsTest() override = default;
SourcePosition toPos(int offset) {
return SourcePosition(offset, offset % 10 - 1);
}
};
// Some random offsets, mostly at 'suspicious' bit boundaries.
struct IntStringPair {
int integer;
std::string string;
};
static IntStringPair int_pairs[] = {{0, "0"},
{101, "101"},
{-1, "-1"},
{1024, "1024"},
{200000, "200000"},
{-1024, "-1024"},
{-200000, "-200000"},
{kMinInt, "-2147483648"},
{kMaxInt, "2147483647"}};
TEST_F(ConversionsTest, IntToCString) {
std::unique_ptr<char[]> buf(new char[4096]);
for (size_t i = 0; i < arraysize(int_pairs); i++) {
ASSERT_STREQ(IntToCString(int_pairs[i].integer, {buf.get(), 4096}),
int_pairs[i].string.c_str());
}
}
struct DoubleStringPair {
double number;
std::string string;
};
static DoubleStringPair double_pairs[] = {
{0.0, "0"},
{kMinInt, "-2147483648"},
{kMaxInt, "2147483647"},
// ES section 7.1.12.1 #sec-tostring-applied-to-the-number-type:
// -0.0 is stringified to "0".
{-0.0, "0"},
{1.1, "1.1"},
{0.1, "0.1"}};
TEST_F(ConversionsTest, DoubleToCString) {
std::unique_ptr<char[]> buf(new char[4096]);
for (size_t i = 0; i < arraysize(double_pairs); i++) {
ASSERT_STREQ(DoubleToCString(double_pairs[i].number, {buf.get(), 4096}),
double_pairs[i].string.c_str());
}
}
} // namespace interpreter
} // namespace internal
} // namespace v8