Skip to content

Commit fba381d

Browse files
committed
add test cases
1 parent a2a8424 commit fba381d

16 files changed

+577
-361
lines changed

dio/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 3.0.9 2020.2.24
2+
3+
- Add test cases
4+
15
# 3.0.8 2019.12.29
26

37
- Code style improvement

dio/lib/src/transformer.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class DefaultTransformer extends Transformer {
9494
},
9595
));
9696
// let's keep references to the data chunks and concatenate them later
97-
final List<Uint8List> chunks = [];
98-
int finalSize = 0;
97+
final chunks = <Uint8List>[];
98+
var finalSize = 0;
9999
StreamSubscription subscription = stream.listen(
100100
(chunk) {
101101
finalSize += chunk.length;
@@ -130,7 +130,7 @@ class DefaultTransformer extends Transformer {
130130
}
131131
// we create a final Uint8List and copy all chunks into it
132132
final responseBytes = Uint8List(finalSize);
133-
int chunkOffset = 0;
133+
var chunkOffset = 0;
134134
for (var chunk in chunks) {
135135
responseBytes.setAll(chunkOffset, chunk);
136136
chunkOffset += chunk.length;

dio/pubspec.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: dio
22
description: A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.
3-
version: 3.0.8
3+
version: 3.0.9
44
homepage: https://github.com/flutterchina/dio
5-
author: wendux <[email protected]>
65

76
environment:
87
sdk: '>2.4.0 <3.0.0'
@@ -13,6 +12,5 @@ dependencies:
1312

1413
dev_dependencies:
1514
test: ^1.5.1
16-
test_coverage: ^0.2.0
1715
pedantic: '1.1.0'
1816

dio/test/_formdata

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
----dio-boundary-3788753558
2+
content-disposition: form-data; name="name"
3+
4+
wendux
5+
----dio-boundary-3788753558
6+
content-disposition: form-data; name="age"
7+
8+
25
9+
----dio-boundary-3788753558
10+
content-disposition: form-data; name="file"
11+
content-type: text/plain; charset=utf-8
12+
13+
hellow world.
14+
----dio-boundary-3788753558
15+
content-disposition: form-data; name="files[]"; filename="1.txt"
16+
content-type: application/octet-stream
17+
18+
你好世界,
19+
我很好人类
20+
哈哈哈哈哈😆
21+
22+
----dio-boundary-3788753558
23+
content-disposition: form-data; name="files[]"; filename="2.txt"
24+
content-type: application/octet-stream
25+
26+
你好世界,
27+
我很好人类
28+
哈哈哈哈哈😆
29+
30+
----dio-boundary-3788753558--

dio/test/_testfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
你好世界,
2+
我很好人类
3+
哈哈哈哈哈😆

dio/test/basic_test.dart

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2014, 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+
@TestOn('vm')
5+
6+
import 'dart:async';
7+
import 'dart:io';
8+
import 'package:dio/dio.dart';
9+
import 'package:test/test.dart';
10+
11+
void main() {
12+
test('#send with an invalid URL', () {
13+
expect(Dio().get('http://http.invalid').catchError((e) => throw e.error),
14+
throwsA(const TypeMatcher<SocketException>()));
15+
});
16+
test('#cancellation', () async {
17+
var dio = Dio();
18+
CancelToken token = CancelToken();
19+
Timer(Duration(milliseconds: 10), () {
20+
token.cancel('cancelled');
21+
});
22+
23+
var url = 'https://accounts.google.com';
24+
expect(
25+
dio
26+
.get(url, cancelToken: token)
27+
.catchError((e) => throw CancelToken.isCancel(e)),
28+
throwsA(isTrue));
29+
});
30+
31+
32+
test('#url encode ', () {
33+
var data = {
34+
'a': '你好',
35+
'b': [5, '6'],
36+
'c': {
37+
'd': 8,
38+
'e': {
39+
'a': 5,
40+
'b': [66, 8]
41+
}
42+
}
43+
};
44+
var result =
45+
'a=%E4%BD%A0%E5%A5%BD&b%5B%5D=5&b%5B%5D=6&c%5Bd%5D=8&c%5Be%5D%5Ba%5D=5&c%5Be%5D%5Bb%5D%5B%5D=66&c%5Be%5D%5Bb%5D%5B%5D=8';
46+
expect(Transformer.urlEncodeMap(data), result);
47+
});
48+
}

0 commit comments

Comments
 (0)