Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:io'; | |
| 6 import 'dart:convert'; | |
| 7 | |
| 8 import "package:expect/expect.dart"; | |
| 9 | |
| 10 testEncodeDecode(str) { | |
| 11 Expect.equals( | |
| 12 SYSTEM_ENCODING.decoder.convert( | |
| 13 SYSTEM_ENCODING.encoder.convert(str)), str); | |
| 14 } | |
| 15 | |
| 16 testDecodeEncode(bytes) { | |
| 17 Expect.listEquals( | |
| 18 SYSTEM_ENCODING.encoder.convert( | |
| 19 SYSTEM_ENCODING.decoder.convert(bytes)), bytes); | |
| 20 } | |
| 21 | |
| 22 test(bytes) { | |
|
kustermann
2015/06/22 11:11:21
Please add types to the parameters.
Søren Gjesse
2015/06/23 11:17:59
Done.
| |
| 23 var str = new String.fromCharCodes(bytes); | |
| 24 Expect.equals(SYSTEM_ENCODING.decoder.convert(bytes), str); | |
| 25 Expect.listEquals(SYSTEM_ENCODING.encoder.convert(str), bytes); | |
| 26 testDecodeEncode(bytes); | |
| 27 testEncodeDecode(str); | |
| 28 } | |
| 29 | |
| 30 main() { | |
| 31 test([65, 66, 67]); | |
| 32 test([65, 0, 67]); | |
| 33 test([0, 65, 0, 67, 0]); | |
| 34 test([0, 0, 0]); | |
| 35 test(new Iterable.generate(128, (i) => i).toList()); | |
| 36 testEncodeDecode('\u00c6\u00d8\u00c5'); | |
| 37 if (Platform.isWindows) { | |
| 38 Expect.listEquals( | |
| 39 SYSTEM_ENCODING.encoder.convert('\u1234\u5678\u9abc'), | |
| 40 '???'.codeUnits); | |
|
kustermann
2015/06/22 11:11:21
Could you add a comment here to explain the differ
Lasse Reichstein Nielsen
2015/06/22 12:08:34
WHat kind of silly encoding is that? :)
Søren Gjesse
2015/06/23 11:17:59
That is what you get!
Søren Gjesse
2015/06/23 11:17:59
Done.
| |
| 41 } else { | |
|
Lasse Reichstein Nielsen
2015/06/22 12:08:34
So all non-windows systems use UTF-8? So far. :)
Søren Gjesse
2015/06/23 11:17:59
Yes, added comment.
| |
| 42 Expect.listEquals( | |
| 43 SYSTEM_ENCODING.encoder.convert('\u1234\u5678\u9abc'), | |
| 44 UTF8.encoder.convert('\u1234\u5678\u9abc')); | |
| 45 } | |
| 46 } | |
| OLD | NEW |