summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-smi-lexicographic-compare.cc
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2018-12-04 08:20:37 +0100
committerMichaël Zasso <targos@protonmail.com>2018-12-06 15:23:33 +0100
commit9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3 (patch)
tree2b0c843168dafb939d8df8a15b2aa72b76dee51d /deps/v8/test/cctest/test-smi-lexicographic-compare.cc
parentb8fbe69db1292307adb2c2b2e0d5ef48c4ab2faf (diff)
downloadandroid-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.tar.gz
android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.tar.bz2
android-node-v8-9b4bf7de6c9a7c25f116c7a502384c20b5cfaea3.zip
deps: update V8 to 7.1.302.28
PR-URL: https://github.com/nodejs/node/pull/23423 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'deps/v8/test/cctest/test-smi-lexicographic-compare.cc')
-rw-r--r--deps/v8/test/cctest/test-smi-lexicographic-compare.cc79
1 files changed, 79 insertions, 0 deletions
diff --git a/deps/v8/test/cctest/test-smi-lexicographic-compare.cc b/deps/v8/test/cctest/test-smi-lexicographic-compare.cc
new file mode 100644
index 0000000000..58617fd5c2
--- /dev/null
+++ b/deps/v8/test/cctest/test-smi-lexicographic-compare.cc
@@ -0,0 +1,79 @@
+// Copyright 2018 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 <set>
+
+#include "src/objects-inl.h"
+#include "src/v8.h"
+#include "test/cctest/cctest.h"
+
+namespace v8 {
+namespace internal {
+
+namespace {
+
+void AddSigned(std::set<Smi*>& smis, int64_t x) {
+ if (!Smi::IsValid(x)) return;
+
+ smis.insert(Smi::FromInt(static_cast<int>(x)));
+ smis.insert(Smi::FromInt(static_cast<int>(-x)));
+}
+
+// Uses std::lexicographical_compare twice to convert the result to -1, 0 or 1.
+int ExpectedCompareResult(Smi* a, Smi* b) {
+ std::string str_a = std::to_string(a->value());
+ std::string str_b = std::to_string(b->value());
+ bool expected_a_lt_b = std::lexicographical_compare(
+ str_a.begin(), str_a.end(), str_b.begin(), str_b.end());
+ bool expected_b_lt_a = std::lexicographical_compare(
+ str_b.begin(), str_b.end(), str_a.begin(), str_a.end());
+
+ if (!expected_a_lt_b && !expected_b_lt_a) {
+ return 0;
+ } else if (expected_a_lt_b) {
+ return -1;
+ } else {
+ CHECK(expected_b_lt_a);
+ return 1;
+ }
+}
+
+bool Test(Isolate* isolate, Smi* a, Smi* b) {
+ int actual = Smi::LexicographicCompare(isolate, a, b)->value();
+ int expected = ExpectedCompareResult(a, b);
+
+ return actual == expected;
+}
+
+} // namespace
+
+TEST(TestSmiLexicographicCompare) {
+ Isolate* isolate = CcTest::InitIsolateOnce();
+ HandleScope scope(isolate);
+
+ std::set<Smi*> smis;
+
+ for (int64_t xb = 1; xb <= Smi::kMaxValue; xb *= 10) {
+ for (int64_t xf = 0; xf <= 9; ++xf) {
+ for (int64_t xo = -1; xo <= 1; ++xo) {
+ AddSigned(smis, xb * xf + xo);
+ }
+ }
+ }
+
+ for (int64_t yb = 1; yb <= Smi::kMaxValue; yb *= 2) {
+ for (int64_t yo = -2; yo <= 2; ++yo) {
+ AddSigned(smis, yb + yo);
+ }
+ }
+
+ for (Smi* a : smis) {
+ for (Smi* b : smis) {
+ CHECK(Test(isolate, a, b));
+ }
+ }
+}
+
+} // namespace internal
+} // namespace v8