Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Side by Side Diff: test/percent_test.dart

Issue 1912273003: Make the package strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/convert.git@master
Patch Set: Code review changes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/hex_test.dart ('k') | test/string_accumulator_sink_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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:async'; 5 import 'dart:async';
6 6
7 import 'package:charcode/ascii.dart'; 7 import 'package:charcode/ascii.dart';
8 import 'package:convert/convert.dart'; 8 import 'package:convert/convert.dart';
9 import 'package:test/test.dart'; 9 import 'package:test/test.dart';
10 10
(...skipping 19 matching lines...) Expand all
30 expect(percent.encode([0x80, 0xFF]), equals("%80%FF")); 30 expect(percent.encode([0x80, 0xFF]), equals("%80%FF"));
31 }); 31 });
32 32
33 test("mixes encoded and unencoded characters", () { 33 test("mixes encoded and unencoded characters", () {
34 expect(percent.encode([$a, $plus, $b, $equal, 0x80]), 34 expect(percent.encode([$a, $plus, $b, $equal, 0x80]),
35 equals("a%2Bb%3D%80")); 35 equals("a%2Bb%3D%80"));
36 }); 36 });
37 37
38 group("with chunked conversion", () { 38 group("with chunked conversion", () {
39 test("percent-encodes byte arrays", () { 39 test("percent-encodes byte arrays", () {
40 var results = []; 40 var results = <String>[];
41 var controller = new StreamController(sync: true); 41 var controller = new StreamController<String>(sync: true);
42 controller.stream.listen(results.add); 42 controller.stream.listen(results.add);
43 var sink = percent.encoder.startChunkedConversion(controller.sink); 43 var sink = percent.encoder.startChunkedConversion(controller.sink);
44 44
45 sink.add([$a, $plus, $b, $equal, 0x80]); 45 sink.add([$a, $plus, $b, $equal, 0x80]);
46 expect(results, equals(["a%2Bb%3D%80"])); 46 expect(results, equals(["a%2Bb%3D%80"]));
47 47
48 sink.add([0x00, 0x01, 0xfe, 0xff]); 48 sink.add([0x00, 0x01, 0xfe, 0xff]);
49 expect(results, equals(["a%2Bb%3D%80", "%00%01%FE%FF"])); 49 expect(results, equals(["a%2Bb%3D%80", "%00%01%FE%FF"]));
50 }); 50 });
51 51
52 test("handles empty and single-byte lists", () { 52 test("handles empty and single-byte lists", () {
53 var results = []; 53 var results = <String>[];
54 var controller = new StreamController(sync: true); 54 var controller = new StreamController<String>(sync: true);
55 controller.stream.listen(results.add); 55 controller.stream.listen(results.add);
56 var sink = percent.encoder.startChunkedConversion(controller.sink); 56 var sink = percent.encoder.startChunkedConversion(controller.sink);
57 57
58 sink.add([]); 58 sink.add([]);
59 expect(results, equals([""])); 59 expect(results, equals([""]));
60 60
61 sink.add([0x00]); 61 sink.add([0x00]);
62 expect(results, equals(["", "%00"])); 62 expect(results, equals(["", "%00"]));
63 63
64 sink.add([]); 64 sink.add([]);
(...skipping 26 matching lines...) Expand all
91 }); 91 });
92 92
93 test("supports less aggressive encoding", () { 93 test("supports less aggressive encoding", () {
94 expect(percent.decode(" `{@[,/^}\x7F\x00"), equals([ 94 expect(percent.decode(" `{@[,/^}\x7F\x00"), equals([
95 $space, $backquote, $open_brace, $at, $open_bracket, $comma, 95 $space, $backquote, $open_brace, $at, $open_bracket, $comma,
96 $division, $caret, $close_brace, $del, $nul 96 $division, $caret, $close_brace, $del, $nul
97 ])); 97 ]));
98 }); 98 });
99 99
100 group("with chunked conversion", () { 100 group("with chunked conversion", () {
101 var results; 101 List<List<int>> results;
102 var sink; 102 var sink;
103 setUp(() { 103 setUp(() {
104 results = []; 104 results = [];
105 var controller = new StreamController(sync: true); 105 var controller = new StreamController<List<int>>(sync: true);
106 controller.stream.listen(results.add); 106 controller.stream.listen(results.add);
107 sink = percent.decoder.startChunkedConversion(controller.sink); 107 sink = percent.decoder.startChunkedConversion(controller.sink);
108 }); 108 });
109 109
110 test("converts percent to byte arrays", () { 110 test("converts percent to byte arrays", () {
111 sink.add("a%2Bb%3D%80"); 111 sink.add("a%2Bb%3D%80");
112 expect(results, equals([[$a, $plus, $b, $equal, 0x80]])); 112 expect(results, equals([[$a, $plus, $b, $equal, 0x80]]));
113 113
114 sink.add("%00%01%FE%FF"); 114 sink.add("%00%01%FE%FF");
115 expect(results, 115 expect(results,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 test("rejects dangling % detected in convert()", () { 200 test("rejects dangling % detected in convert()", () {
201 expect(() => percent.decode("ab%"), throwsFormatException); 201 expect(() => percent.decode("ab%"), throwsFormatException);
202 }); 202 });
203 203
204 test("rejects dangling digit detected in convert()", () { 204 test("rejects dangling digit detected in convert()", () {
205 expect(() => percent.decode("ab%2"), throwsFormatException); 205 expect(() => percent.decode("ab%2"), throwsFormatException);
206 }); 206 });
207 }); 207 });
208 } 208 }
OLDNEW
« no previous file with comments | « test/hex_test.dart ('k') | test/string_accumulator_sink_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698