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 "dart:convert"; | 5 import "dart:convert"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 | 7 |
8 import "package:path/path.dart"; | 8 import "package:path/path.dart"; |
| 9 import "package:expect/expect.dart"; |
9 | 10 |
10 void testReadByte() { | 11 void testReadByte() { |
11 void test(String line, List<String> expected) { | 12 void test(String line, List<String> expected) { |
12 var script = Platform.script.resolve("stdin_sync_script.dart").toFilePath(); | 13 var script = Platform.script.resolve("stdin_sync_script.dart").toFilePath(); |
13 Process.start(Platform.executable, | 14 Process.start(Platform.executable, |
14 ["--checked", script]..addAll( | 15 ["--checked", script]..addAll( |
15 expected.map(JSON.encode))).then((process) { | 16 expected.map(JSON.encode))).then((process) { |
16 process.stdin.write(line); | 17 process.stdin.write(line); |
17 process.stdin.close(); | 18 process.stdin.close(); |
18 process.stderr | 19 process.stderr |
(...skipping 18 matching lines...) Expand all Loading... |
37 test("hej\u0187", ['hej\u0187']); | 38 test("hej\u0187", ['hej\u0187']); |
38 | 39 |
39 test("hej\rhej\nhej\r", ['hej\rhej', 'hej\r']); | 40 test("hej\rhej\nhej\r", ['hej\rhej', 'hej\r']); |
40 | 41 |
41 test("hej\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']); | 42 test("hej\r\r\nhej\r\nhej\r", ['hej\r', 'hej', 'hej\r']); |
42 | 43 |
43 test("hej", ['hej']); | 44 test("hej", ['hej']); |
44 } | 45 } |
45 | 46 |
46 void testEchoMode() { | 47 void testEchoMode() { |
| 48 stdin.echoMode = true; |
| 49 Expect.isTrue(stdin.echoMode); |
47 stdin.echoMode = false; | 50 stdin.echoMode = false; |
| 51 Expect.isFalse(stdin.echoMode); |
48 var line; | 52 var line; |
49 while ((line = stdin.readLineSync()) != null) { | 53 while ((line = stdin.readLineSync()) != null) { |
50 print("You typed: $line"); | 54 print("You typed: $line"); |
51 } | 55 } |
52 } | 56 } |
53 | 57 |
54 void testLineMode() { | 58 void testLineMode() { |
| 59 stdin.lineMode = true; |
| 60 Expect.isTrue(stdin.lineMode); |
55 stdin.lineMode = false; | 61 stdin.lineMode = false; |
| 62 Expect.isFalse(stdin.lineMode); |
56 var char; | 63 var char; |
57 while ((char = stdin.readByteSync()) != -1) { | 64 while ((char = stdin.readByteSync()) != -1) { |
58 print("You typed: $char"); | 65 print("You typed: $char"); |
59 } | 66 } |
60 } | 67 } |
61 | 68 |
62 | 69 |
63 void main() { | 70 void main() { |
64 testReadByte(); | 71 testReadByte(); |
65 | 72 |
66 // testEchoMode and testLineMode is an developer-interactive test, thus not | 73 // testEchoMode and testLineMode is an developer-interactive test, thus not |
67 // enabled. | 74 // enabled. |
68 //testEchoMode(); | 75 //testEchoMode(); |
69 //testLineMode(); | 76 //testLineMode(); |
70 } | 77 } |
OLD | NEW |