| 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 _NOOP = 'Nothing_to_escape'; | 
|  | 10 | 
|  | 11 const _TEST_INPUT = '<A <test> of \u00A0 "double" & \'single\' values>'; | 
|  | 12 | 
|  | 13 const _OUTPUT_UNKNOWN = '<A <test> of   "double" & ' | 
|  | 14   ''single' values>'; | 
|  | 15 | 
|  | 16 const _OUTPUT_ATTRIBUTE = "<A <test> of   "double" & " | 
|  | 17   "\'single\' values>"; | 
|  | 18 | 
|  | 19 const _OUTPUT_ELEMENT = '<A <test> of   "double" & ' | 
|  | 20   '\'single\' values>'; | 
|  | 21 | 
|  | 22 void _testMode(HtmlEscape escape, String input, String expected) { | 
|  | 23   _testConvert(escape, input, expected); | 
|  | 24   _testTransform(escape, input, expected); | 
|  | 25   _testChunked(escape, input, expected); | 
|  | 26 } | 
|  | 27 | 
|  | 28 void _testChunked(HtmlEscape escape, String input, String expected) { | 
|  | 29   var buffer = new StringBuffer(); | 
|  | 30 | 
|  | 31   var rootSink = new StringConversionSink.fromStringSink(buffer); | 
|  | 32   var sink = escape.startChunkedConversion(rootSink); | 
|  | 33 | 
|  | 34   sink.addSlice("1" + input + "2", 1, input.length + 1, false); | 
|  | 35   sink.close(); | 
|  | 36 | 
|  | 37   Expect.equals(expected, buffer.toString()); | 
|  | 38 } | 
|  | 39 | 
|  | 40 void _testConvert(HtmlEscape escape, String input, String expected) { | 
|  | 41   var output = escape.convert(input); | 
|  | 42   Expect.equals(expected, output); | 
|  | 43 } | 
|  | 44 | 
|  | 45 void _testTransform(HtmlEscape escape, String input, String expected) { | 
|  | 46   var controller = new StreamController(sync: true); | 
|  | 47 | 
|  | 48   var stream = controller.stream | 
|  | 49       .transform(escape); | 
|  | 50 | 
|  | 51   var done = false; | 
|  | 52   int count = 0; | 
|  | 53 | 
|  | 54   void stringData(value) { | 
|  | 55     Expect.equals(expected, value); | 
|  | 56     count++; | 
|  | 57   } | 
|  | 58 | 
|  | 59   void streamClosed() { | 
|  | 60     done = true; | 
|  | 61   } | 
|  | 62 | 
|  | 63   stream.listen( | 
|  | 64       stringData, | 
|  | 65       onDone: streamClosed); | 
|  | 66 | 
|  | 67 | 
|  | 68   for(var i = 0; i < _COUNT; i++) { | 
|  | 69     controller.add(input); | 
|  | 70   } | 
|  | 71   controller.close(); | 
|  | 72   Expect.isTrue(done); | 
|  | 73   Expect.equals(_COUNT, count); | 
|  | 74 } | 
|  | 75 | 
|  | 76 const _COUNT = 3; | 
|  | 77 | 
|  | 78 void main() { | 
|  | 79   _testMode(HTML_ESCAPE, _TEST_INPUT, _OUTPUT_UNKNOWN); | 
|  | 80   _testMode(const HtmlEscape(), _TEST_INPUT, _OUTPUT_UNKNOWN); | 
|  | 81   _testMode(const HtmlEscape(HtmlEscapeMode.UNKNOWN), _TEST_INPUT, _OUTPUT_UNKNO
    WN); | 
|  | 82   _testMode(const HtmlEscape(HtmlEscapeMode.ATTRIBUTE), _TEST_INPUT, _OUTPUT_ATT
    RIBUTE); | 
|  | 83   _testMode(const HtmlEscape(HtmlEscapeMode.ELEMENT), _TEST_INPUT, _OUTPUT_ELEME
    NT); | 
|  | 84   _testMode(HTML_ESCAPE, _NOOP, _NOOP); | 
|  | 85 } | 
| OLD | NEW | 
|---|