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

Unified Diff: test/codegen/lib/convert/codec1_test.dart

Issue 1965563003: Update dart:convert and dart:core Uri. (Closed) Base URL: https://github.com/dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
Index: test/codegen/lib/convert/codec1_test.dart
diff --git a/test/codegen/lib/convert/codec1_test.dart b/test/codegen/lib/convert/codec1_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..5b5d9b3bf08d1621d8644a45307c878a46bf7a68
--- /dev/null
+++ b/test/codegen/lib/convert/codec1_test.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:convert';
+
+import 'package:expect/expect.dart';
+
+class MyCodec extends Codec<int, String> {
+ const MyCodec();
+
+ final Converter<int, String> encoder = const IntStringConverter();
+ final Converter<String, int> decoder = const StringIntConverter();
+}
+
+class IntStringConverter extends Converter<int, String> {
+ const IntStringConverter();
+
+ String convert(int i) => i.toString();
+}
+
+class StringIntConverter extends Converter<String, int> {
+ const StringIntConverter();
+
+ int convert(String str) => int.parse(str);
+}
+
+class MyCodec2 extends Codec<int, String> {
+ const MyCodec2();
+
+ Converter<int, String> get encoder => new IntStringConverter2();
+ Converter<String, int> get decoder => new StringIntConverter2();
+}
+
+class IntStringConverter2 extends Converter<int, String> {
+ String convert(int i) => (i + 99).toString();
+}
+
+class StringIntConverter2 extends Converter<String, int> {
+ int convert(String str) => int.parse(str) + 400;
+}
+
+const TEST_CODEC = const MyCodec();
+const TEST_CODEC2 = const MyCodec2();
+
+main() {
+ Expect.equals("0", TEST_CODEC.encode(0));
+ Expect.equals(5, TEST_CODEC.decode("5"));
+ Expect.equals(3, TEST_CODEC.decode(TEST_CODEC.encode(3)));
+
+ Expect.equals("99", TEST_CODEC2.encode(0));
+ Expect.equals(405, TEST_CODEC2.decode("5"));
+ Expect.equals(499, TEST_CODEC2.decode(TEST_CODEC2.encode(0)));
+
+ var inverted, fused;
+ inverted = TEST_CODEC.inverted;
+ fused = TEST_CODEC.fuse(inverted);
+ Expect.equals(499, fused.encode(499));
+ Expect.equals(499, fused.decode(499));
+
+ fused = inverted.fuse(TEST_CODEC);
+ Expect.equals("499", fused.encode("499"));
+ Expect.equals("499", fused.decode("499"));
+
+ inverted = TEST_CODEC2.inverted;
+ fused = TEST_CODEC2.fuse(inverted);
+ Expect.equals(499, fused.encode(0));
+ Expect.equals(499, fused.decode(0));
+
+ fused = TEST_CODEC.fuse(inverted);
+ Expect.equals(405, fused.encode(5));
+ Expect.equals(101, fused.decode(2));
+}

Powered by Google App Engine
This is Rietveld 408576698