mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Move the XRefMock
in the unit tests to a central location
This patch helps to avoid code duplication for this mock since more unit tests are depending on it.
This commit is contained in:
parent
783d42ec2b
commit
ab820438ae
5 changed files with 39 additions and 80 deletions
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
import { CMapCompressionType, isNodeJS } from '../../src/shared/util';
|
||||
import { isRef } from '../../src/core/primitives';
|
||||
|
||||
class NodeFileReaderFactory {
|
||||
static fetch(params) {
|
||||
|
@ -74,9 +75,40 @@ class NodeCMapReaderFactory {
|
|||
}
|
||||
}
|
||||
|
||||
class XRefMock {
|
||||
constructor(array) {
|
||||
this._map = Object.create(null);
|
||||
|
||||
for (let key in array) {
|
||||
let obj = array[key];
|
||||
this._map[obj.ref.toString()] = obj.data;
|
||||
}
|
||||
}
|
||||
|
||||
fetch(ref) {
|
||||
return this._map[ref.toString()];
|
||||
}
|
||||
|
||||
fetchAsync(ref) {
|
||||
return Promise.resolve(this.fetch(ref));
|
||||
}
|
||||
|
||||
fetchIfRef(obj) {
|
||||
if (!isRef(obj)) {
|
||||
return obj;
|
||||
}
|
||||
return this.fetch(obj);
|
||||
}
|
||||
|
||||
fetchIfRefAsync(obj) {
|
||||
return Promise.resolve(this.fetchIfRef(obj));
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
NodeFileReaderFactory,
|
||||
NodeCMapReaderFactory,
|
||||
XRefMock,
|
||||
buildGetDocumentParams,
|
||||
TEST_PDFS_PATH,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue