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

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

Issue 19627004: Add echo and line modes to Stdin. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add missing files. Created 7 years, 4 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 | Annotate | Revision Log
« runtime/bin/stdin_linux.cc ('K') | « sdk/lib/io/stdio.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
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 import "package:path/path.dart"; 5 import "package:path/path.dart";
6 import "dart:io"; 6 import "dart:io";
7 import "dart:json"; 7 import "dart:json";
8 8
9 void test(String line, List<String> expected) { 9 void testReadByte() {
10 var script = join(dirname(Platform.script), "stdin_sync_script.dart"); 10 void test(String line, List<String> expected) {
11 Process.start(Platform.executable, 11 var script = join(dirname(Platform.script), "stdin_sync_script.dart");
12 [script]..addAll( 12 Process.start(Platform.executable,
13 expected.map(stringify))).then((process) { 13 [script]..addAll(
14 process.stdin.write(line); 14 expected.map(stringify))).then((process) {
15 process.stdin.close(); 15 process.stdin.write(line);
16 process.stderr 16 process.stdin.close();
17 .transform(new StringDecoder()) 17 process.stderr
18 .transform(new LineTransformer()) 18 .transform(new StringDecoder())
19 .fold(new StringBuffer(), (b, d) => b..write(d)) 19 .transform(new LineTransformer())
20 .then((data) { 20 .fold(new StringBuffer(), (b, d) => b..write(d))
21 if (data.toString() != '') throw "Bad output: '$data'"; 21 .then((data) {
22 }); 22 if (data.toString() != '') throw "Bad output: '$data'";
23 process.stdout 23 });
24 .transform(new StringDecoder()) 24 process.stdout
25 .transform(new LineTransformer()) 25 .transform(new StringDecoder())
26 .fold(new StringBuffer(), (b, d) => b..write(d)) 26 .transform(new LineTransformer())
27 .then((data) { 27 .fold(new StringBuffer(), (b, d) => b..write(d))
28 if (data.toString() != 'true') throw "Bad output: '$data'"; 28 .then((data) {
29 }); 29 if (data.toString() != 'true') throw "Bad output: '$data'";
30 }); 30 });
31 } 31 });
32 }
32 33
33 void main() {
34 test("hej\x01\x00\x0d\x0a\x0a4\x0a", ['hej\x01\x00', '', '4']); 34 test("hej\x01\x00\x0d\x0a\x0a4\x0a", ['hej\x01\x00', '', '4']);
35 35
36 test("hej\u0187", ['hej\u0187']); 36 test("hej\u0187", ['hej\u0187']);
37 37
38 test("hej\rhej\nhej\r", ['hej\rhej', 'hej\r']); 38 test("hej\rhej\nhej\r", ['hej\rhej', 'hej\r']);
39 39
40 if (Platform.isWindows) { 40 if (Platform.isWindows) {
41 // Windows trim one of the \r. 41 // Windows trim one of the \r.
42 test("hej\r\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']); 42 test("hej\r\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']);
43 } else { 43 } else {
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 46
47 test("hej", ['hej']); 47 test("hej", ['hej']);
48 } 48 }
49
50 void testEchoMode() {
51 stdin.echoMode = false;
52 var line;
53 while ((line = stdin.readLineSync()) != null) {
54 print("You typed: $line");
55 }
56 }
57
58 void testRawMode() {
59 stdin.lineMode = false;
60 var char;
61 while ((char = stdin.readByteSync()) != -1) {
62 print("You typed: $char");
63 }
64 }
65
66
67 void main() {
68 testReadByte();
69
70 // testEchoMode and testRawMode is an developer-interactive test, thus not
71 // enabled.
72 //testEchoMode();
73 //testRawMode();
74 }
OLDNEW
« runtime/bin/stdin_linux.cc ('K') | « sdk/lib/io/stdio.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698