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

Side by Side Diff: tests/standalone/io/stdin_sync_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) 2013, the Dart project authors. Please see the AUTHORS file 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 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 // OtherResources=stdin_sync_script.dart 5 // OtherResources=stdin_sync_script.dart
6 6
7 import "dart:convert"; 7 import "dart:convert";
8 import "dart:io"; 8 import "dart:io";
9 9
10 import "package:path/path.dart"; 10 import "package:path/path.dart";
11 import "package:expect/expect.dart"; 11 import "package:expect/expect.dart";
12 12
13 void testReadByte() { 13 void testReadByte() {
14 void test(String line, List<String> expected) { 14 void test(String line, List<String> expected) {
15 var script = Platform.script.resolve("stdin_sync_script.dart").toFilePath(); 15 var script = Platform.script.resolve("stdin_sync_script.dart").toFilePath();
16 Process.start(Platform.executable, 16 Process
17 [script]..addAll( 17 .start(Platform.executable, [script]..addAll(expected.map(JSON.encode)))
18 expected.map(JSON.encode))).then((process) { 18 .then((process) {
19 process.stdin.write(line); 19 process.stdin.write(line);
20 process.stdin.flush().then((_) => process.stdin.close()); 20 process.stdin.flush().then((_) => process.stdin.close());
21 process.stderr 21 process.stderr
22 .transform(UTF8.decoder) 22 .transform(UTF8.decoder)
23 .transform(new LineSplitter()) 23 .transform(new LineSplitter())
24 .fold(new StringBuffer(), (b, d) => b..write(d)) 24 .fold(new StringBuffer(), (b, d) => b..write(d))
25 .then((data) { 25 .then((data) {
26 if (data.toString() != '') throw "Bad output: '$data'"; 26 if (data.toString() != '') throw "Bad output: '$data'";
27 }); 27 });
28 process.stdout 28 process.stdout
29 .transform(UTF8.decoder) 29 .transform(UTF8.decoder)
30 .transform(new LineSplitter()) 30 .transform(new LineSplitter())
31 .fold(new StringBuffer(), (b, d) => b..write(d)) 31 .fold(new StringBuffer(), (b, d) => b..write(d))
32 .then((data) { 32 .then((data) {
33 if (data.toString() != 'true') throw "Bad output: '$data'"; 33 if (data.toString() != 'true') throw "Bad output: '$data'";
34 }); 34 });
35 }); 35 });
36 } 36 }
37 37
38 test("hej\x01\x00\x0d\x0a\x0a4\x0a", ['hej\x01\x00', '', '4']); 38 test("hej\x01\x00\x0d\x0a\x0a4\x0a", ['hej\x01\x00', '', '4']);
39 39
40 test("hej\u0187", ['hej\u0187']); 40 test("hej\u0187", ['hej\u0187']);
41 41
42 test("hej\rhej\nhej\r", ['hej\rhej', 'hej\r']); 42 test("hej\rhej\nhej\r", ['hej\rhej', 'hej\r']);
43 43
44 test("hej\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']); 44 test("hej\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']);
45 45
46 test("hej", ['hej']); 46 test("hej", ['hej']);
47 } 47 }
48 48
49
50 void testEchoMode() { 49 void testEchoMode() {
51 stdin.echoMode = true; 50 stdin.echoMode = true;
52 Expect.isTrue(stdin.echoMode); 51 Expect.isTrue(stdin.echoMode);
53 stdin.echoMode = false; 52 stdin.echoMode = false;
54 Expect.isFalse(stdin.echoMode); 53 Expect.isFalse(stdin.echoMode);
55 var line; 54 var line;
56 while ((line = stdin.readLineSync()) != null) { 55 while ((line = stdin.readLineSync()) != null) {
57 print("You typed: $line"); 56 print("You typed: $line");
58 } 57 }
59 } 58 }
60 59
61
62 void testLineMode() { 60 void testLineMode() {
63 stdin.lineMode = true; 61 stdin.lineMode = true;
64 Expect.isTrue(stdin.lineMode); 62 Expect.isTrue(stdin.lineMode);
65 stdin.lineMode = false; 63 stdin.lineMode = false;
66 Expect.isFalse(stdin.lineMode); 64 Expect.isFalse(stdin.lineMode);
67 var char; 65 var char;
68 while ((char = stdin.readByteSync()) != -1) { 66 while ((char = stdin.readByteSync()) != -1) {
69 print("You typed: $char"); 67 print("You typed: $char");
70 } 68 }
71 } 69 }
72 70
73
74 void main() { 71 void main() {
75 testReadByte(); 72 testReadByte();
76 73
77 // testEchoMode and testLineMode is developer-interactive tests, thus not 74 // testEchoMode and testLineMode is developer-interactive tests, thus not
78 // enabled. 75 // enabled.
79 //testEchoMode(); 76 //testEchoMode();
80 //testLineMode(); 77 //testLineMode();
81 } 78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698