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
@ -20,31 +20,12 @@ import {
|
|||||||
AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag,
|
AnnotationBorderStyleType, AnnotationFieldFlag, AnnotationFlag,
|
||||||
AnnotationType, stringToBytes, stringToUTF8String
|
AnnotationType, stringToBytes, stringToUTF8String
|
||||||
} from '../../src/shared/util';
|
} from '../../src/shared/util';
|
||||||
import { Dict, isRef, Name, Ref } from '../../src/core/primitives';
|
import { Dict, Name, Ref } from '../../src/core/primitives';
|
||||||
import { Lexer, Parser } from '../../src/core/parser';
|
import { Lexer, Parser } from '../../src/core/parser';
|
||||||
import { StringStream } from '../../src/core/stream';
|
import { StringStream } from '../../src/core/stream';
|
||||||
|
import { XRefMock } from './test_utils';
|
||||||
|
|
||||||
describe('annotation', function() {
|
describe('annotation', function() {
|
||||||
function XRefMock(array) {
|
|
||||||
this.map = Object.create(null);
|
|
||||||
for (var elem in array) {
|
|
||||||
var obj = array[elem];
|
|
||||||
var ref = obj.ref, data = obj.data;
|
|
||||||
this.map[ref.toString()] = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
XRefMock.prototype = {
|
|
||||||
fetch(ref) {
|
|
||||||
return this.map[ref.toString()];
|
|
||||||
},
|
|
||||||
fetchIfRef(obj) {
|
|
||||||
if (!isRef(obj)) {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
return this.fetch(obj);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
function PDFManagerMock(params) {
|
function PDFManagerMock(params) {
|
||||||
this.docBaseUrl = params.docBaseUrl || null;
|
this.docBaseUrl = params.docBaseUrl || null;
|
||||||
}
|
}
|
||||||
|
@ -13,34 +13,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Dict, isRef, Name, Ref } from '../../src/core/primitives';
|
import { Dict, Name, Ref } from '../../src/core/primitives';
|
||||||
import { Stream, StringStream } from '../../src/core/stream';
|
import { Stream, StringStream } from '../../src/core/stream';
|
||||||
import { ColorSpace } from '../../src/core/colorspace';
|
import { ColorSpace } from '../../src/core/colorspace';
|
||||||
|
import { XRefMock } from './test_utils';
|
||||||
|
|
||||||
describe('colorspace', function () {
|
describe('colorspace', function () {
|
||||||
class XRefMock {
|
|
||||||
constructor(array) {
|
|
||||||
this.map = Object.create(null);
|
|
||||||
for (let elem in array) {
|
|
||||||
let obj = array[elem];
|
|
||||||
let ref = obj.ref;
|
|
||||||
let data = obj.data;
|
|
||||||
this.map[ref.toString()] = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch(ref) {
|
|
||||||
return this.map[ref.toString()];
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchIfRef(obj) {
|
|
||||||
if (!isRef(obj)) {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
return this.fetch(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('ColorSpace', function () {
|
describe('ColorSpace', function () {
|
||||||
it('should be true if decode is not an array', function () {
|
it('should be true if decode is not an array', function () {
|
||||||
expect(ColorSpace.isDefaultDecode('string', 0)).toBeTruthy();
|
expect(ColorSpace.isDefaultDecode('string', 0)).toBeTruthy();
|
||||||
|
@ -18,16 +18,9 @@ import { OperatorList, PartialEvaluator } from '../../src/core/evaluator';
|
|||||||
import { Stream, StringStream } from '../../src/core/stream';
|
import { Stream, StringStream } from '../../src/core/stream';
|
||||||
import { OPS } from '../../src/shared/util';
|
import { OPS } from '../../src/shared/util';
|
||||||
import { WorkerTask } from '../../src/core/worker';
|
import { WorkerTask } from '../../src/core/worker';
|
||||||
|
import { XRefMock } from './test_utils';
|
||||||
|
|
||||||
describe('evaluator', function() {
|
describe('evaluator', function() {
|
||||||
function XrefMock(queue) {
|
|
||||||
this.queue = queue || [];
|
|
||||||
}
|
|
||||||
XrefMock.prototype = {
|
|
||||||
fetchIfRef() {
|
|
||||||
return this.queue.shift();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
function HandlerMock() {
|
function HandlerMock() {
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
}
|
}
|
||||||
@ -63,7 +56,7 @@ describe('evaluator', function() {
|
|||||||
beforeAll(function(done) {
|
beforeAll(function(done) {
|
||||||
partialEvaluator = new PartialEvaluator({
|
partialEvaluator = new PartialEvaluator({
|
||||||
pdfManager: new PdfManagerMock(),
|
pdfManager: new PdfManagerMock(),
|
||||||
xref: new XrefMock(),
|
xref: new XRefMock(),
|
||||||
handler: new HandlerMock(),
|
handler: new HandlerMock(),
|
||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
});
|
});
|
||||||
|
@ -16,34 +16,9 @@
|
|||||||
import {
|
import {
|
||||||
Cmd, Dict, isCmd, isDict, isName, isRef, isRefsEqual, Name, Ref, RefSet
|
Cmd, Dict, isCmd, isDict, isName, isRef, isRefsEqual, Name, Ref, RefSet
|
||||||
} from '../../src/core/primitives';
|
} from '../../src/core/primitives';
|
||||||
|
import { XRefMock } from './test_utils';
|
||||||
|
|
||||||
describe('primitives', function() {
|
describe('primitives', function() {
|
||||||
function XRefMock(array) {
|
|
||||||
this.map = Object.create(null);
|
|
||||||
for (var elem in array) {
|
|
||||||
var obj = array[elem];
|
|
||||||
var ref = obj.ref, data = obj.data;
|
|
||||||
this.map[ref.toString()] = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
XRefMock.prototype = {
|
|
||||||
fetch(ref) {
|
|
||||||
return this.map[ref.toString()];
|
|
||||||
},
|
|
||||||
fetchIfRef(obj) {
|
|
||||||
if (!isRef(obj)) {
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
return this.fetch(obj);
|
|
||||||
},
|
|
||||||
fetchAsync(ref) {
|
|
||||||
return Promise.resolve(this.fetch(ref));
|
|
||||||
},
|
|
||||||
fetchIfRefAsync(obj) {
|
|
||||||
return Promise.resolve(this.fetchIfRef(obj));
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('Name', function() {
|
describe('Name', function() {
|
||||||
it('should retain the given name', function() {
|
it('should retain the given name', function() {
|
||||||
var givenName = 'Font';
|
var givenName = 'Font';
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { CMapCompressionType, isNodeJS } from '../../src/shared/util';
|
import { CMapCompressionType, isNodeJS } from '../../src/shared/util';
|
||||||
|
import { isRef } from '../../src/core/primitives';
|
||||||
|
|
||||||
class NodeFileReaderFactory {
|
class NodeFileReaderFactory {
|
||||||
static fetch(params) {
|
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 {
|
export {
|
||||||
NodeFileReaderFactory,
|
NodeFileReaderFactory,
|
||||||
NodeCMapReaderFactory,
|
NodeCMapReaderFactory,
|
||||||
|
XRefMock,
|
||||||
buildGetDocumentParams,
|
buildGetDocumentParams,
|
||||||
TEST_PDFS_PATH,
|
TEST_PDFS_PATH,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user