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

Unified Diff: test/mjsunit/es6/unicode-escapes.js

Issue 706263002: Implement ES6 unicode escapes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 1 month 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 | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/es6/unicode-escapes.js
diff --git a/test/mjsunit/es6/unicode-escapes.js b/test/mjsunit/es6/unicode-escapes.js
new file mode 100644
index 0000000000000000000000000000000000000000..31f7f4c08093180296d3c5c4f6d109940ee2e3c6
--- /dev/null
+++ b/test/mjsunit/es6/unicode-escapes.js
@@ -0,0 +1,80 @@
+// Copyright 2014 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.
+
+// ES6 extends the \uxxxx escape and also allows \u{xxxx}.
+
+// Unicode escapes in variable names.
+
+(function TestVariableNames1() {
+ var foobar = 1;
+ assertEquals(foob\u0061r, 1);
+ assertEquals(foob\u{0061}r, 1);
+ assertEquals(foob\u{61}r, 1);
+ assertEquals(foob\u{0000000061}r, 1);
+})();
+
+(function TestVariableNames2() {
+ var foobar = 1;
+ assertEquals(\u0066oobar, 1);
+ assertEquals(\u{0066}oobar, 1);
+ assertEquals(\u{66}oobar, 1);
+ assertEquals(\u{0000000066}oobar, 1);
+})();
+
+// Unicode escapes in strings.
+
+(function TestStrings() {
+ var s1 = "foob\u0061r";
+ assertEquals(s1, "foobar");
+ var s2 = "foob\u{0061}r";
+ assertEquals(s2, "foobar");
+ var s3 = "foob\u{61}r";
+ assertEquals(s3, "foobar");
+ var s4 = "foob\u{0000000061}r";
+ assertEquals(s4, "foobar");
+})();
+
+
+(function TestSurrogates() {
+ // U+10E6D corresponds to the surrogate pair [U+D803, U+DE6D].
+ var s1 = "foo\u{10e6d}";
+ var s2 = "foo\u{d803}\u{de6d}";
+ assertEquals(s1, s2);
+})();
+
+// Unicode escapes in regexp body. Note that no escapes are allowed in regexp
+// flags.
+
+// FIXME: the test is not yet correct wrt the u regexp flag. The \u{xxxx} style
+// is only allowed when the flag is passed.
+
+(function TestRegexp1() {
+ var r1 = /(\u0066|\u0062)oo/;
+ assertTrue(r1.test("foo"));
+ assertTrue(r1.test("boo"));
+ assertFalse(r1.test("moo"));
+ var r2 = /(\u{0066}|\u{0062})oo/;
+ assertTrue(r2.test("foo"));
+ assertTrue(r2.test("boo"));
+ assertFalse(r2.test("moo"));
+ var r3 = /(\u{66}|\u{000062})oo/;
+ assertTrue(r3.test("foo"));
+ assertTrue(r3.test("boo"));
+ assertFalse(r3.test("moo"));
+})();
+
+(function TestRegexp2() {
+ var r1 = /[\u0062-\u0066]oo/;
+ assertTrue(r1.test("foo"));
+ assertTrue(r1.test("boo"));
+ assertFalse(r1.test("moo"));
+ var r2 = /[\u{0062}-\u{0066}]oo/;
+ assertTrue(r2.test("foo"));
+ assertTrue(r2.test("boo"));
+ assertFalse(r2.test("moo"));
+ var r3 = /[\u{62}-\u{00000066}]oo/;
+ assertTrue(r3.test("foo"));
+ assertTrue(r3.test("boo"));
+ assertFalse(r3.test("moo"));
+}());
« no previous file with comments | « test/cctest/test-parsing.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698