Index: tests/standalone/io/system_encoding_test.dart |
diff --git a/tests/standalone/io/system_encoding_test.dart b/tests/standalone/io/system_encoding_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..db9e788be02e7376ca3adc11c8d93abd8a617c11 |
--- /dev/null |
+++ b/tests/standalone/io/system_encoding_test.dart |
@@ -0,0 +1,50 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
Lasse Reichstein Nielsen
2015/06/23 13:08:51
2015?
Søren Gjesse
2015/06/24 07:58:26
Done.
|
+// 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:io'; |
+import 'dart:convert'; |
+ |
+import "package:expect/expect.dart"; |
+ |
+void testEncodeDecode(String str) { |
Lasse Reichstein Nielsen
2015/06/23 13:08:50
Document that this only works for ASCII.
Søren Gjesse
2015/06/24 07:58:26
Done.
|
+ Expect.equals( |
+ SYSTEM_ENCODING.decoder.convert( |
+ SYSTEM_ENCODING.encoder.convert(str)), str); |
+} |
+ |
+void testDecodeEncode(List<int> bytes) { |
Lasse Reichstein Nielsen
2015/06/23 13:08:50
... and this should work for all bytes.
Søren Gjesse
2015/06/24 07:58:26
No, only 0..127, as on all platforms but Windows t
|
+ Expect.listEquals( |
+ SYSTEM_ENCODING.encoder.convert( |
+ SYSTEM_ENCODING.decoder.convert(bytes)), bytes); |
+} |
+ |
+void test(List<int> bytes) { |
+ var str = new String.fromCharCodes(bytes); |
+ Expect.equals(SYSTEM_ENCODING.decoder.convert(bytes), str); |
+ Expect.listEquals(SYSTEM_ENCODING.encoder.convert(str), bytes); |
+ testDecodeEncode(bytes); |
+ testEncodeDecode(str); |
+} |
+ |
+main() { |
+ test([65, 66, 67]); |
+ test([65, 0, 67]); |
+ test([0, 65, 0, 67, 0]); |
+ test([0, 0, 0]); |
+ test(new Iterable.generate(128, (i) => i).toList()); |
+ testEncodeDecode('\u00c6\u00d8\u00c5'); |
+ if (Platform.isWindows) { |
+ // On Windows the default Windows code page cannot encode these |
+ // Unicode characters and the ? character is used. |
+ Expect.listEquals( |
+ SYSTEM_ENCODING.encoder.convert('\u1234\u5678\u9abc'), |
+ '???'.codeUnits); |
+ } else { |
+ // On all systems except for Windows UTF-8 is used as the system |
+ // encoding. |
+ Expect.listEquals( |
+ SYSTEM_ENCODING.encoder.convert('\u1234\u5678\u9abc'), |
Lasse Reichstein Nielsen
2015/06/23 13:08:51
.encoder.convert(...) -> .encode(...)
Simlar abov
Søren Gjesse
2015/06/24 07:58:26
Done.
|
+ UTF8.encoder.convert('\u1234\u5678\u9abc')); |
+ } |
+} |