Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-dldc committed Nov 1, 2024
1 parent 52e870b commit 2de98e3
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 37 deletions.
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "4.0.1",
"exports": "./mod.ts",
"imports": {
"$std/": "https://deno.land/[email protected]/",
"@dldc/erreur": "jsr:@dldc/erreur@^7.1.1",
"@dldc/file": "jsr:@dldc/file@^2.0.1",
"@std/expect": "jsr:@std/expect@^1.0.7",
"sql.js": "npm:sql.js@^1.10.3"
},
"tasks": {
Expand Down
65 changes: 42 additions & 23 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/adler32.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "$std/expect/mod.ts";
import { expect } from "@std/expect";
import { adler32, rollingAdler32 } from "../src/utils/adler32.ts";

Deno.test("rollingAdler32", () => {
Expand Down
20 changes: 10 additions & 10 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { expect } from "$std/expect/mod.ts";
import { Buffer } from "node:buffer";
import { expect } from "@std/expect";
import { prepare } from "../mod.ts";
import { arrayBufferEqual } from "./utils/arrayBufferEqual.ts";
import { data } from "./utils/data.ts";

Deno.test("checksums", () => {
const testData1 = data.buffer.slice(0);
const blockSize = 16;
const doc1 = Buffer.from(prepare(testData1, blockSize));
const doc1 = prepare(testData1, blockSize);

const testData2 = data.buffer.slice(0);
const doc2 = Buffer.from(prepare(testData2, blockSize));
const doc2 = prepare(testData2, blockSize);

expect(doc1.equals(doc2)).toBe(true);
expect(arrayBufferEqual(doc1, doc2)).toBe(true);

// change data in first block
new Uint8Array(testData2)[0]++;
const doc3 = Buffer.from(prepare(testData2, blockSize));
const doc3 = prepare(testData2, blockSize);

expect(doc1.equals(doc3)).toBe(false);
expect(arrayBufferEqual(doc1, doc3)).toBe(false);

// adler32 is different for first block
expect(doc1.slice(8, 12).equals(doc3.slice(8, 12))).toBe(false);
expect(arrayBufferEqual(doc1.slice(8, 12), doc3.slice(8, 12))).toBe(false);
// md5 is different for first block
expect(doc1.slice(12, 28).equals(doc3.slice(12, 28))).toBe(false);
expect(arrayBufferEqual(doc1.slice(12, 28), doc3.slice(12, 28))).toBe(false);
// rest is the same
expect(doc1.slice(28).equals(doc3.slice(28))).toBe(true);
expect(arrayBufferEqual(doc1.slice(28), doc3.slice(28))).toBe(true);
});
2 changes: 1 addition & 1 deletion tests/sqlite.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "$std/expect/mod.ts";
import { expect } from "@std/expect";
import initSqlJs from "sql.js";
import { apply, diff, prepare } from "../mod.ts";
import { toHex } from "./utils/hex.ts";
Expand Down
2 changes: 1 addition & 1 deletion tests/sync.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from "$std/expect/mod.ts";
import { expect } from "@std/expect";
import { readFile } from "node:fs/promises";
import { apply, diff, prepare } from "../mod.ts";
import { adler32 } from "../src/utils/adler32.ts";
Expand Down
13 changes: 13 additions & 0 deletions tests/utils/arrayBufferEqual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function arrayBufferEqual(a: ArrayBuffer, b: ArrayBuffer): boolean {
if (a.byteLength !== b.byteLength) {
return false;
}
const aView = new Uint8Array(a);
const bView = new Uint8Array(b);
for (let i = 0; i < a.byteLength; i++) {
if (aView[i] !== bView[i]) {
return false;
}
}
return true;
}

0 comments on commit 2de98e3

Please sign in to comment.