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
2 changes: 1 addition & 1 deletion client/lib/gumnut/floor.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test from 'node:test';
import * as assert from 'node:assert';
import { GumnutFloor } from './floor.ts';
import { stringToArray } from '../ymodel/helper.ts';
import { stringToArray } from '../shared/array.ts';

test('floor server changes', () => {
const f = new GumnutFloor();
Expand Down
8 changes: 4 additions & 4 deletions client/lib/gumnut/floor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { encodePatch, type Patch, type WirePatch, decodePatch } from '../ymodel/
import { InoPosRef, InoPosRefImpl, type GumnutData } from './types.ts';
import type { PatchApi } from '../ymodel/work-holder.ts';
import type { RangeUpdate } from '../ymodel/internal/range.ts';
import { arrayToString } from '../ymodel/helper.ts';
import { arrayToString } from '../shared/array.ts';
import { decodeGumnutDataArray, encodeGumnutDataArray } from './wire.ts';

type WireType = {
Expand Down Expand Up @@ -209,9 +209,9 @@ export class GumnutFloor {
};
}

resolveRef(r: InoPosRef) {
resolveRef(r: InoPosRef): number {
const impl = r as InoPosRefImpl;
return this.low.byIno(impl.target).posOf(impl.id);
return this.low.byIno(impl.target).idToPos(impl.id).pos;
}

perform(fn: FloorFn): InoChanges {
Expand All @@ -225,7 +225,7 @@ export class GumnutFloor {
},
resolveRef(r) {
const impl = r as InoPosRefImpl;
return byIno(impl.target).posOf(impl.id);
return byIno(impl.target).idToPos(impl.id).pos;
},
};
yield* fn(api);
Expand Down
2 changes: 1 addition & 1 deletion client/lib/gumnut/wire.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringToArray } from '../ymodel/helper.ts';
import { stringToArray } from '../shared/array.ts';
import type { Id } from '../ymodel/internal/shared.ts';
import { emptySymbol, InoPosRefImpl, type GumnutData } from './types.ts';

Expand Down
21 changes: 0 additions & 21 deletions client/lib/model/layout.test.ts

This file was deleted.

249 changes: 0 additions & 249 deletions client/lib/model/layout.ts

This file was deleted.

61 changes: 61 additions & 0 deletions client/lib/shared/array.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import test from 'node:test';
import * as assert from 'node:assert';
import { arrayToString, hasIndex } from './array.ts';

test('hole', () => {
const x = new Array(5);

x[0] = undefined;

assert.ok(!hasIndex(x, 1));
assert.ok(hasIndex(x, 0));

assert.ok(!hasIndex(x, 10000));

assert.ok(!hasIndex(x, 0.1));
assert.ok(!hasIndex(x, -1));
assert.ok(!hasIndex(x, NaN));
assert.ok(!hasIndex(x, Infinity));
assert.ok(!hasIndex(x, -Infinity));
});

test('arrayToString', () => {
assert.strictEqual(arrayToString(['Z']), '\0');
assert.strictEqual(arrayToString([true, false, Infinity]), '\x01\0\0');
assert.strictEqual(arrayToString([32.5, NaN]), ' \0');
assert.strictEqual(arrayToString([null]), '\0');

// check toPrimitive
class Foo {
[Symbol.toPrimitive]() {
return 123; // '{'
}
}
assert.strictEqual(arrayToString([new Foo()]), '{');

// check boring class
class Bar {}
assert.strictEqual(arrayToString([new Bar()]), '\0');

// check bigint throws
assert.throws(() => {
arrayToString([1234n]);
});

// check symbol throws
assert.throws(() => {
arrayToString([Symbol('blah')]);
});

// check symbol throws
assert.throws(() => {
arrayToString([Symbol.for('blah')]);
});

// this is `number & 0xffff` semantics in JS - clamp to uint16
const s = arrayToString([-100_000_000]);
assert.strictEqual(s.length, 1);
assert.strictEqual(s, String.fromCodePoint(7936));
assert.strictEqual(arrayToString([-100_000_000.99]), s);
assert.strictEqual(arrayToString([-100_000_000.00001]), s);
});
Loading
Loading