Skip to content

Commit

Permalink
add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
wendux committed Feb 24, 2020
1 parent a2a8424 commit fba381d
Show file tree
Hide file tree
Showing 16 changed files with 577 additions and 361 deletions.
4 changes: 4 additions & 0 deletions dio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.0.9 2020.2.24

- Add test cases

# 3.0.8 2019.12.29

- Code style improvement
Expand Down
6 changes: 3 additions & 3 deletions dio/lib/src/transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class DefaultTransformer extends Transformer {
},
));
// let's keep references to the data chunks and concatenate them later
final List<Uint8List> chunks = [];
int finalSize = 0;
final chunks = <Uint8List>[];
var finalSize = 0;
StreamSubscription subscription = stream.listen(
(chunk) {
finalSize += chunk.length;
Expand Down Expand Up @@ -130,7 +130,7 @@ class DefaultTransformer extends Transformer {
}
// we create a final Uint8List and copy all chunks into it
final responseBytes = Uint8List(finalSize);
int chunkOffset = 0;
var chunkOffset = 0;
for (var chunk in chunks) {
responseBytes.setAll(chunkOffset, chunk);
chunkOffset += chunk.length;
Expand Down
4 changes: 1 addition & 3 deletions dio/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: dio
description: A powerful Http client for Dart, which supports Interceptors, FormData, Request Cancellation, File Downloading, Timeout etc.
version: 3.0.8
version: 3.0.9
homepage: https://github.com/flutterchina/dio
author: wendux <[email protected]>

environment:
sdk: '>2.4.0 <3.0.0'
Expand All @@ -13,6 +12,5 @@ dependencies:

dev_dependencies:
test: ^1.5.1
test_coverage: ^0.2.0
pedantic: '1.1.0'

30 changes: 30 additions & 0 deletions dio/test/_formdata
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
----dio-boundary-3788753558
content-disposition: form-data; name="name"

wendux
----dio-boundary-3788753558
content-disposition: form-data; name="age"

25
----dio-boundary-3788753558
content-disposition: form-data; name="file"
content-type: text/plain; charset=utf-8

hellow world.
----dio-boundary-3788753558
content-disposition: form-data; name="files[]"; filename="1.txt"
content-type: application/octet-stream

你好世界,
我很好人类
哈哈哈哈哈😆

----dio-boundary-3788753558
content-disposition: form-data; name="files[]"; filename="2.txt"
content-type: application/octet-stream

你好世界,
我很好人类
哈哈哈哈哈😆

----dio-boundary-3788753558--
3 changes: 3 additions & 0 deletions dio/test/_testfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
你好世界,
我很好人类
哈哈哈哈哈😆
48 changes: 48 additions & 0 deletions dio/test/basic_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2014, 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.
@TestOn('vm')

import 'dart:async';
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:test/test.dart';

void main() {
test('#send with an invalid URL', () {
expect(Dio().get('http://http.invalid').catchError((e) => throw e.error),
throwsA(const TypeMatcher<SocketException>()));
});
test('#cancellation', () async {
var dio = Dio();
CancelToken token = CancelToken();
Timer(Duration(milliseconds: 10), () {
token.cancel('cancelled');
});

var url = 'https://accounts.google.com';
expect(
dio
.get(url, cancelToken: token)
.catchError((e) => throw CancelToken.isCancel(e)),
throwsA(isTrue));
});


test('#url encode ', () {
var data = {
'a': '你好',
'b': [5, '6'],
'c': {
'd': 8,
'e': {
'a': 5,
'b': [66, 8]
}
}
};
var result =
'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';
expect(Transformer.urlEncodeMap(data), result);
});
}
Loading

0 comments on commit fba381d

Please sign in to comment.