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

Unified Diff: test/mjsunit/json.js

Issue 3336001: Make JSON.stringify not quote non-ASCII characters. Fix bug 855. (Closed)
Patch Set: Created 10 years, 4 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/json.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/json.js
diff --git a/test/mjsunit/json.js b/test/mjsunit/json.js
index 945b66249bff5729cad431d3a5c8eadf39e1ca9a..71acedf1f7a5dfb86a22730f366c2df921987668 100644
--- a/test/mjsunit/json.js
+++ b/test/mjsunit/json.js
@@ -317,3 +317,32 @@ TestInvalid('1); x++; (1');
// Test string conversion of argument.
var o = { toString: function() { return "42"; } };
assertEquals(42, JSON.parse(o));
+
+
+for (var i = 0; i < 65536; i++) {
+ var string = String.fromCharCode(i);
+ var encoded = JSON.stringify(string);
+ var expected = "uninitialized";
+ // Following the ES5 specification of the abstraction function Quote.
+ if (string == '"' || string == '\\') {
+ // Step 2.a
+ expected = '\\' + string;
+ } else if ("\b\t\n\r\f".indexOf(string) >= 0) {
+ // Step 2.b
+ if (string == '\b') expected = '\\b';
+ else if (string == '\t') expected = '\\t';
+ else if (string == '\n') expected = '\\n';
+ else if (string == '\f') expected = '\\f';
+ else if (string == '\r') expected = '\\r';
+ } else if (i < 32) {
+ // Step 2.c
+ if (i < 16) {
+ expected = "\\u000" + i.toString(16);
Rico 2010/09/01 14:48:20 Indention off
+ } else {
+ expected = "\\u00" + i.toString(16);
Rico 2010/09/01 14:48:20 Indention off
+ }
+ } else {
+ expected = string;
+ }
+ assertEquals('"' + expected + '"', encoded, "Codepoint " + i);
+}
« no previous file with comments | « src/json.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698