Skip to content

Commit cda9e64

Browse files
authored
refactor: move compare to the tests (#9931)
1 parent a221a45 commit cda9e64

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

packages/workers-shared/asset-worker/src/assets-manifest.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,3 @@ function comparePathHashWithEntry(
121121
const Uint8ToHexString = (array: Uint8Array) => {
122122
return [...array].map((b) => b.toString(16).padStart(2, "0")).join("");
123123
};
124-
125-
/**
126-
* Compare two Uint8Array values
127-
* @param a First array
128-
* @param b Second array
129-
* @returns -1 if a < b, 1 if a > b, 0 if equal
130-
*/
131-
export const compare = (a: Uint8Array, b: Uint8Array) => {
132-
if (a.byteLength < b.byteLength) {
133-
return -1;
134-
}
135-
if (a.byteLength > b.byteLength) {
136-
return 1;
137-
}
138-
139-
for (const [i, v] of a.entries()) {
140-
const bVal = b[i] as number;
141-
if (v < bVal) {
142-
return -1;
143-
}
144-
if (v > bVal) {
145-
return 1;
146-
}
147-
}
148-
149-
return 0;
150-
};

packages/workers-shared/asset-worker/tests/assets-manifest.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
PATH_HASH_SIZE,
77
} from "../../utils/constants";
88
import AssetManifestFixture from "../fixtures/AssetManifest.bin";
9-
import { binarySearch, compare, hashPath } from "../src/assets-manifest";
9+
import { binarySearch, hashPath } from "../src/assets-manifest";
1010

1111
const encoder = new TextEncoder();
1212

@@ -214,3 +214,30 @@ describe("search methods", async () => {
214214
});
215215
});
216216
});
217+
218+
/**
219+
* Compare two Uint8Array values
220+
* @param a First array
221+
* @param b Second array
222+
* @returns -1 if a < b, 1 if a > b, 0 if equal
223+
*/
224+
function compare(a: Uint8Array, b: Uint8Array) {
225+
if (a.byteLength < b.byteLength) {
226+
return -1;
227+
}
228+
if (a.byteLength > b.byteLength) {
229+
return 1;
230+
}
231+
232+
for (const [i, v] of a.entries()) {
233+
const bVal = b[i] as number;
234+
if (v < bVal) {
235+
return -1;
236+
}
237+
if (v > bVal) {
238+
return 1;
239+
}
240+
}
241+
242+
return 0;
243+
}

0 commit comments

Comments
 (0)