-
Notifications
You must be signed in to change notification settings - Fork 8
/
zstd_test.dart
70 lines (63 loc) · 2.02 KB
/
zstd_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2020, Instantiations, Inc. 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.
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:es_compression/zstd.dart';
import 'package:test/test.dart';
void main() {
test('Test Zstd Version Number', () {
const codec = zstd;
const bindingVersion = '1.5.4';
expect(codec.bindingVersion.toString(), bindingVersion);
expect(codec.libraryVersion.toString(), bindingVersion);
});
test('Test Bad Zstd Decode', () {
expect(() => zstd.decode(<int>[1, 2, 3, -2]), throwsFormatException);
});
test('Test Empty Zstd Encode/Decode', () {
const data = '';
final header = [40, 181, 47, 253, 0, 88, 1, 0, 0];
final dataBytes = utf8.encode(data);
final codec = ZstdCodec();
final encoded = codec.encode(dataBytes);
expect(const ListEquality<int>().equals(encoded, header), true);
final decoded = codec.decode(encoded);
expect(const ListEquality<int>().equals(dataBytes, decoded), true);
});
test('Test Zstd Decode Empty Stream Produces No Chunks', () async {
final result =
await const Stream<List<int>>.empty().transform(zstd.decoder).isEmpty;
expect(result, isTrue,
reason: "Stream should be empty and emit no chunks.");
});
test('Test Simple Zstd Encode/Decode', () {
const data = 'MyDart';
final expected = [
40,
181,
47,
253,
0,
88,
48,
0,
0,
77,
121,
68,
97,
114,
116,
1,
0,
0
];
final dataBytes = utf8.encode(data);
final codec = ZstdCodec();
final encoded = codec.encode(dataBytes);
expect(const ListEquality<int>().equals(encoded, expected), true);
final decoded = codec.decode(encoded);
expect(const ListEquality<int>().equals(dataBytes, decoded), true);
});
}