Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "package:expect/expect.dart"; | |
| 6 import 'dart:async'; | |
| 7 import 'dart:convert'; | |
| 8 | |
| 9 const _TEST_INPUT = 'A <test> of \u00A0 "double" & \'single\' values'; | |
| 10 | |
| 11 const _OUTPUT_UNKNOWN = 'A <test> of "double" & ' | |
| 12 ''single' values'; | |
| 13 | |
| 14 const _OUTPUT_ATTRIBUTE = "A <test> of "double" & \'single\ ' values"; | |
|
floitsch
2013/08/30 15:52:00
80 chars.
kevmoo-old
2013/09/05 19:14:20
Done.
| |
| 15 | |
| 16 const _OUTPUT_ELEMENT = 'A <test> of "double" & \'single\' valu es'; | |
|
floitsch
2013/08/30 15:52:00
80 chars.
kevmoo-old
2013/09/05 19:14:20
Done.
| |
| 17 | |
| 18 void main() { | |
|
floitsch
2013/08/30 15:52:00
move main to the bottom of the file.
kevmoo-old
2013/09/05 19:14:20
Done.
| |
| 19 testMode(HTML_ESCAPE, _OUTPUT_UNKNOWN); | |
| 20 testMode(const HtmlEscape(), _OUTPUT_UNKNOWN); | |
| 21 testMode(const HtmlEscape(HtmlEscapeMode.UNKNOWN), _OUTPUT_UNKNOWN); | |
| 22 testMode(const HtmlEscape(HtmlEscapeMode.ATTRIBUTE), _OUTPUT_ATTRIBUTE); | |
| 23 testMode(const HtmlEscape(HtmlEscapeMode.ELEMENT), _OUTPUT_ELEMENT); | |
| 24 } | |
| 25 | |
| 26 void testMode(HtmlEscape escape, String expected) { | |
| 27 var output = escape.convert(_TEST_INPUT); | |
| 28 Expect.equals(expected, output); | |
| 29 | |
| 30 var controller = new StreamController(sync: true); | |
| 31 | |
| 32 var stream = controller.stream | |
| 33 .transform(escape); | |
| 34 | |
| 35 var done = false; | |
| 36 int count = 0; | |
| 37 | |
| 38 void stringData(value) { | |
| 39 Expect.equals(expected, value); | |
| 40 count++; | |
| 41 } | |
| 42 | |
| 43 void streamClosed() { | |
| 44 done = true; | |
| 45 } | |
| 46 | |
| 47 stream.listen( | |
| 48 stringData, | |
| 49 onDone: streamClosed); | |
| 50 | |
| 51 | |
| 52 for(var i = 0; i < _COUNT; i++) { | |
| 53 controller.add(_TEST_INPUT); | |
| 54 } | |
| 55 controller.close(); | |
| 56 Expect.isTrue(done); | |
| 57 Expect.equals(_COUNT, count); | |
| 58 } | |
| 59 | |
| 60 const _COUNT = 3; | |
| OLD | NEW |