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

Side by Side Diff: test/hex_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/byte_accumulator_sink_test.dart ('k') | test/percent_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:convert/convert.dart'; 7 import 'package:convert/convert.dart';
8 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
9 9
10 void main() { 10 void main() {
11 group("encoder", () { 11 group("encoder", () {
12 test("converts byte arrays to hex", () { 12 test("converts byte arrays to hex", () {
13 expect(hex.encode([0x1a, 0xb2, 0x3c, 0xd4]), equals("1ab23cd4")); 13 expect(hex.encode([0x1a, 0xb2, 0x3c, 0xd4]), equals("1ab23cd4"));
14 expect(hex.encode([0x00, 0x01, 0xfe, 0xff]), equals("0001feff")); 14 expect(hex.encode([0x00, 0x01, 0xfe, 0xff]), equals("0001feff"));
15 }); 15 });
16 16
17 group("with chunked conversion", () { 17 group("with chunked conversion", () {
18 test("converts byte arrays to hex", () { 18 test("converts byte arrays to hex", () {
19 var results = []; 19 var results = <String>[];
20 var controller = new StreamController(sync: true); 20 var controller = new StreamController<String>(sync: true);
21 controller.stream.listen(results.add); 21 controller.stream.listen(results.add);
22 var sink = hex.encoder.startChunkedConversion(controller.sink); 22 var sink = hex.encoder.startChunkedConversion(controller.sink);
23 23
24 sink.add([0x1a, 0xb2, 0x3c, 0xd4]); 24 sink.add([0x1a, 0xb2, 0x3c, 0xd4]);
25 expect(results, equals(["1ab23cd4"])); 25 expect(results, equals(["1ab23cd4"]));
26 26
27 sink.add([0x00, 0x01, 0xfe, 0xff]); 27 sink.add([0x00, 0x01, 0xfe, 0xff]);
28 expect(results, equals(["1ab23cd4", "0001feff"])); 28 expect(results, equals(["1ab23cd4", "0001feff"]));
29 }); 29 });
30 30
31 test("handles empty and single-byte lists", () { 31 test("handles empty and single-byte lists", () {
32 var results = []; 32 var results = <String>[];
33 var controller = new StreamController(sync: true); 33 var controller = new StreamController<String>(sync: true);
34 controller.stream.listen(results.add); 34 controller.stream.listen(results.add);
35 var sink = hex.encoder.startChunkedConversion(controller.sink); 35 var sink = hex.encoder.startChunkedConversion(controller.sink);
36 36
37 sink.add([]); 37 sink.add([]);
38 expect(results, equals([""])); 38 expect(results, equals([""]));
39 39
40 sink.add([0x00]); 40 sink.add([0x00]);
41 expect(results, equals(["", "00"])); 41 expect(results, equals(["", "00"]));
42 42
43 sink.add([]); 43 sink.add([]);
(...skipping 16 matching lines...) Expand all
60 expect(hex.decode("0001feff"), equals([0x00, 0x01, 0xfe, 0xff])); 60 expect(hex.decode("0001feff"), equals([0x00, 0x01, 0xfe, 0xff]));
61 }); 61 });
62 62
63 test("supports uppercase letters", () { 63 test("supports uppercase letters", () {
64 expect(hex.decode("0123456789ABCDEFabcdef"), equals([ 64 expect(hex.decode("0123456789ABCDEFabcdef"), equals([
65 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef 65 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xab, 0xcd, 0xef
66 ])); 66 ]));
67 }); 67 });
68 68
69 group("with chunked conversion", () { 69 group("with chunked conversion", () {
70 var results; 70 List<List<int>> results;
71 var sink; 71 var sink;
72 setUp(() { 72 setUp(() {
73 results = []; 73 results = [];
74 var controller = new StreamController(sync: true); 74 var controller = new StreamController<List<int>>(sync: true);
75 controller.stream.listen(results.add); 75 controller.stream.listen(results.add);
76 sink = hex.decoder.startChunkedConversion(controller.sink); 76 sink = hex.decoder.startChunkedConversion(controller.sink);
77 }); 77 });
78 78
79 test("converts hex to byte arrays", () { 79 test("converts hex to byte arrays", () {
80 sink.add("1ab23cd4"); 80 sink.add("1ab23cd4");
81 expect(results, equals([[0x1a, 0xb2, 0x3c, 0xd4]])); 81 expect(results, equals([[0x1a, 0xb2, 0x3c, 0xd4]]));
82 82
83 sink.add("0001feff"); 83 sink.add("0001feff");
84 expect(results, 84 expect(results,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 expect(() => sink.add(char), throwsFormatException); 144 expect(() => sink.add(char), throwsFormatException);
145 }); 145 });
146 } 146 }
147 }); 147 });
148 148
149 test("rejects odd length detected in convert()", () { 149 test("rejects odd length detected in convert()", () {
150 expect(() => hex.decode("1ab23cd"), throwsFormatException); 150 expect(() => hex.decode("1ab23cd"), throwsFormatException);
151 }); 151 });
152 }); 152 });
153 } 153 }
OLDNEW
« no previous file with comments | « test/byte_accumulator_sink_test.dart ('k') | test/percent_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698