First slice of the TypeScript port of the filius-ipad runtime engine, with 29 tests ported from the Swift suite. Parts not ported yet throw NotPortedError instead of guessing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
781 B
TypeScript
20 lines
781 B
TypeScript
// Ported from filius-ipad (GPLv2/GPLv3), ios/FiliusPad/TopologyEditor.
|
|
// Swift orders identifiers by `UUID.uuidString`, which is upper case. Every
|
|
// deterministic ordering in the runtime depends on it, so identifiers are
|
|
// compared the same way here whatever case they were written in.
|
|
|
|
/** A node, port, link or socket identifier: a UUID string. */
|
|
export type Id = string;
|
|
|
|
/** `lhs.uuidString < rhs.uuidString` in Swift. */
|
|
export function idLess(lhs: Id, rhs: Id): boolean {
|
|
return lhs.toUpperCase() < rhs.toUpperCase();
|
|
}
|
|
|
|
/** Comparator for `Array.prototype.sort` with the Swift ordering. */
|
|
export function compareIds(lhs: Id, rhs: Id): number {
|
|
const left = lhs.toUpperCase();
|
|
const right = rhs.toUpperCase();
|
|
return left < right ? -1 : left > right ? 1 : 0;
|
|
}
|