This commit is contained in:
vorotamoroz
2026-01-07 08:38:33 +00:00
parent b52ceec36a
commit 336f2c8a4d
21 changed files with 8136 additions and 61 deletions

77
test/utils/dummyfile.ts Normal file
View File

@@ -0,0 +1,77 @@
import { DEFAULT_SETTINGS } from "@/lib/src/common/types.ts";
import { readFile } from "../utils/fileapi.vite.ts";
let charset = "";
export async function init() {
console.log("Initializing dummyfile utils...");
charset = (await readFile("test/utils/testcharvariants.txt")).toString();
console.log(`Loaded charset of length ${charset.length}`);
console.log(charset);
}
export const DummyFileSourceInisialised = init();
function* indexer(range: number = 1000, seed: number = 0): Generator<number, number, number> {
let t = seed | 0;
while (true) {
t = (t + 0x6d2b79f5) | 0;
let z = t;
z = Math.imul(z ^ (z >>> 15), z | 1);
z ^= z + Math.imul(z ^ (z >>> 7), z | 61);
const float = ((z ^ (z >>> 14)) >>> 0) / 4294967296;
yield Math.floor(float * range);
}
}
export function* generateFile(size: number): Generator<string> {
const chunkSourceStr = charset;
const chunkStore = [...chunkSourceStr]; // To support indexing avoiding multi-byte issues
const bufSize = 1024;
let buf = "";
let generated = 0;
const indexGen = indexer(chunkStore.length);
while (generated < size) {
const f = indexGen.next().value;
buf += chunkStore[f];
generated += 1;
if (buf.length >= bufSize) {
yield buf;
buf = "";
}
}
if (buf.length > 0) {
yield buf;
}
}
export function* generateBinaryFile(size: number): Generator<Uint8Array<ArrayBuffer>> {
let generated = 0;
const pattern = Array.from({ length: 256 }, (_, i) => i);
const indexGen = indexer(pattern.length);
const bufSize = 1024;
const buf = new Uint8Array(bufSize);
let bufIdx = 0;
while (generated < size) {
const f = indexGen.next().value;
buf[bufIdx] = pattern[f];
bufIdx += 1;
generated += 1;
if (bufIdx >= bufSize) {
yield buf;
bufIdx = 0;
}
}
if (bufIdx > 0) {
yield buf.subarray(0, bufIdx);
}
}
// File size for markdown test files (10B to 1MB, roughly logarithmic scale)
export const FILE_SIZE_MD = [10, 100, 1000, 10000, 100000, 1000000];
// File size for test files (10B to 40MB, roughly logarithmic scale)
export const FILE_SIZE_BINS = [
10,
100,
1000,
50000,
100000,
5000000,
DEFAULT_SETTINGS.syncMaxSizeInMB * 1024 * 1024 + 1,
];

View File

@@ -0,0 +1,3 @@
import { server } from "vitest/browser";
const { readFile, writeFile } = server.commands;
export { readFile, writeFile };

View File

@@ -0,0 +1,17 @@
國破山河在,城春草木深。
感時花濺淚,恨別鳥驚心。
烽火連三月,家書抵萬金。
白頭搔更短,渾欲不勝簪。
«Nel mezzo del cammin di nostra vita
mi ritrovai per una selva oscura,
ché la diritta via era smarrita.»
Духовной жаждою томим,
В пустыне мрачной я влачился, —
И шестикрылый серафим
На перепутье мне явился.
Shall I compare thee to a summers day?
Thou art more lovely and more temperate:
Rough winds do shake the darling buds of May,
And summers lease hath all too short a date:
📜🖋️ 🏺 🏛️ 春望𠮷ché🇷🇺АaRTLO🏳🌈👨👩👧👦lʼanatraアイウエオ