| OLD | NEW |
| 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 test("hej\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']); |
| 41 // Windows trim one of the \r. | |
| 42 test("hej\r\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']); | |
| 43 } else { | |
| 44 test("hej\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']); | |
| 45 } | |
| 46 | 41 |
| 47 test("hej", ['hej']); | 42 test("hej", ['hej']); |
| 48 } | 43 } |
| 44 |
| 45 void testEchoMode() { |
| 46 stdin.echoMode = false; |
| 47 var line; |
| 48 while ((line = stdin.readLineSync()) != null) { |
| 49 print("You typed: $line"); |
| 50 } |
| 51 } |
| 52 |
| 53 void testLineMode() { |
| 54 stdin.lineMode = false; |
| 55 var char; |
| 56 while ((char = stdin.readByteSync()) != -1) { |
| 57 print("You typed: $char"); |
| 58 } |
| 59 } |
| 60 |
| 61 |
| 62 void main() { |
| 63 testReadByte(); |
| 64 |
| 65 // testEchoMode and testLineMode is an developer-interactive test, thus not |
| 66 // enabled. |
| 67 //testEchoMode(); |
| 68 //testLineMode(); |
| 69 } |
| OLD | NEW |