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

Unified Diff: tests/json/json_test.dart

Issue 25548010: Make JSON encoder take extra function argument to use instead of toJson calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename convert function to "toEncodable". Created 7 years, 2 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 | « sdk/lib/json/json.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/json/json_test.dart
diff --git a/tests/json/json_test.dart b/tests/json/json_test.dart
index 891fef3ee79b1ff90ba096299fd30a988fefdbcd..3f6235782711b43ded0b73427686ad59e7ddc109 100644
--- a/tests/json/json_test.dart
+++ b/tests/json/json_test.dart
@@ -136,6 +136,18 @@ main() {
*/
expect(() => JSON.encode(new TestClass()), throws);
});
+
+ test('stringify custom converter', () {
+ List l = [const C(0), const C(1)];
+ expect(JSON.encode(l, (x) => "C(${x.id})"), equals("[C(0),C(1)]"));
+ expect(JSON.encode(l), equals("[C/0,C/1]"));
+ });
+}
+
+class C {
+ final int id;
+ const C(this.id);
+ toJson() => "C/$id";
}
class TestClass {
@@ -158,5 +170,3 @@ class ToJson {
validateRoundTrip(expected) {
expect(JSON.decode(JSON.encode(expected)), equals(expected));
}
-
-
« no previous file with comments | « sdk/lib/json/json.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698