forked from 4akloon/epub_plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epub_book_ref_test.dart
137 lines (115 loc) · 4.03 KB
/
epub_book_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
library epubreadertest;
import 'package:archive/archive.dart';
import 'package:epub_plus/epub_plus.dart';
import 'package:epub_plus/src/ref_entities/epub_content_ref.dart';
import 'package:epub_plus/src/ref_entities/epub_text_content_file_ref.dart';
import 'package:test/test.dart';
main() async {
Archive arch = Archive();
var reference = EpubBookRef(
epubArchive: arch,
author: "orthros",
authors: ["orthros"],
schema: EpubSchema(),
title: "A Dissertation on Epubs",
);
late EpubBookRef testBookRef;
setUp(() async {
testBookRef = reference.copyWith();
});
group("EpubBookRef", () {
group(".equals", () {
test("is true for equivalent objects", () async {
expect(testBookRef, equals(reference));
});
test("is false when Content changes", () async {
var file = EpubTextContentFileRef(
epubBookRef: testBookRef,
contentMimeType: "application/txt",
contentType: EpubContentType.other,
fileName: "orthros.txt",
);
EpubContentRef content = EpubContentRef(
allFiles: {"hello": file},
);
testBookRef = testBookRef.copyWith(content: content);
expect(testBookRef, isNot(reference));
});
test("is false when Author changes", () async {
testBookRef = testBookRef.copyWith(author: "NotOrthros");
expect(testBookRef, isNot(reference));
});
test("is false when AuthorList changes", () async {
testBookRef = testBookRef.copyWith(authors: ["NotOrthros"]);
expect(testBookRef, isNot(reference));
});
test("is false when Schema changes", () async {
var schema = EpubSchema(
contentDirectoryPath: "some/random/path",
);
testBookRef = testBookRef.copyWith(schema: schema);
expect(testBookRef, isNot(reference));
});
test("is false when Title changes", () async {
testBookRef = testBookRef.copyWith(title: "The Philosophy of Epubs");
expect(testBookRef, isNot(reference));
});
});
group(".hashCode", () {
test("is true for equivalent objects", () async {
expect(testBookRef.hashCode, equals(reference.hashCode));
});
test("is false when Content changes", () async {
var file = EpubTextContentFileRef(
epubBookRef: testBookRef,
contentMimeType: "application/txt",
contentType: EpubContentType.other,
fileName: "orthros.txt",
);
EpubContentRef content = EpubContentRef(
allFiles: {"hello": file},
);
testBookRef = testBookRef.copyWith(content: content);
expect(testBookRef, isNot(reference));
});
test("is false when Author changes", () async {
testBookRef = testBookRef.copyWith(author: "NotOrthros");
expect(testBookRef.hashCode, isNot(reference.hashCode));
});
test("is false when AuthorList changes", () async {
testBookRef = testBookRef.copyWith(authors: ["NotOrthros"]);
expect(testBookRef.hashCode, isNot(reference.hashCode));
});
test("is false when Schema changes", () async {
var schema = EpubSchema(
contentDirectoryPath: "some/random/path",
);
testBookRef = testBookRef.copyWith(schema: schema);
expect(testBookRef.hashCode, isNot(reference.hashCode));
});
test("is false when Title changes", () async {
testBookRef = testBookRef.copyWith(title: "The Philosophy of Epubs");
expect(testBookRef.hashCode, isNot(reference.hashCode));
});
});
});
}
extension on EpubBookRef {
EpubBookRef copyWith({
Archive? epubArchive,
String? title,
List<String>? authors,
String? author,
EpubSchema? schema,
EpubContentRef? content,
}) {
return EpubBookRef(
epubArchive: epubArchive ?? this.epubArchive,
title: title ?? this.title,
authors: authors ?? this.authors,
author: author ?? this.author,
schema: schema ?? this.schema,
content: content ?? this.content,
);
}
}