Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Unified Diff: test/cctest/test-conversions.cc

Issue 19300002: ES6: Add support for explicit octal and binary integer literals (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix long lines Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/scanner.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-conversions.cc
diff --git a/test/cctest/test-conversions.cc b/test/cctest/test-conversions.cc
index 3253d832bb6edb317d400ea0d13296fd66918c16..9e194eafffbda0cafccf6de4d06567f8f91306a2 100644
--- a/test/cctest/test-conversions.cc
+++ b/test/cctest/test-conversions.cc
@@ -37,12 +37,14 @@ using namespace v8::internal;
TEST(Hex) {
UnicodeCache uc;
- CHECK_EQ(0.0, StringToDouble(&uc, "0x0", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.0, StringToDouble(&uc, "0X0", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(1.0, StringToDouble(&uc, "0x1", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(16.0, StringToDouble(&uc, "0x10", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(255.0, StringToDouble(&uc, "0xff", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(175.0, StringToDouble(&uc, "0xAF", ALLOW_HEX | ALLOW_OCTALS));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0x0", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0X0", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(1.0, StringToDouble(&uc, "0x1", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(16.0, StringToDouble(&uc, "0x10", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(255.0, StringToDouble(&uc, "0xff",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(175.0, StringToDouble(&uc, "0xAF",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
CHECK_EQ(0.0, StringToDouble(&uc, "0x0", ALLOW_HEX));
CHECK_EQ(0.0, StringToDouble(&uc, "0X0", ALLOW_HEX));
@@ -55,12 +57,32 @@ TEST(Hex) {
TEST(Octal) {
UnicodeCache uc;
- CHECK_EQ(0.0, StringToDouble(&uc, "0", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.0, StringToDouble(&uc, "00", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(1.0, StringToDouble(&uc, "01", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(7.0, StringToDouble(&uc, "07", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(8.0, StringToDouble(&uc, "010", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(63.0, StringToDouble(&uc, "077", ALLOW_HEX | ALLOW_OCTALS));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0o0", ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0O0", ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(1.0, StringToDouble(&uc, "0o1", ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(7.0, StringToDouble(&uc, "0o7", ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(8.0, StringToDouble(&uc, "0o10",
+ ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(63.0, StringToDouble(&uc, "0o77",
+ ALLOW_OCTAL | ALLOW_IMPLICIT_OCTAL));
+
+ CHECK_EQ(0.0, StringToDouble(&uc, "0o0", ALLOW_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0O0", ALLOW_OCTAL));
+ CHECK_EQ(1.0, StringToDouble(&uc, "0o1", ALLOW_OCTAL));
+ CHECK_EQ(7.0, StringToDouble(&uc, "0o7", ALLOW_OCTAL));
+ CHECK_EQ(8.0, StringToDouble(&uc, "0o10", ALLOW_OCTAL));
+ CHECK_EQ(63.0, StringToDouble(&uc, "0o77", ALLOW_OCTAL));
+}
+
+
+TEST(ImplicitOctal) {
+ UnicodeCache uc;
+ CHECK_EQ(0.0, StringToDouble(&uc, "0", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "00", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(1.0, StringToDouble(&uc, "01", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(7.0, StringToDouble(&uc, "07", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(8.0, StringToDouble(&uc, "010", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(63.0, StringToDouble(&uc, "077", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
CHECK_EQ(0.0, StringToDouble(&uc, "0", ALLOW_HEX));
CHECK_EQ(0.0, StringToDouble(&uc, "00", ALLOW_HEX));
@@ -71,26 +93,53 @@ TEST(Octal) {
const double x = 010000000000; // Power of 2, no rounding errors.
CHECK_EQ(x * x * x * x * x, StringToDouble(&uc, "01" "0000000000" "0000000000"
- "0000000000" "0000000000" "0000000000", ALLOW_OCTALS));
+ "0000000000" "0000000000" "0000000000", ALLOW_IMPLICIT_OCTAL));
}
-TEST(MalformedOctal) {
+TEST(Binary) {
UnicodeCache uc;
- CHECK_EQ(8.0, StringToDouble(&uc, "08", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(81.0, StringToDouble(&uc, "081", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(78.0, StringToDouble(&uc, "078", ALLOW_HEX | ALLOW_OCTALS));
-
- CHECK(std::isnan(StringToDouble(&uc, "07.7", ALLOW_HEX | ALLOW_OCTALS)));
- CHECK(std::isnan(StringToDouble(&uc, "07.8", ALLOW_HEX | ALLOW_OCTALS)));
- CHECK(std::isnan(StringToDouble(&uc, "07e8", ALLOW_HEX | ALLOW_OCTALS)));
- CHECK(std::isnan(StringToDouble(&uc, "07e7", ALLOW_HEX | ALLOW_OCTALS)));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0b0",
+ ALLOW_BINARY | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0B0",
+ ALLOW_BINARY | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(1.0, StringToDouble(&uc, "0b1",
+ ALLOW_BINARY | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(2.0, StringToDouble(&uc, "0b10",
+ ALLOW_BINARY | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(3.0, StringToDouble(&uc, "0b11",
+ ALLOW_BINARY | ALLOW_IMPLICIT_OCTAL));
+
+ CHECK_EQ(0.0, StringToDouble(&uc, "0b0", ALLOW_BINARY));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0B0", ALLOW_BINARY));
+ CHECK_EQ(1.0, StringToDouble(&uc, "0b1", ALLOW_BINARY));
+ CHECK_EQ(2.0, StringToDouble(&uc, "0b10", ALLOW_BINARY));
+ CHECK_EQ(3.0, StringToDouble(&uc, "0b11", ALLOW_BINARY));
+}
- CHECK_EQ(8.7, StringToDouble(&uc, "08.7", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(8e7, StringToDouble(&uc, "08e7", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.001, StringToDouble(&uc, "0.001", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.713, StringToDouble(&uc, "0.713", ALLOW_HEX | ALLOW_OCTALS));
+TEST(MalformedOctal) {
+ UnicodeCache uc;
+ CHECK_EQ(8.0, StringToDouble(&uc, "08", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(81.0, StringToDouble(&uc, "081", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(78.0, StringToDouble(&uc, "078", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+
+ CHECK(std::isnan(StringToDouble(&uc, "07.7",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL)));
+ CHECK(std::isnan(StringToDouble(&uc, "07.8",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL)));
+ CHECK(std::isnan(StringToDouble(&uc, "07e8",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL)));
+ CHECK(std::isnan(StringToDouble(&uc, "07e7",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL)));
+
+ CHECK_EQ(8.7, StringToDouble(&uc, "08.7", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(8e7, StringToDouble(&uc, "08e7", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+
+ CHECK_EQ(0.001, StringToDouble(&uc, "0.001",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.713, StringToDouble(&uc, "0.713",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
CHECK_EQ(8.0, StringToDouble(&uc, "08", ALLOW_HEX));
CHECK_EQ(81.0, StringToDouble(&uc, "081", ALLOW_HEX));
@@ -112,12 +161,12 @@ TEST(MalformedOctal) {
TEST(TrailingJunk) {
UnicodeCache uc;
CHECK_EQ(8.0, StringToDouble(&uc, "8q", ALLOW_TRAILING_JUNK));
- CHECK_EQ(63.0,
- StringToDouble(&uc, "077qqq", ALLOW_OCTALS | ALLOW_TRAILING_JUNK));
- CHECK_EQ(10.0,
- StringToDouble(&uc, "10e", ALLOW_OCTALS | ALLOW_TRAILING_JUNK));
- CHECK_EQ(10.0,
- StringToDouble(&uc, "10e-", ALLOW_OCTALS | ALLOW_TRAILING_JUNK));
+ CHECK_EQ(63.0, StringToDouble(&uc, "077qqq",
+ ALLOW_IMPLICIT_OCTAL | ALLOW_TRAILING_JUNK));
+ CHECK_EQ(10.0, StringToDouble(&uc, "10e",
+ ALLOW_IMPLICIT_OCTAL | ALLOW_TRAILING_JUNK));
+ CHECK_EQ(10.0, StringToDouble(&uc, "10e-",
+ ALLOW_IMPLICIT_OCTAL | ALLOW_TRAILING_JUNK));
}
@@ -144,12 +193,14 @@ TEST(IntegerStrLiteral) {
CHECK(std::isnan(StringToDouble(&uc, " - 1 ", NO_FLAGS)));
CHECK(std::isnan(StringToDouble(&uc, " + 1 ", NO_FLAGS)));
- CHECK_EQ(0.0, StringToDouble(&uc, "0e0", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.0, StringToDouble(&uc, "0e1", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.0, StringToDouble(&uc, "0e-1", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.0, StringToDouble(&uc, "0e-100000", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.0, StringToDouble(&uc, "0e+100000", ALLOW_HEX | ALLOW_OCTALS));
- CHECK_EQ(0.0, StringToDouble(&uc, "0.", ALLOW_HEX | ALLOW_OCTALS));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0e0", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0e1", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0e-1", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0e-100000",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0e+100000",
+ ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
+ CHECK_EQ(0.0, StringToDouble(&uc, "0.", ALLOW_HEX | ALLOW_IMPLICIT_OCTAL));
}
« no previous file with comments | « src/scanner.cc ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698