Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/unit/name_number_tree_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { XRefMock } from "./test_utils.js";
describe("NameOrNumberTree", function () {
describe("NameTree", function () {
it("should return an empty map when root is null", function () {
const xref = new XRefMock([]);
const xref = new XRefMock();
const tree = new NameTree(null, xref);
expect(tree.getAll().size).toEqual(0);
});
Expand All @@ -30,7 +30,7 @@ describe("NameOrNumberTree", function () {
const root = new Dict();
root.set("Names", ["alpha", "value_a", "beta", "value_b"]);

const xref = new XRefMock([]);
const xref = new XRefMock();
const tree = new NameTree(root, xref);
const map = tree.getAll();

Expand Down Expand Up @@ -66,7 +66,7 @@ describe("NameOrNumberTree", function () {
const root = new Dict();
root.set("Kids", [inlineLeaf]);

const xref = new XRefMock([]);
const xref = new XRefMock();
const tree = new NameTree(root, xref);

// Should not throw even though the kid is an inline Dict (not a Ref).
Expand Down Expand Up @@ -126,7 +126,7 @@ describe("NameOrNumberTree", function () {
const root = new Dict();
root.set("Nums", [1, "one", 2, "two"]);

const xref = new XRefMock([]);
const xref = new XRefMock();
const tree = new NumberTree(root, xref);
const map = tree.getAll();

Expand All @@ -144,7 +144,7 @@ describe("NameOrNumberTree", function () {
const root = new Dict();
root.set("Kids", [inlineLeaf]);

const xref = new XRefMock([]);
const xref = new XRefMock();
const tree = new NumberTree(root, xref);

const map = tree.getAll();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/primitives_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe("primitives", function () {
const dict = new Dict(null);
expect(dict.xref).toBeNull();

const xref = new XRefMock([]);
const xref = new XRefMock();
dict.assignXref(xref);
expect(dict.xref).toEqual(xref);
});
Expand Down
38 changes: 20 additions & 18 deletions test/unit/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,46 @@ function getCrossOriginHostname(hostname) {
}

class XRefMock {
constructor(array) {
this._map = Object.create(null);
this._newTemporaryRefNum = null;
this._newPersistentRefNum = null;
this.stream = new NullStream();

for (const key in array) {
const obj = array[key];
this._map[obj.ref.toString()] = obj.data;
#map = new Map();

#newPersistentRefNum = null;

#newTemporaryRefNum = null;

stream = new NullStream();

constructor(array = []) {
for (const { ref, data } of array) {
this.#map.set(ref.toString(), data);
}
}

getNewPersistentRef(obj) {
if (this._newPersistentRefNum === null) {
this._newPersistentRefNum = Object.keys(this._map).length || 1;
if (this.#newPersistentRefNum === null) {
this.#newPersistentRefNum = this.#map.size || 1;
}
const ref = Ref.get(this._newPersistentRefNum++, 0);
this._map[ref.toString()] = obj;
const ref = Ref.get(this.#newPersistentRefNum++, 0);
this.#map.set(ref.toString(), obj);
return ref;
}

getNewTemporaryRef() {
if (this._newTemporaryRefNum === null) {
this._newTemporaryRefNum = Object.keys(this._map).length || 1;
if (this.#newTemporaryRefNum === null) {
this.#newTemporaryRefNum = this.#map.size || 1;
}
return Ref.get(this._newTemporaryRefNum++, 0);
return Ref.get(this.#newTemporaryRefNum++, 0);
}

resetNewTemporaryRef() {
this._newTemporaryRefNum = null;
this.#newTemporaryRefNum = null;
}

countUpdatesAfter(offset) {
return null;
}

fetch(ref) {
return this._map[ref.toString()];
return this.#map.get(ref.toString());
}

async fetchAsync(ref) {
Expand Down