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

Side by Side Diff: tests/standalone/io/system_encoding_test.dart

Issue 1194883002: Improve the encoding/decoding to/from system encoding on Windows (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Addressed review comments from lrn@ Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « sdk/lib/io/string_transformer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 // This only works reliabily for "ASCII" cross platform as that is the only
11 // well known part of the default Windows code page.
12 void testEncodeDecode(String str) {
13 Expect.equals(
14 SYSTEM_ENCODING.decode(SYSTEM_ENCODING.encode(str)), str);
15 }
16
17 // This only works reliabily for "ASCII" cross platform as that is the only
18 // common set of bytes between UTF-8 Windows code pages that convert back
19 // and forth.
20 void testDecodeEncode(List<int> bytes) {
21 Expect.listEquals(
22 SYSTEM_ENCODING.encode(SYSTEM_ENCODING.decode(bytes)), bytes);
23 }
24
25 void test(List<int> bytes) {
26 var str = new String.fromCharCodes(bytes);
27 Expect.equals(SYSTEM_ENCODING.decode(bytes), str);
28 Expect.listEquals(SYSTEM_ENCODING.encode(str), bytes);
29 testDecodeEncode(bytes);
30 testEncodeDecode(str);
31 }
32
33 main() {
34 test([65, 66, 67]);
35 test([65, 0, 67]);
36 test([0, 65, 0, 67, 0]);
37 test([0, 0, 0]);
38 test(new Iterable.generate(128, (i) => i).toList());
39 // This might break on some Windows systems.
40 testEncodeDecode('\u00c6\u00d8\u00c5');
41 if (Platform.isWindows) {
42 // On Windows the default Windows code page cannot encode these
43 // Unicode characters and the ? character is used.
44 Expect.listEquals(
45 SYSTEM_ENCODING.encode('\u1234\u5678\u9abc'),
46 '???'.codeUnits);
47 } else {
48 // On all systems except for Windows UTF-8 is used as the system
49 // encoding.
50 Expect.listEquals(
51 SYSTEM_ENCODING.encode('\u1234\u5678\u9abc'),
52 UTF8.encode('\u1234\u5678\u9abc'));
53 }
54 }
OLDNEW
« no previous file with comments | « sdk/lib/io/string_transformer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698