fix(read/edit): make compact line prefix unambiguous for tab-indented files (#613)
This commit is contained in:
committed by
GitHub
parent
84fcc7f7e0
commit
08cc6f3287
51
src/utils/file.test.ts
Normal file
51
src/utils/file.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { afterEach, describe, expect, mock, test } from 'bun:test'
|
||||
|
||||
async function importFileModuleWithKillswitchEnabled(
|
||||
killswitchEnabled: boolean,
|
||||
) {
|
||||
mock.module('../services/analytics/growthbook.js', () => ({
|
||||
getFeatureValue_CACHED_MAY_BE_STALE: () => killswitchEnabled,
|
||||
}))
|
||||
|
||||
return import(`./file.js?ts=${Date.now()}-${Math.random()}`)
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
mock.restore()
|
||||
})
|
||||
|
||||
describe('addLineNumbers', () => {
|
||||
test('uses unambiguous arrow compact prefix and preserves leading tabs', async () => {
|
||||
const { addLineNumbers } = await importFileModuleWithKillswitchEnabled(false)
|
||||
|
||||
const result = addLineNumbers({
|
||||
content: '\tfirst\n\t\tsecond',
|
||||
startLine: 41,
|
||||
})
|
||||
|
||||
expect(result).toBe('41→\tfirst\n42→\t\tsecond')
|
||||
})
|
||||
|
||||
test('keeps padded arrow format when compact mode is disabled', async () => {
|
||||
const { addLineNumbers } = await importFileModuleWithKillswitchEnabled(true)
|
||||
|
||||
const result = addLineNumbers({
|
||||
content: 'alpha\nbeta',
|
||||
startLine: 1,
|
||||
})
|
||||
|
||||
expect(result).toBe(' 1→alpha\n 2→beta')
|
||||
})
|
||||
})
|
||||
|
||||
describe('stripLineNumberPrefix', () => {
|
||||
test('strips compact arrow, padded arrow, and legacy tab prefixes', async () => {
|
||||
const { stripLineNumberPrefix } = await importFileModuleWithKillswitchEnabled(
|
||||
false,
|
||||
)
|
||||
|
||||
expect(stripLineNumberPrefix('41→\tfirst')).toBe('\tfirst')
|
||||
expect(stripLineNumberPrefix(' 2→beta')).toBe('beta')
|
||||
expect(stripLineNumberPrefix('7\t\tlegacy-tab')).toBe('\tlegacy-tab')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user