forked from 4akloon/epub_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epub_byte_content_file_ref_test.dart
89 lines (74 loc) · 2.73 KB
/
epub_byte_content_file_ref_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
library epubreadertest;
import 'package:archive/archive.dart';
import 'package:epub_plus/epub_plus.dart';
import 'package:epub_plus/src/ref_entities/epub_byte_content_file_ref.dart';
import 'package:test/test.dart';
main() async {
Archive arch = Archive();
EpubBookRef ref = EpubBookRef(epubArchive: arch);
var reference = EpubByteContentFileRef(
epubBookRef: ref,
contentMimeType: "application/test",
contentType: EpubContentType.other,
fileName: "orthrosFile",
);
late EpubByteContentFileRef testFileRef;
setUp(() async {
Archive arch2 = Archive();
EpubBookRef ref2 = EpubBookRef(epubArchive: arch2);
testFileRef = reference.copyWith(epubBookRef: ref2);
});
group("EpubByteContentFileRef", () {
group(".equals", () {
test("is true for equivalent objects", () async {
expect(testFileRef, equals(reference));
});
test("is false when ContentMimeType changes", () async {
testFileRef =
testFileRef.copyWith(contentMimeType: "application/different");
expect(testFileRef, isNot(reference));
});
test("is false when ContentType changes", () async {
testFileRef = testFileRef.copyWith(contentType: EpubContentType.css);
expect(testFileRef, isNot(reference));
});
test("is false when FileName changes", () async {
testFileRef = testFileRef.copyWith(fileName: "a_different_file_name");
expect(testFileRef, isNot(reference));
});
});
group(".hashCode", () {
test("is the same for equivalent content", () async {
expect(testFileRef.hashCode, equals(reference.hashCode));
});
test('changes when ContentMimeType changes', () async {
testFileRef =
testFileRef.copyWith(contentMimeType: "application/different");
expect(testFileRef.hashCode, isNot(reference.hashCode));
});
test('changes when ContentType changes', () async {
testFileRef = testFileRef.copyWith(contentType: EpubContentType.css);
expect(testFileRef.hashCode, isNot(reference.hashCode));
});
test('changes when FileName changes', () async {
testFileRef = testFileRef.copyWith(fileName: "a_different_file_name");
expect(testFileRef.hashCode, isNot(reference.hashCode));
});
});
});
}
extension on EpubByteContentFileRef {
EpubByteContentFileRef copyWith({
EpubBookRef? epubBookRef,
String? contentMimeType,
EpubContentType? contentType,
String? fileName,
}) {
return EpubByteContentFileRef(
epubBookRef: epubBookRef ?? this.epubBookRef,
contentMimeType: contentMimeType ?? this.contentMimeType,
contentType: contentType ?? this.contentType,
fileName: fileName ?? this.fileName,
);
}
}