Pure helper that extracts the trailing numeric sequence from a code string (ST-007 → 7, T-42 → 42). Non-conforming codes fall back to Number.MAX_SAFE_INTEGER so they sort to the end. Includes 5 unit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
684 B
TypeScript
25 lines
684 B
TypeScript
import { describe, it, expect } from 'vitest'
|
|
|
|
import { parseCodeNumber } from '@/lib/code'
|
|
|
|
describe('parseCodeNumber', () => {
|
|
it('parses a standard story code', () => {
|
|
expect(parseCodeNumber('ST-001')).toBe(1)
|
|
})
|
|
|
|
it('parses a task code', () => {
|
|
expect(parseCodeNumber('T-42')).toBe(42)
|
|
})
|
|
|
|
it('parses a large number', () => {
|
|
expect(parseCodeNumber('ST-1000')).toBe(1000)
|
|
})
|
|
|
|
it('returns MAX_SAFE_INTEGER for a code with no trailing digits', () => {
|
|
expect(parseCodeNumber('FOO')).toBe(Number.MAX_SAFE_INTEGER)
|
|
})
|
|
|
|
it('returns MAX_SAFE_INTEGER for an empty string', () => {
|
|
expect(parseCodeNumber('')).toBe(Number.MAX_SAFE_INTEGER)
|
|
})
|
|
})
|