Chromium Code Reviews| Index: tests/lib/convert/html_escape_test.dart |
| diff --git a/tests/lib/convert/html_escape_test.dart b/tests/lib/convert/html_escape_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5f5f20c1a3e2db55990e1b2f86b334bb1516fe28 |
| --- /dev/null |
| +++ b/tests/lib/convert/html_escape_test.dart |
| @@ -0,0 +1,60 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import "package:expect/expect.dart"; |
| +import 'dart:async'; |
| +import 'dart:convert'; |
| + |
| +const _TEST_INPUT = 'A <test> of \u00A0 "double" & \'single\' values'; |
| + |
| +const _OUTPUT_UNKNOWN = 'A <test> of "double" & ' |
| + ''single' values'; |
| + |
| +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.
|
| + |
| +const _OUTPUT_ELEMENT = 'A <test> of "double" & \'single\' values'; |
|
floitsch
2013/08/30 15:52:00
80 chars.
kevmoo-old
2013/09/05 19:14:20
Done.
|
| + |
| +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.
|
| + testMode(HTML_ESCAPE, _OUTPUT_UNKNOWN); |
| + testMode(const HtmlEscape(), _OUTPUT_UNKNOWN); |
| + testMode(const HtmlEscape(HtmlEscapeMode.UNKNOWN), _OUTPUT_UNKNOWN); |
| + testMode(const HtmlEscape(HtmlEscapeMode.ATTRIBUTE), _OUTPUT_ATTRIBUTE); |
| + testMode(const HtmlEscape(HtmlEscapeMode.ELEMENT), _OUTPUT_ELEMENT); |
| +} |
| + |
| +void testMode(HtmlEscape escape, String expected) { |
| + var output = escape.convert(_TEST_INPUT); |
| + Expect.equals(expected, output); |
| + |
| + var controller = new StreamController(sync: true); |
| + |
| + var stream = controller.stream |
| + .transform(escape); |
| + |
| + var done = false; |
| + int count = 0; |
| + |
| + void stringData(value) { |
| + Expect.equals(expected, value); |
| + count++; |
| + } |
| + |
| + void streamClosed() { |
| + done = true; |
| + } |
| + |
| + stream.listen( |
| + stringData, |
| + onDone: streamClosed); |
| + |
| + |
| + for(var i = 0; i < _COUNT; i++) { |
| + controller.add(_TEST_INPUT); |
| + } |
| + controller.close(); |
| + Expect.isTrue(done); |
| + Expect.equals(_COUNT, count); |
| +} |
| + |
| +const _COUNT = 3; |