Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148import { describe, expect, it,} from '@monochromatic-dev/module-test/ts';
import { lineStarts, mutantId, positionAt, spliceReplacement,} from '../../dist/final/node/index.mjs';
await describe({ name: '', children: [ describe({ name: spliceReplacement.name, children: [ it({ name: 'replaces an operator token in place', fn: async () => { expect(spliceReplacement({ source: 'a + b', start: 2, end: 3, text: '-', },),).toBe('a - b',); }, },), it({ name: 'splices exactly at UTF-16 offsets past astral characters', fn: async () => { /** Source with a surrogate-pair character before the operator. */ const source = 'const s = "\u{10348}"; const n = 1 + 2;'; /** Offset of the plus token, computed in UTF-16 units. */ const plusAt = source.indexOf('+',); expect(spliceReplacement({ source, start: plusAt, end: plusAt + 1, text: '-', },),).toBe(source.split('+',) .join('-',),); }, },), it({ name: 'rejects out-of-bounds spans', fails: true, fn: async () => { spliceReplacement({ source: 'ab', start: 1, end: 5, text: 'x', },); }, },), it({ name: 'rejects inverted spans', fails: true, fn: async () => { spliceReplacement({ source: 'abc', start: 2, end: 1, text: 'x', },); }, },), ], },), describe({ name: positionAt.name, children: [ it({ name: 'maps offsets to one-based lines and zero-based columns', fn: async () => { /** Line-start table for two-line source. */ const table = lineStarts('ab\ncd',); expect(positionAt({ table, offset: 0, },),).toEqual({ line: 1, column: 0, },); expect(positionAt({ table, offset: 4, },),).toEqual({ line: 2, column: 1, },); }, },), it({ name: 'keeps offsets aligned after astral characters', fn: async () => { /** Two-line source whose first line holds an astral character. */ const source = '"\u{10348}"\nconst x = 1;'; expect(positionAt({ table: lineStarts(source,), offset: source.indexOf('const',), },),).toEqual({ line: 2, column: 0, },); }, },), ], },), describe({ name: mutantId.name, children: [ it({ name: 'is deterministic and coordinate-sensitive', fn: async () => { /** Baseline coordinates for identity comparison. */ const base = { file: 'src/a.ts', start: 2, end: 3, operator: 'arithmetic', replacement: '-', }; expect(mutantId(base,),).toBe(mutantId({ ...base, },),); expect(mutantId(base,),).not.toBe(mutantId({ ...base, replacement: '*', },),); }, },), ], },), ],},);