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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:io'; 5 import 'dart:io';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import "package:expect/expect.dart"; 8 import "package:expect/expect.dart";
9 9
10 // This only works reliabily for "ASCII" cross platform as that is the only 10 // This only works reliabily for "ASCII" cross platform as that is the only
11 // well known part of the default Windows code page. 11 // well known part of the default Windows code page.
12 void testEncodeDecode(String str) { 12 void testEncodeDecode(String str) {
13 Expect.equals( 13 Expect.equals(SYSTEM_ENCODING.decode(SYSTEM_ENCODING.encode(str)), str);
14 SYSTEM_ENCODING.decode(SYSTEM_ENCODING.encode(str)), str);
15 } 14 }
16 15
17 // This only works reliabily for "ASCII" cross platform as that is the only 16 // 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 17 // common set of bytes between UTF-8 Windows code pages that convert back
19 // and forth. 18 // and forth.
20 void testDecodeEncode(List<int> bytes) { 19 void testDecodeEncode(List<int> bytes) {
21 Expect.listEquals( 20 Expect.listEquals(
22 SYSTEM_ENCODING.encode(SYSTEM_ENCODING.decode(bytes)), bytes); 21 SYSTEM_ENCODING.encode(SYSTEM_ENCODING.decode(bytes)), bytes);
23 } 22 }
24 23
25 void test(List<int> bytes) { 24 void test(List<int> bytes) {
26 var str = new String.fromCharCodes(bytes); 25 var str = new String.fromCharCodes(bytes);
27 Expect.equals(SYSTEM_ENCODING.decode(bytes), str); 26 Expect.equals(SYSTEM_ENCODING.decode(bytes), str);
28 Expect.listEquals(SYSTEM_ENCODING.encode(str), bytes); 27 Expect.listEquals(SYSTEM_ENCODING.encode(str), bytes);
29 testDecodeEncode(bytes); 28 testDecodeEncode(bytes);
30 testEncodeDecode(str); 29 testEncodeDecode(str);
31 } 30 }
32 31
33 main() { 32 main() {
34 test([65, 66, 67]); 33 test([65, 66, 67]);
35 test([65, 0, 67]); 34 test([65, 0, 67]);
36 test([0, 65, 0, 67, 0]); 35 test([0, 65, 0, 67, 0]);
37 test([0, 0, 0]); 36 test([0, 0, 0]);
38 test(new Iterable.generate(128, (i) => i).toList()); 37 test(new Iterable.generate(128, (i) => i).toList());
39 if (Platform.isWindows) { 38 if (Platform.isWindows) {
40 // On Windows the default Windows code page cannot encode these 39 // On Windows the default Windows code page cannot encode these
41 // Unicode characters and the ? character is used. 40 // Unicode characters and the ? character is used.
42 Expect.listEquals( 41 Expect.listEquals(
43 SYSTEM_ENCODING.encode('\u1234\u5678\u9abc'), 42 SYSTEM_ENCODING.encode('\u1234\u5678\u9abc'), '???'.codeUnits);
44 '???'.codeUnits);
45 } else { 43 } else {
46 // On all systems except for Windows UTF-8 is used as the system 44 // On all systems except for Windows UTF-8 is used as the system
47 // encoding. 45 // encoding.
48 Expect.listEquals( 46 Expect.listEquals(SYSTEM_ENCODING.encode('\u1234\u5678\u9abc'),
49 SYSTEM_ENCODING.encode('\u1234\u5678\u9abc'),
50 UTF8.encode('\u1234\u5678\u9abc')); 47 UTF8.encode('\u1234\u5678\u9abc'));
51 } 48 }
52 } 49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698